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
AJAYAJAY 

how to update contract if some fields in opportunity are updated say it like account details,etc.,?

Nitin SharmaNitin Sharma
Hi Ajay,

You can use process builder for this scenario. Use update field action in process builder and match contract field with opportunity field.

Thanks,
Nitin Shrama
SandhyaSandhya (Salesforce Developers) 
Hi AJAY,

You can write trigger also to achieve your requirement.

Please refer below code.
 
trigger CreateContract on Opportunity (after insert, after update) {

    List<Contract> conttoinsert = new List<Contract>();

    for (Opportunity opp : Trigger.new) {

        // Create contract record only when the Stage is Updated to "Pending Win"
        if (opp.StageName == 'Pending win') {
            Contract con = new Contract();
            con.Opportunity_Name__c   = opp.id;
            con.Account               = opp.Account;
            con.CurrencyIsoCode       = opp.CurrencyIsoCode;
            conttoinsert.add(con); // For Bulk processing of the Records.
        } //end if
    } // End of For

    // Inserting the New Contract Records if these records exist
    if ( !conttoinsert.isEmpty()) {
        update conttoinsert;
    } else {
        throw new CommonException('There are no records for insertion');
    }

// define own implementation of Exception
public class CommonException extends System.Exception{}

}

Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
 
Thanks and Regards
Sandhya


 
Rakesh51Rakesh51
Hi Ajay,

I strongly recomand to use Process Builder. it is very easy to create and migrate
AJAYAJAY
 Hi Rakesh,
Thanks, i have reviewd process builder,but i have to complete the task using triggers only.Could you please help me out with it? 
AJAYAJAY
Hi Sandhya,
Thanks for the snippet.I need code if the fields say account executive and account manager both being lookup(user) fields are updated or changed in opportunity,then their corresponding email-ids present in contract should also change accordingly by using the trigger.Could you please help me out with some add-ins to this?

Thanks and Regards.