CampaignMember
is a junction object between the Lead
(or Contact
) and the Campaign
As such, you can't write a formula field that traverses through the children of a Lead (i.e. the Lead's CampaignMembers).
Option 1
However, you could try using the Declarative Lookup Rollup Summary (DLRS) package (free) to rollup the Campaign ID from CampaignMember
if and only if, the CampaignMember.Campaign.Name = 'Foo'
. This is a point and click configuration solution.
Option 2
Write your own trigger on CampaignMember
that on afterInsert/Update/Delete/UnDelete updates the parent Lead with the campaign ID, if any, whenever any CampaignStatus.Campaign.Name = 'Foo'
Them, under either option, you now have a custom field on Lead that you can interrogate for your Lead formula field.
Side note: If a Campaign is deleted, all its CampaignMembers are also (cascade) deleted but their trigger won't fire and the Lead record would have an orphan Campaign ID. Dealing with this is an exercise for the reader (one possibility is for your custom Lead field to be a Lookup on Campaign