0

I am attempting to calculate the sum MRR of Assets related to an Account and add it to a field on the Opportunity object. The code doesn't show an error but does not return values when new Opportunities are created. This is a Trigger.isBefore class.

Map<Id,List<Opportunity>> qualifiedOpportunities = new Map<Id,List<Opportunity>>();
       for(Opportunity opp : opportunities)
       {
           if(opp.Type ==  'Past Due' && Trigger.isInsert)
           {
               if(! qualifiedOpportunities.containsKey(opp.Location__c) ) qualifiedOpportunities.put(opp.Location__c,new List<Opportunity>());
               //ADD TO QUALIFIED OPPS TO SET AMOUNT BEFORE PROCESSING
               qualifiedOpportunities.get(opp.Location__c).add(opp);
           }
       }

       for(AggregateResult a  : [SELECT SUM(Current_Price__c),Location__c FROM Asset WHERE Location__c IN :qualifiedOpportunities.keySet() AND Status = 'Active' GROUP BY Location__c])
       {
           for(Opportunity opp : qualifiedOpportunities.get((Id) a.get('Location__c')))
           {
               opp.Past_Due_MRR__c = (Decimal) a.get('expr0');
           }
       }
   }
4
  • 1
    Is Location__c non-null?
    – David Reed
    Commented Oct 31, 2020 at 19:46
  • @DavidReed Yes, the Location__c field is a required field on the opportunity.
    – Egypte
    Commented Oct 31, 2020 at 20:55
  • Which object is the trigger on? If its on opportunity then you won't get opportunity ids in a before trigger, you maye have to write trigger against after insert event. Do you see field from Salesforce UI (to be sure that fls is enabled for the fields)?
    – Raul
    Commented Oct 31, 2020 at 21:54
  • 1
    @Raul The fls was the issue. I should have double-checked that. Thank you so much!
    – Egypte
    Commented Nov 1, 2020 at 13:41

1 Answer 1

0

I was not thorough and did not double-check the field level security in my sandbox. This was root of the issue.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .