I have the below scenarios:

Sobject/Field Information:

Status__c field on Account - New, In Progress, CLosed StageName field on Opportunity - New, In Progress, Closed

Scenario 1: Whenever Status__c field is changed in Account, the stagename of all the related opportunities of the account should be changed to the value in Status__c field of account.

Scenario 2: When StageName of Opportunity is changed to In Progress, Status__c of its related account should change to In Progress. This update on account should not change the StageName values of the related Opportunities.

  • 3
    Hello, Welcome to SFSE, What specific issue or error are you encountering? Please see How to Ask and edit your question to provide more information – RedDevil May 11 '19 at 6:02
  • @RedDevil I do not have an error. I am confused with the approach to go with. When my stage o f opportunity is changed, its related account's status should change. This update will in turn cause accounts trigger/workflow to run and will update the stagename of all related opportunities, which should not happen. – Rohit May 11 '19 at 6:08

What you have here is an example of circular logic (I might call it recursion as well). You have two objects, and both objects have code to update the other object (in certain situations).

Fixing this requires that you add additional code somewhere to break the loop. How exactly you go about doing that depends on what you (or your company, or your client) can tolerate for how the required change will affect the behavior of this code.

  • Do you care if setting an Account's status to In Progress doesn't update any Opportunity?
    • If not, then simply add a condition that prevents the Account from updating Opportunities when the status changes to this value?
  • Does the update still have to happen if something besides an Opportunity changes the Account status to In Progress?
    • If so, then you need to add something to let you know that an Account was updated because of an Opportunity. A checkbox on Account that isn't included on any page layout, a static Set<Id> in some Apex class, something

Put another way, the requirements that you have been given are incomplete. You need to bring this to your company/client and get more details about what should happen. The additional details that you'll (hopefully) get, combined with the details of the existing implementation (which parts are handled by triggers? which are handled by workflow or other things?) will dictate which approaches you can use to overcome this issue.

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.