New Tool Available (January 2018)
I've developed a new, more robust tool, Mass Action Scheduler, that lets you declaratively schedule Process Builder, Flows, Quick Actions, Email Alerts, Workflow Rules, and Apex to process records from Reports and List Views.
Check out the examples to see how.
Automate Adding Contacts and Leads as Campaign Members By Report
Save time and effort and avoid data loads by automatically adding contacts and leads to your campaigns based on reports.
Use reports to segment and filter the leads and contacts that matter to you then use either Report Subscriptions or Scheduled Jobs to automate adding those records to your campaigns. You can even specify the default campaign member status to use when adding the members.
Packaged Release History
Release 1.7 (current)
Fixes reports.InvalidReportMetadataException: [Some filter conditions are defined but not referenced in your filter logic.] (issue 11)
Fixes System.UnexpectedException: No more than one executeBatch can be called from within a test method (issue 10)
Expose AddCampaignMembersByReportSchedulable to subscriber orgs (issue 9)
- Fixed bug with custom report types, there was a case-sensitivity issue with column names.
- Introduces "Add Campaign Members by Report Log" tab so you can see some information when errors occur. Managed packages hide Debug Log details so it was nearly impossible for me to help troubleshoot. Now you'll at least have some high level information that may help you solve the issue and/or help me know where to dig in further.
- If error log records are generated then email is sent to all Salesforce Users listed in
Setup | Email Administration | Apex Exception Emailnotifying them to review the error log records.
- Project now available as a managed package! No more messing with unit tests during deployment!
- Introduces "Add Campaign Members by Report Settings" tab to easily configure which reports feed into which campaigns.
- Supports reports where the Contact and/or Lead ID exists in the report multiple times. Recommend ensuring reports don't include duplicate ids for overall performance, but now duplicates won't cause the app to fail to add members to your campaigns.
- Multi-lingual support for report column names. The label of a column name changes based on running user's language preference so now the code references the unique API column name instead.
- General development
- Support reports with more than 2,000 records
- Support specifying the default campaign member status to use when adding new members
- Introduces schedulable class that developers can use if you exceed your limit of Report Subscriptions
Installing the Source Code (Developers)
You may install the unmanaged code from GitHub and make any desired adjustments. You are responsible for ensuring unit tests meet your org's validation rules and other requirements.
Install latest package release from links above.
Assign yourself the permission set named Add Campaign Members By Report Admin. This grants you access to Visualforce pages developed to let you easily manage the custom setting (selecting campaign, selecting report, selecting column from report). Otherwise by doing it manually in Setup | Develop | Custom Settings requires you to know all the underlying record IDs and details about Report Metadata.
Create a report in
Tabularformat that contains at least one Contact ID or Lead ID field. The field must be either the record ID or a lookup to the object holding the ID value, it cannot be a
formulafield. Please note,
Matrixor other complex report formats are not supported by this package at this time.
Create an active Campaign that you want the contacts/leads from the report to be added to as members whenever the report runs.
Navigate to the tab Add Campaign Members By Report Settings. This will list any existing custom settings, which you may edit or delete as needed. Click the New button to create a new configuration for our report (step 3) and campaign (step 4).
- Go back and run your report from step 3. On the report results page, click on the
Subscribebutton. It should appear just after the
Add to Campaignbutton. Ironically enough, this solution has nothing to do with the
Add to Campaignbutton -- though you're welcome to use that button to manually add contacts to your campaigns. But if you're still interested in automating the process, keep reading because you're almost done!
- To test the subscription, click the Save & Run Now button. If successful then your campaign should now include all the contacts/leads from the report. If you've maxed out your number of report subscriptions, see the FAQ below for how to schedule the report with Apex instead.
- Note, it may take a moment depending on how many records are in your report.
- For small reports (less than 200 records) it may complete in a couple seconds.
- For large reports (more than 2,000 records) it may take a few moments until all campaign members are added.
- You will notice progress nearly immediately as the batch background job runs.
Do I need to install the Non-Profit Success Pack?
No, this package uses a copy of the SalesforceFoundation ReportService as part of their CampaignTools package to support all records in a report beyond the 2,000 limit. I have included the two apex classes needed in this package. Just let the Salesforce Foundation know we appreciate them!
Can I use other report types other than the standard "Contacts & Accounts" or "Leads"?
Yes! You can use any standard or custom report type provided that one of the columns in the report is either the Contact.Id, Lead.Id, or a lookup to the Contact or Lead objects. The column cannot simply be a
formula field, however.
For example, you could use Opportunities with Contact Roles report type and include the Contact ID field on the report.
I have reached the limit of number of reports I can subscribe to, what can I do?
At the time of this writing there is a limit of 5 reports any given user can subscribe to at a time.
Alternatively, you can schedule a job to run periodically that will automatically run the reports for you. It's about as simple or simpler to do than setting up the report subscription.
- In Setup, navigate to Develop | Apex Classes
- Click the Schedule Apex button
- Enter AddCampaignMembersByReportSchedulable for Job Name and Apex Class inputs
- Choose your desired frequency then click Save button
You can review your scheduled job status in Setup at Jobs | Scheduled Jobs.
When the scheduled job runs then it will enqueue a batch job, one per record configured in Add Campaign Members by Report Settings.
Please consider voting for these ideas to increase the report subscription limit:
- Increase the limit on the number of reports a user can subscribe to
- Increase Report Subscription Notifications
Error: There was an unexpected error while running an action for 'Some Report Name'
Salesforce automatically sends this email whenever a Report Subscription action encounters an error. The email does not contain any helpful information, but if you get this email then do check the Add Campaign Members by Report Logs tab for any error messages.
Error: Missing custom setting AddCampaignMembersByReportSetting__c record with name "00OB0000000UKz0MAG"
You need to use the Add Campaign Member by Report Settings tab and create a setting that maps your report to the campaign it will add members to. The alphanumeric value at end of the error message is the ID of the report that needs to be configured.