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
bradlobradlo 

Add all account contacts to campaign button

Hi,
I may be have been searching wrong, because I would have thought that I would come up with something (positive or negative) on my current quest, but I can find nothing.

What i would like to do is create a button for the account list view, which allows you to select accounts, then using the button add all the related contacts for those selected accounts to a selectable campaign as campaign members with a selectable status.  I realise that this can be done for individual contacts in the contact list view, but I can not find anything that anyone has suggested about doing this on the Account list view.

Use Scenario
Sales rep in the field wants to invite all contacts from certain accounts to a function (campaign).  Some of the business have dozens of contacts, so selecting every contact individually is laborious.

Any ideas welcome.
James LoghryJames Loghry
You can do this through a report, if it could be stretched to meet your requirement: https://help.salesforce.com/HTViewHelpDoc?id=campaigns_reportwizard.htm&language=en_US

Otherwise, you could use a VF page with a commandButton. The VF page would use the standardController of "Account" and also use recordSetVars="accounts" to associate the selected accounts with a list in your controller.  The method called by the command button would iterate over any contacts related to those accounts and then create the campaign members like below:
 
public PageReference addCampaignMembers(){
    Set<Id> accountIds = new Map<Id,Account>(accounts).keySet();
    List<CampaignMember> members = new List<CampaignMember>();
    for(Contact c : [Select Id From Contact Where AccountId in : accountIds]){
        members.add(new CampaignMember(CampaignId = campaignId,ContactId = c.Id));
    }
    insert members;
}

Also, the followng docs should help:
  • https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_sosc_custom_button.htm
  • http://salesforce.stackexchange.com/questions/4102/creating-a-custom-list-view-button-that-handles-multi-record-selection