UPDATE: 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.
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.
Wait, this sounds familiar…
Yep, I’ve written about this topic before, but that initial implementation had two major drawbacks:
- The Analytics API only supports up to 2,000 records per report request. Companies with many records in their reports were not getting all of the campaign members added.
- Salesforce limits report subscriptions to 5 per user. So if you had many reports to configure then you were out of luck.
Out with the Old, In with the New
I’ve re-written the solution, available on GitHub, from the ground up to overcome those initial limitations and aim to be more scalable.
Have more than 2,000 campaign members to add? No Problem!
To overcome the 2,000 record limit per report request, I’ve included the SalesforceFoundation‘s ReportService, part of their CampaignTools package, in my solution. You do not need to install the Non-Profit Starter Pack (NPSP), just thank them for making their awesome solutions open source for the community!
Compared to the earlier solution, originally your reports did not explicitly have to have the Contact ID or Lead ID columns on the report (yes that helped, but wasn’t necessary). I would try to infer the record id from any of the columns on the report. In this new solution, your report must include the Contact ID or Lead ID record id field or a lookup to those objects.
Out of Report Subscriptions? Schedule Jobs instead!
To overcome the 5 report subscription limit, I’ve included support for Scheduled Jobs.
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 you just need to do it in the Developer Console to run the below snippet:
// schedule job to run at 3am every day String cron = '0 0 3 * * ?'; System.schedule( 'AddCampaignMembersJob-' + DateTime.now().getTime(), cron, new AddCampaignMembersByReportSchedulable() );
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
Use different Campaign Member Statuses for each Report
New feature: you can now specify the default campaign member status to use in the custom setting per report + campaign assignment. You can either leave the value blank and leverage Salesforce default behavior or specify your desired value.
Not real-time, but near real-time
For scalability, the campaign members are now added in a batch job in the background rather than in real-time. For small reports (less than 500 records) you may not even notice a difference. For large reports (more than 2,000) records you may see the campaign members be added over a period of seconds or minutes.