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
Bayarea 101Bayarea 101 

Opportunity update trigger

What i am trying to acehive here are 2 things.
1. When an Opportunity is updated this trigger should look for a custom object. If there is a custom object is available than fire other wise not.
2. Once this trigger is fired certain fields on the opportunity should be updated. 
trigger Oppupdate on Opportunity (After update)
Opportunity Opp = [Select ID broker_firm__c, broker_firm_office__c, primary_contact_role__c from Opportunity WHERE ID In:Trigger.newMap.keySet()];
Underwriting__c U=[Select ID Opportunity__c from Underwriting__c where Opportunity_Id__c =:Opp.Id];

For (Opportunity{        
                 U.broker_firm__c = o.broker_firm__c;
                 U.broker_firm_office__c = o.broker_firm_office__c;               
                 U.broker_name__c = o.primary_contact_role__c;
Try the below code, just cross verify the api name of the fields in the below code
trigger Oppupdate on Opportunity (before update)

List<Underwriting__c> U=[Select ID,Opportunity__c,broker_firm__c,broker_firm_office__c,broker_name__c from Underwriting__c where Opportunity__c In:Trigger.newMap.keySet()];

for (Opportunity{   
		for(Underwriting__c uw: u){
			Oppty.broker_firm__c = o.broker_firm__c;
        	Oppty.broker_firm_office__c = o.broker_firm_office__c;               
        	Oppty.broker_name__c = o.primary_contact_role__c;
To understand more about apex code, check this trailhead modules
For satisfying 1st condition, you need to check whether the realtionship (Lookup / masterdetail) fileds are having values or not. This needs to be the first condition in Opportunity trigger.

For second condition, the code(multi group reference data model - List/set/Map) given by Karanraj will work for your requirement.

All the best! 
Bayarea 101Bayarea 101
This code is not working ti fails on compiling