+ Start a Discussion
BurstOfSunshineBurstOfSunshine 

Need help with trigger query

Hello:

   I'm scratching my head on this one, probably obvious to many but I can't figure out what's wrong. Eclipse is giving me this error:

 

"Save error: Invalid field stage for SObject Opportunity" line 9

 

Sales_Commission and Accounting are both children to Opportunity, but I couldn't address the Accounting object without a SOQL query. I guess that's the right way to do it?

 

  The code looks like this: (and thx for the help)

 

trigger ClosedWonOpportunity on Opportunity (After Insert, After Update) {
   List <Opportunity> opps = Trigger.new;
   List <Sales_Commission__c> scs = new List<Sales_Commission__c>();
   For (Opportunity opp : trigger.new) {
       if ((opp.stage == 'Closed Won') || (opp.stage == 'Closed Won - Quickpay')
           ||(opp.stage == 'Closed Won 50%')) {
               Sales_Commission__c cs = new Sales_Commission__c();
               sc.Opportunity__c = opp.Name;
               if (opp.stage == 'Closed Won') {
                   sc.Sale_Amount__c = [select Recognized_Amount__c from Accounting__c where
                     Opportunity__r.Name = :opp.name].Recognized_Amount__c;
                     .
                      .
                       .
                      
               }
           scs.add(sc);
           }
   }
   insert(scs);
}

Best Answer chosen by Admin (Salesforce Developers) 
Pan_AKPan_AK

Hi

 

There is no filed with the FieldName stage .The fieldName is StageName

Please use StageName insted of stage in ur code .

 

Please tick the Answer if the solves ur issue .

All Answers

Pan_AKPan_AK

Hi

 

There is no filed with the FieldName stage .The fieldName is StageName

Please use StageName insted of stage in ur code .

 

Please tick the Answer if the solves ur issue .

This was selected as the best answer
CaptainObviousCaptainObvious

try opp.stagename instead