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
Sfdc SivaSfdc Siva 

Writing Trigger help

Hi All,

We have one Formula field called "Contract End Date"  in Opportunity object ,Needs  to populate the "Contract End Date" on the Account "Service Contract End Date"  at the time of opp is created.

Can any one please help me to creating a trigger on above senario.

Thanks
 
AshwAshw
trigger triggername on Opportunity(after insert, after update){
        list<ID> lstid = new list<ID>();
        list<Account> lstacc = new list<Account>();
        
        for(Opportunity opp: trigger.new){
            lstid.add(opp.AccountId);
        }
        for(Account acc : [select id, ContractEndDate__c from Account where ID IN: lstid]){
            for(Opportunity co : trigger.new){
                acc.ServiceContractEndDate__c = co.ContractEndDate__c ;
                lstacc.add(co);
            }
        }
        upsert lstacc;
    }