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
GWebberGWebber 

E-mail Service to Create Contact

I'm having some difficulties creating an e-mail service that creates Contacts, which can then be linked to an Opportunity using OpportunityContactRole.  I'm not getting e-mail error logs when I send my tests, so I can't figure out what's going wrong.  Here's the key bit of the code that I think is not working properly:

 

 

if(!event_code.equals(''))
          {
               Opportunity opp = [Select ID
                   From Opportunity Where Event_Code__c = :event_code limit 1];
               
               Contact primaryContact = new Contact();
               primaryContact.LastName = event_last;
               primaryContact.FirstName = event_first;
               try{
               insert primaryContact;
               }catch(DMLException e){
                     system.debug('ERROR Inserting attachment:'+e.getDMLMessage(0));
               } 

               OpportunityContactRole primaryContactRole = new OpportunityContactRole();
               primaryContactRole.ContactId = primaryContact.id;
               primaryContactRole.OpportunityId = opp.id;
               try{
                     insert primaryContactRole;
               }catch(DMLException e){
                     system.debug('ERROR Inserting attachment:'+e.getDMLMessage(0));
               } 
          }

 

 

myredpointmyredpoint

Try adding this to your new Opp Contact Role area:

 

 

primaryContactRole.Role = 'SomeRole';

 

Also, you're inserting a contact without an accountId.

 

BritishBoyinDCBritishBoyinDC

That sounds like the two places that's wrong.

 

But you can also set the debug log for the user who is set to process these records - when the service is called it will show you the errors...