| Candidates | Employers
Great SFDC Trigger Example to Create a new Contact based on inbound Case.

CRM Applications Discussions


Reply Great SFDC Trigger Example to Create a new Contact based on inbound Case. From:
GuestUser
Below is a great Example of Trigger on Case Object.
1. Get RecordType ID by Name (hmm Not API Name but Label Name :) unusual)
2. This trigger will also check if you have Duplicated.
Please note the "ContactMatch" class is below, too.
3. Insert a new Contact and associate it with the case.
That is all :)
_____________________________________________________
trigger CaseNameTrigger on Case (before insert) {
Id CaseRecord1TypeId =
Schema.SObjectType.Case.getRecordTypeInfosByName().get('RecordTypeName1').getRecordTypeId();
Id CaseRecordType2Id =
Schema.SObjectType.Case.getRecordTypeInfosByName().get('RecordTypeName2').getRecordTypeId();
for(Case c:Trigger.New)
{
if (c.RecordTypeId == CaseRecord1TypeId ) // check Recordtype, 1 then
{
// check if contact already exists, if not then add a new one.
If (c.First_Name__c != Null && c.Last_Name__c != Null) {
Contact con = new Contact(LastName = c.Last_Name__c,
FirstName = c.First_Name__c,
Email=c.SuppliedEmail);
if (ContactMatch.match(con)) //check for duplicate Contact
{
}
else { //New Contact
Insert con; //create
c.contactid=con.id; //get id and associate with the case
}
}
}
else if (c.RecordTypeId == CaseRecordType2Id ) // Recordtype 2
{// process here
}
}
}
________________________________________________________
public class ContactMatch {
public static Boolean match(Contact c) {
List<Contact> test = [SELECT FirstName, LastName, Email
FROM Contact
WHERE FirstName =: c.FirstName
AND LastName =: c.LastName
AND Email =: c.Email
AND Id !=: c.Id];
return (test.size() > 0);
}
}
click to view
Replies to this message: 
-None-
CRMJobs Candidate Tools
Search jobs, review companies, manage your resume, and stay connected without digging through old navigation.
Search CRM Jobs Company Profiles Contact Support Site Map
Business Transparency Public business verification and contact details Expand to review CRMJobs.net public verification, billing, privacy, and support contact details.
CRMJobs.net publishes the public business details below so candidates, recruiters, advertisers, and support contacts can verify the site's business identity, where to find official company pages, and where billing or privacy questions should be directed.
Operating / Published Name CRMJOBS.NET
Public Company Profile View CRMJOBS.NET company profile Published company profile on CRMJobs.net.
Business HQ Los Angeles, California 90249, United States Full street line is not published in the current company record.
Established 1998
Support Email support@crmjobs.net
Privacy Contact support@crmjobs.net
Billing And Member Services MemberServices@crmjobs.net
Refund and billing handling: Billing or refund questions should be sent to MemberServices@crmjobs.net. Upgraded membership changes and cancellation requests should be sent to support or Member Services at least 5 business days before the next billing period.
Terms & Privacy | About Us | Partners | Advertise | Search CRM Jobs | Link To Us
© CRMJobs.net. All Rights Reserved.