-1

I'm trying to get the Opportunity Stage value from the Opp Line Item Object but my query returns a null value. What am I missing in my "If" statement?

public static void updateClasses(List<OpportunityLineItem> newList){
        Map<Id, Id> olIds = new Map<Id, Id>();


        for(OpportunityLineItem ol : newList){
        system.debug('----------olOpp Stage Name------------'+ol.Opportunity.StageName);
            if(ol.Opportunity.StageName == 'Closed Won'){
            olIds.put(ol.Id, ol.Class__c);
            }
        }
2

Try this :

You cannot get the related object's(opportunity in this case) field info without actually querying for it.

public static void updateClasses(List<OpportunityLineItem> newList){
            Map<Id, Id> olIds = new Map<Id, Id>();
    for(OpportunityLineItem ol : [select id,Class__c,opportunity.stagename from opportunitylineitem where Id IN: newList]){
            system.debug('----------olOpp Stage Name------------'+ol.Opportunity.StageName);
                if(ol.Opportunity.StageName == 'Closed Won'){
                olIds.put(ol.Id, ol.name);
                }
            }
}
  • Thanks @rao, if I don't Limit that query, will I hit governor limits? – sfdcJameson Jun 10 '15 at 21:08
  • @user7505 duh sorry about the limit, I was testing that in my dev console. Cut paste error updated the answer – Rao Jun 10 '15 at 21:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.