Skip to main content
I am new to APEX coding and am struggling with the following error.  Any help would be apprecaited.

Error: Compile Error: Variable does not exist: Designated_Forecast_Account__c at line 5 column 1

My trigger:

trigger ForecastAccount on Opportunity (before insert, before update) {

 

if ( Project__r.Sponsor_Account__r.Forecast_Account__c  = True) {

 

Designated_Forecast_Account__c =  Sponsor_Account__r.Id ;

 

} else if

 

(  Project__r.Sponsor_Account__r.Forecast_Account__c  = False){

 

Designated_Forecast_Account__c = Sponsor_Account__r.Reporting_Parent__c ;

 }

}

 
5 个回答
  1. 2017年7月14日 15:35
    I would suggest to take following path,

    1) First make a formula field on Project__c object named "Forcast Account Checkbox" and it will simpley be checked when Forcast_Account__c is checked.

    2) Now we are going to make a use of that field in trigger:

    Trigger ForecastAccount on Opportunity (before insert, before update)

    {

    For(Opportunity Opp : Trigger.New)

    {

    If(Opp.Project__c != null)

    {

    List<Opportunity> comingOppInfo = [Select Id, Designated_Forecast_Account__c, Project__r.Id,

    Project__r.Forcast_Account_Checkbox, Project__r.Sponser_Account__c, Project__r.Reporting_Parent__c

    FROM Opportunity WHERE Id =:Opp.Id LIMIT 1];

    If(comingOppInfo[0]. Project__r.Forcast_Account_Checkbox == TRUE)

    {

    comingOppInfo[0].Designated_Forecast_Account__c = comingOppInfo[0].Project__r.Sponser_Account__c;

    }

    Else If(comingOppInfo[0]. Project__r.Forcast_Account_Checkbox == FALSE)

    {

    comingOppInfo[0].Designated_Forecast_Account__c = comingOppInfo[0].Project__r.Reporting_Parent__c;

    }

    }

    }

    }

    Hope this helps!