Adding Leads from Salesforce Campaigns to Saleswhale

Follow

This guide shows how to set up your Salesforce instance for pulling Leads and/or Contacts from your Salesforce Campaigns into Saleswhale. This will require:

  1. setting up the required custom field,
  2. enabling custom actions via Apex Triggers.

Before you get started, clarify whether your leads are stored as Leads, Contacts, or Leads and Contacts.

 

Set up the required custom field

You will first need to set up a custom field on your Salesforce Lead and/or Contact object.

To begin, navigate to your Salesforce Setup panel. Then follow the guide to adding Salesforce custom fields.

This custom field, in this case, should be created with the following attributes: 

1) Field Type: Lookup Relationship

2) Related To: Campaign

3) Field Label: Current Campaign

4) Field Name: CurrentCampaignId

 

Enable custom actions via Apex Triggers 

Adding an Apex Trigger to the CampaignMember Object will automatically update the new Campaign field you just created once your Lead and/or Contact is added to a Campaign.

First, locate your CampaignMember Object.

Image_2018-09-01_at_10.02.22_PM.png
via Salesforce Lightning, locate Campaign Member in your Object Manager

Screen_Shot_2018-10-02_at_10.06.33_PM.png
via Salesforce Classic, search for Campaign Members via the Setup search bar

 

When defining your new Apex Trigger for Campaign Members, copy and past the following syntax depending on whether your leads are stored as Leads, Contacts, or Leads and Contacts.

Syntax for Leads and Contacts

trigger UpdateLeadOrContactCampaignField on CampaignMember (after insert ) {
    for (CampaignMember cm : Trigger.new) {
        if (cm.LeadId != null) {
            Lead lead = [Select CurrentCampaignId__c from Lead where Id=:cm.LeadId];
            lead.CurrentCampaignId__c = cm.CampaignId;
            update lead;
        }

        if (cm.ContactId != null) {
            Contact contact = [Select CurrentCampaignId__c from Contact where Id=:cm.ContactId];
            contact.CurrentCampaignId__c = cm.CampaignId;
            update contact;
        }
    }
}

 

Syntax for Leads only

trigger UpdateLeadCampaignField on CampaignMember (after insert ) {
    for (CampaignMember cm : Trigger.new) {
        if (cm.LeadId != null) {
            Lead lead = [Select CurrentCampaignId__c from Lead where Id=:cm.LeadId];
            lead.CurrentCampaignId__c = cm.CampaignId;
            update lead;
        }
    }

 

Syntax for Contacts only

trigger UpdateContactCampaignField on CampaignMember (after insert ) {
    for (CampaignMember cm : Trigger.new) {
        if (cm.ContactId != null) {
            Contact contact = [Select CurrentCampaignId__c from Contact where Id=:cm.ContactId];
            contact.CurrentCampaignId__c = cm.CampaignId;
            update contact;
        }
    }
}

 

Finally, send the Salesforce ID of the campaign you want to add leads from to the Saleswhale support team or you Saleswhale Customer Success Manager. You can find the Salesforce ID of your campaign by navigating to the Salesforce Campaign page and locating the ID in the URL. The bolded portions are examples of Salesforce Campaign IDs below shown in the example URLs below.

https://hj43.lightning.force.com/lightning/r/Campaign/7016B00000075xhQAA/view (Salesforce Lightning)

https://hj43.salesforce.com/7016B00000075xh (Salesforce Classic)

 

0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.