0

I had a scenario about 3 sObjects (Opportunity, CustomProduct, CustomSample).

  1. Both CustomProduct and CustomSample had lookup field to Opportunity. Each sObject have triggers (immediately and future method).

  2. When I insert/update CustomSample data. It also update Opportunity and CustomProduct. Because future method, we only can update all 3 data in ONE process.

  3. If we want to seperate the process. What is the best practice about triggers and handle future method? I found some posts are providing good structure of triggers.

    There are nothing about future method. Or the future method is not a good option?

If I am wrong, please give me suggestions.


updated:

  • Insert/update CustomSample Process includes as below:

    1. CustomSample have before and after trigger, and after trigger will update Opportunity.

    2. Opportunity also have before and after trigger. In after trigger, it will update CustomProduct directly and indirectly(future method).

    3. CustomProduct have before and after trigger, too.

  • Maybe it's just me, but it is really difficult to understand what you are asking. It sounds like you are only working on one trigger? And you're worried about preexisting triggers on objects you touch through cross-object updates? – Adrian Larson May 12 '15 at 4:43
  • Hi @AdrianLarson, sorry about that, there are 6 triggers. Your guess is right. – DeepIce May 12 '15 at 6:38
0

There are a number of good options for trigger patterns, here is one for example.

With regards to multiple future methods, I think you may want to look into using Queueable Apex instead of future methods link. The key aspect of Queueable you're looking for is:

Chaining jobs: You can chain one job to another job by starting a second job from a running job. Chaining jobs is useful if you need to do some processing that depends on another process to have run first.

  • Thx @Davinc, I never thought Queueable Apex can be applied to my case. – DeepIce May 12 '15 at 15:48

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.