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
samsafin42samsafin42 

Creating a Contact with Email Address Only

Greetings (and May the 4th be with you!)

I'm not writing code in its entirety yet because I want to ensure I'm thinking this through all the way before I do that.

Use case: We provide training on the software that we provide to companies, and we will soon be certifying users as well. Accordingly, our training team wants to begin tracking these classes and certifications in Salesforce. They have just switched to using Citrix GoToTraining to provide their training and exams, and we are going to integrate the systems at some point in the future. We want to track classes, registrants, exams, test-takers, and certifications. We also want to provide visibility to account manageres to both an individual's class and exam history and the Account's history of classes and exams. 

The hiccup: The only fields we are able to gather today via GoTo are First Name, Last Name, Email, and Class (or Exam) they registered for.

My proposed solution:
Using an After Trigger, we pull the email address from the registrant record and perform a SOQL query to check for a matching email. If it exists, we pull the Contact Id and populate that in the Lookup field on the Registrant record. If the email does not exist, we perform a second SOQL query looking for Accounts with Contacts that have similar email formats. If we find an Account with the same email format, we add the new Contact, related to the Account, and we pull the new Id to populate the Lookup field on the Registrant record. If we do NOT find a matching Account, we still create a Contact, but we house it under a default Account called "Training," which will belong to the training group, who will monitor those Contacts and re-assign them as necessary.

It seems overly complicated, but I can't determine how to trim this down any more, if at all. Thoughts?
JeffreyStevensJeffreyStevens
Seems like a fine plan to me.

Make sure your trigger is bulkified (no SOQL's in loops, no DML's in loops, etc.).

I think you'll want a field that houses the email format in a seperate field (ie At_Domain__c, etc), have formula or workflow or process builder to keept it updated.