0

We have leads coming in from various sources. Depending on the source of the lead, the lead should be attached to a specific campaign. How would we leverage process builder and flow to automate this without having 40+ different nodes in Process Builder criteria for each of the lead sources?

1

I don't think a PB would work as you would have to hard code the ids but a flow or pb that calls a flow should work.

  1. Create a custom field on the campaign called lead source. Values should exactly match the lead source values on the lead.
  2. Create a flow that looks up the campaigns where the new lead source field is not null
  3. Loop through the leads and assign the ids based on the campaign with the matching lead source

As I imagine this in a flow (I don't work with them often so there may be some optimizations) it seems that it would run very inefficiently. I'm sure it can be done but I think using apex code in a trigger would allow for something that operates much more efficiently.

The key take away here is that by having matching fields from 1 record to the other, you can get rid of all of the extra nodes.

In Apex I'd use a map:

Map sourceToCampaign = new Map();

for (Campaign c : [
    SELECT Id, LeadSource__c
    FROM Campaign
    WHERE LeadSource__c != null
]) {
    sourceToCampaign.put(c.LeadSource__c, c);
}

for (Lead l : leads) {
    l.campaignId = sourceToCampaign.get(l.LeadSource);
}
| improve this answer | |
  • 1
    In the visual flow, when you do a Fast Lookup for campaigns, you can create a lookup criteria where Campaign.lead_source contains lead.leadsource. This way you only have to loop through the campaigns that are relevant. – denvergreene Aug 31 '18 at 1:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.