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 

Need help to write a trigger

Hi there,
I am new to Apex triggers. I need to write a trigger for Opportunity object. The logic is when any update is made on opportuntiy object. Means if a user make change to any fields on  opportuntiy object certain field needs to be get update on Credit App object.
Credit app  Fields to be updated:
1. Broker_Firm__c
2. Broker_Firm_Office__c
3. Primary_Contact_Role__c
4. Correspondent_Programs__c ( it is a multi picklist field)
    List of multi pick list values are 
        a. Service Type
         b. Volume Type 
here is the code i have but it is not working

trigger UpdateOpportunity on Opportunity (before update)

{
Opportunity Opp = [Select broker_firm__c, broker_firm_office__c, primary_contact_role__c from Opportunity WHERE ID In:Trigger.newMap.keySet()];
List<Underwriting__c> U=[Select Opportunity__c from Underwriting__c where Opportunity_Id__c =:Opp.Id];

if(u.isEmpty())
return;
List<Opportunity> opptoUpdate = new List<Opportunity>();
For (Opportunity O:Trigger.new){        
                 O.broker_firm__c = U[0].broker_firm__c;
                 O.broker_firm_office__c = U[0].broker_firm_office__c;               
                 O.broker_name__c = U[0].primary_contact_role__c;
                 
                 opptoUpdate.add(O);
                 }
                 
                 if(opptoUpdate.size()>0)
                 update opptoUpdate;
}
 
Himanshu ParasharHimanshu Parashar
Please let me know what is the api name of the Opportunity field on your Credit App object and how Underwriting__c related to this functionality.

Thanks,
Himanshu