You need to sign in to do that
Don't have an account?

need help to write a trigger for opoortunity
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 an opportuntiy object certain fields should be get update based on the value of other object Credit App.
Opportunity Fields to be updated:
1. Broker_Firm__c
2. Broker_Firm_Office__c
3. Primary_Contact_Role__c
I am trying to it thru this Apex trigger please let me know if i am doing soemthing because it is no compiling
trigger UpdateOpportunity on Opportunity (After update)
//Map broker related opportunity fields to keep credit App up to date.
{
Opportunity Opp = [Select broker_firm__c, broker_firm_office__c, primary_contact_role__c from Opportunity WHERE ID In:Trigger.newMap.keySet()];
Underwriting__c U=[Select Opportunity__c from Underwriting__c where Opportunity_Id__c =:Opp.Id];
For (Opportunity O:Trigger.new){
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;
}
}
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 an opportuntiy object certain fields should be get update based on the value of other object Credit App.
Opportunity Fields to be updated:
1. Broker_Firm__c
2. Broker_Firm_Office__c
3. Primary_Contact_Role__c
I am trying to it thru this Apex trigger please let me know if i am doing soemthing because it is no compiling
trigger UpdateOpportunity on Opportunity (After update)
//Map broker related opportunity fields to keep credit App up to date.
{
Opportunity Opp = [Select broker_firm__c, broker_firm_office__c, primary_contact_role__c from Opportunity WHERE ID In:Trigger.newMap.keySet()];
Underwriting__c U=[Select Opportunity__c from Underwriting__c where Opportunity_Id__c =:Opp.Id];
For (Opportunity O:Trigger.new){
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;
}
}
Cyrus Talladen
CRM Engineer
www.levementum.com
Error:Apex trigger UpdateOpportunity caused an unexpected exception, contact your administrator: UpdateOpportunity: execution of AfterUpdate caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.UpdateOpportunity: line 5, column 1
And also add debug logs after the query to make sure that it is returning what you like.
Cyrus T
www.levementum.com
Error:Apex trigger UpdateOpportunity caused an unexpected exception, contact your administrator: UpdateOpportunity: execution of AfterUpdate caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.UpdateOpportunity: line 5, column 1
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;
}