function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Prakhyat sapraPrakhyat sapra 

Whenever the account is updated. Those related opportunities whose created date is above 30 days and stage is closed won that opportunity stage convert in the closed lost. please help me to write the trigger on this

Whenever the account is updated. Those related opportunities whose created date is above 30 days and the stage is closed won that opportunity stage convert in the closed lost.
AnkaiahAnkaiah (Salesforce Developers) 
Hi Prakhyat,

Refer the below link will help you to proceed further.

https://salesforce.stackexchange.com/questions/51507/trigger-to-update-opportunity-stage-based-on-account-status

Let me know if still faacing issues i will help you with code.

Thanks!!
AnkaiahAnkaiah (Salesforce Developers) 
Hi Prakhyat,

Try with below code.
trigger updateopportunities on Account(after update) 
{
    Set<Id> accountIds = new Set<Id>();

    for(Account ac : Trigger.new)
    {
        accounIds.add(ac.Id);
    }

     List<Opportunity> oppsToUpdate = new List<Opportunity>();

     for(Opportunity opp : [select id, StageName from Opportunity where AccountId in: accountIds AND StageName='ClosedWon' AND createdDate > LAST_N_DAYS:30])
     {
          opp.StageName='ClosedLost';
          oppsToUpdate.add(opp);
     }

     update oppsToUpdate;
}

If this helps, Please mark it as best answer.

Thanks!!​​​​​​​