You need to sign in to do that
Don't have an account?
Bayarea 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;
}
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;
}
Thanks,
Himanshu