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
Keri-An Richards 9Keri-An Richards 9 

Update account on contract activation

Hi all,

Wondering if you can help please...  I need to update a custom field "Contract_end_date__c" on my Account record when a Contract is Activated.

Although it seems this -should- be able to be done either by adding a formula field, roll-up summary field or a workflow - it doesn't seem that the Account/Contract Master/Detail relationship works in the same way that many of the others do and therefore there doesn't seem to be a way to do this without code.

I'm not a developer, and would really appreciate any help I can get.

Thanks,
Keri-An
Best Answer chosen by Keri-An Richards 9
Gopal RathoreGopal Rathore
Hi Kerl-An
Check This Trigger
trigger UpdateAccountIfContractActivated on Contract (after update) {
 for(contract con : trigger.new){
        if(con.status == 'Activated'){
            account ac = [SELECT id , Contract_end_date__c from account where id =:con.AccountId];
            ac.Contract_end_date__c = con.ActivatedDate;
                update ac;
        }
    }
}

Regards 
Gopal Rathore

All Answers

Avidev9Avidev9
I think you probably need to write a trigger on Contract Object for the same. 
Keri-An Richards 9Keri-An Richards 9
Thank you - that's what I was hoping for help with.
Gopal RathoreGopal Rathore
Hi Kerl-An
Check This Trigger
trigger UpdateAccountIfContractActivated on Contract (after update) {
 for(contract con : trigger.new){
        if(con.status == 'Activated'){
            account ac = [SELECT id , Contract_end_date__c from account where id =:con.AccountId];
            ac.Contract_end_date__c = con.ActivatedDate;
                update ac;
        }
    }
}

Regards 
Gopal Rathore
This was selected as the best answer
Keri-An Richards 9Keri-An Richards 9
Thanks Gopal, what I needed was a little different - but I was able to bend yours so it did what I wanted:
trigger UpdateAccountIfContractActivated on Contract (after update) {
for(contract con : trigger.new){
        if(con.status == 'Activated'){
            account ac = [SELECT id , Contract_Renewal_Date__c from account where id =:con.AccountId];
            ac.Contract_Renewal_Date__c = con.EndDate;
                update ac;
        }
    }
}