• errol allen
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

Hello,

4 years ago, I have created a Trigger "BeforeUpdate" for the opportunities.

When a specific changes is made, we request all the Opportunity Line Item associated and put them into a Map  : 
Map<Opportunity,List<OpportunityLineItem>> mapOppsOlisToSendJira = new Map<Opportunity,List<OpportunityLineItem>>();

This map is the Input parameter of another method "setAndSendJiraOpportunityDescription".

Until 3 months ago, the trigger and apex class were all right : 
in the trigger, I put key and values into the map.

And after that, the method "setAndSendJiraOpportunityDescription" browse the keySet() and for each Opportunity, get the associated Opp Line Items.

But since 3 months, we have sometimes an errors where for my Opportunity, I lost the associated values.

In the trigger, I put the values, I have a debug log to check taht. And it's all right.

But in the method "setAndSendJiraOpportunityDescription", when I check again, I have "null" as values.

In the complete log, we can see the variable assignment : we still have the Opp Line Item.

And in the first line of this method, in the debug log, we lost them.

 

Do you have any idea what is wrong ? 

The TriggerThe methodLogs of the trigger - values are filledBeginning of the method - Assignment OKLogs of the map just after assignement - values are lost

Hello,
I work in a company that our salesforce platform's architect follows SalesForce's trigger best practice to have a recursion check on Opportunity to stop the execution on each event independently. So the ExecuteAfterUpdate will run exactly once for each opportunity record. 
Here is my requirement:
1.  Apex class to have an API call to import Opportunity and OpportunityLineItems from another systme to Salesforce
2. Rollup OpportunityLineItems value to corresponding Opportunity value
3. Calculate OpportunityLineItems' value percentage= OpportunityLineItem Value/ Opportunity value.
Here is the implementation:
1. Apex class1 insert/update Opportunities
2. Opportunity Trigger is executed 1st time
3. Same Apex class1 then insert/update OpportunityLineItems
4. OpportunityLineItem trigger is exeucted 1st time and calls Apex class2 to rollup OpportunityLineItems value to Opportunity value, Opportunity is updated
5. Opportunity trigger is executed 2nd time and calls Apex class3 to calculate OpportunityLineItems' value percentage= OpportunityLineItem Value/ Opportunity value.
I am blocked in step#5, because Opportunity trigger is executed 2nd time, our company's trigger recusion check finds this Opportunity is already processed in step#2, it does not pass this Opportunity record to Apex class3.
My questions:
1. Is my implementation correct? 
2. Is company's trigger recursion implementation correct, because the same Opportunity record's value in step #2 and step #5 is not the same?
3. What should I do to bypass it?

thank you for the help.
Lei