I am trying to create an apex trigger that automatically adds the Quote Contact as the Primary Opportunity Contact. I am using the code below
trigger OpportunityContactRoleTrigger on Quote (after insert, after update) {
List<OpportunityContactRole> roles = new List<OpportunityContactRole>();
for (Quote q : [SELECT Id, Contact.Id, OpportunityId FROM Quote WHERE Id =: Trigger.new AND OpportunityId != null]) {
OpportunityContactRole role = new OpportunityContactRole();
role.ContactId = q.Contact.Id;
role.OpportunityId = q.OpportunityId;
role.Role = 'Other';
roles.add(role);
}
insert roles;
}
However, when I try to publish this to the active instance I get the following error:
LeapfrogQuoteController.test_invoke() Class 110 1 Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, OpportunityContactRoleTrigger: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Co...
OpportunityContactRole
in your org