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
Arundhati DebArundhati Deb 

write a trigger on opportunity to update opportunity fields based on the contract licence type


I have to write a trigger to update the different opportunity fields based on the contract licence type. Contract id is a lookup field on opportunity and we have to see the contract licence type and update opportunity fields
Hi Arundhati,

Please use the below sample trigger to achieve your requirement
trigger updateOpportunityOnContract on Contract (after update) {
  Set<Id> oppIds = new Set<Id>();
  for(Contract {
    if(c.Status=='Activated' && Trigger.oldMap.get(!='Activated') {
  for(Opportunity[] oppList:[select id from opportunity where id in :oppIds]) {
    for(Opportunity opp:oppList) {
      opp.StageName = 'Closed Won';
    update oppList;

if you have the relationship, then you can achieve from process builder as well.

Thanks & Regards,
Sakthivel Madesh