• MOrtiz
  • 0 Points
  • Member since 2013

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
  • 9

Im trying to use a apex script that i have found. But it seems like it does not take care of the problem of opportunities not having a primary contact. If the primary contact is not defined it throws the following error.


Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger trgMnCopyPrimaryContact caused an unexpected exception, contact your administrator: trgMnCopyPrimaryContact: execution of BeforeUpdate caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.trgMnCopyPrimaryContact: line 6, column 13


trigger trgMnCopyPrimaryContact on Opportunity (before update) {

   for (Opportunity o : Trigger.new) {

       OpportunityContactRole contactRole =
            [select ContactID from OpportunityContactRole where IsPrimary = true and OpportunityId = :o.id];

       if (contactRole != null) {
         o.Opportunity_contact__c = contactRole.ContactID;





Im not a java developer and wonder if someone can help me to add functionality that does not fail if the primary contact is missing.

As you all are probably aware, you can send an email alert (in a workflow rule) to a sales team role.  I was wondering if there was a possibility to be able to send to a contact role?