Event Chatter Batch Posting - Deployment Steps¶
Prerequisites¶
- Admin access to Salesforce org
- Access to Object Manager and Apex Classes
- Ability to create custom fields
Deployment Checklist¶
1. Create Required Field¶
Field: Chatter_Posted__c on Event_Registration__c object
Steps:
- Go to Setup → Object Manager → Event Registration
- Click Fields & Relationships
- Click New
- Select Checkbox as the field type
- Configure:
- Field Label:
Chatter Posted - Field Name:
Chatter_Posted__c(auto-populated) - Default Value: Unchecked
- Description: "Indicates if this event has been posted to Chatter. Set to true after batch job posts the event."
- Field Label:
- Click Next → Next → Save
- (Optional) Add field to page layouts if you want visibility
Time: ~5 minutes
2. Deploy Apex Classes¶
Files to Deploy:
force-app/main/default/classes/EventChatterBatchPoster.clsforce-app/main/default/classes/EventChatterBatchPoster.cls-meta.xmlforce-app/main/default/classes/EventChatterBatchPosterTest.clsforce-app/main/default/classes/EventChatterBatchPosterTest.cls-meta.xmlforce-app/main/default/classes/EventChatterPostHelper.cls(updated with batch methods)force-app/main/default/classes/EventChatterPostHelper.cls-meta.xmlforce-app/main/default/classes/EventChatterPostHelperTest.cls(updated with batch tests)force-app/main/default/classes/EventChatterPostHelperTest.cls-meta.xml
Steps:
- Deploy via Salesforce CLI:
sf project deploy start --source-dir force-app/main/default/classes - Or deploy via VS Code Salesforce Extension
- Or deploy via Change Sets in Setup → Deployment → Outbound Change Sets
Verify:
- All classes compile successfully
- Test classes pass (75%+ coverage required)
Time: ~5-10 minutes
3. Mark All Existing Events as Posted (Pre-Rollout)¶
Purpose: Prevent the batch job from posting about events that were approved before this feature was implemented.
IMPORTANT: This must be run BEFORE scheduling the batch job for the first time.
Steps:
- Open Developer Console (Setup → Developer Console)
- Go to Debug → Open Execute Anonymous Window
- Copy and paste the contents of
scripts/apex/mark_all_events_as_posted.apex - Check Open Log and click Execute
- Review the debug logs to confirm all events were updated
- Verify the update:
This should return the total count of all Event_Registration__c records
sf data query --query "SELECT COUNT() FROM Event_Registration__c WHERE Chatter_Posted__c = true" --target-org smi
What This Does:
- Sets
Chatter_Posted__c = trueon ALL existing Event_Registration__c records - Ensures the batch job only processes NEW events approved after rollout
- Prevents duplicate or unwanted posts about historical events
Time: ~2-3 minutes
4. Schedule the Batch Job¶
Option A: Using Apex Script (Recommended)
- Open Developer Console or VS Code Execute Anonymous
- Run the script:
scripts/apex/schedule_event_chatter_batch.apex - Verify job was scheduled:
- Go to Setup → Scheduled Jobs
- Look for "Event Chatter Batch Posting - Daily 5am"
- Verify next fire time is 5:00 AM Pacific
Option B: Manual Scheduling
- Go to Setup → Apex Classes
- Find
EventChatterBatchPoster - Click Schedule Apex
- Configure:
- Job Name:
Event Chatter Batch Posting - Daily 5am - Frequency: Daily
- Start Time: 5:00 AM
- Time Zone: Pacific Time
- Job Name:
- Click Save
Verify:
- Job appears in Setup → Scheduled Jobs
- Next fire time is correct (5:00 AM Pacific)
Time: ~2 minutes
5. Configure Service Account¶
Note: This org uses sm-client@prolocity.com as the service account for Chatter posting. Ensure this user:
- Has permissions to read/edit
Event_Registration__crecords - Is a member of all activity group Chatter groups
- Is added to any new Chatter groups automatically via the
Add_Chatter_Service_To_New_Groupsflow
Verify Service Account Setup:
-
Verify service account exists and is active:
sf data query --target-org smi \ --query "SELECT Id, Username, IsActive FROM User WHERE Username = 'sm-client@prolocity.com'" -
Add service account to all existing Chatter groups:
- Open Developer Console (Setup → Developer Console)
- Go to Debug → Open Execute Anonymous Window
- Copy and paste the contents of
scripts/apex/add_sm_client_to_all_chatter_groups.apex - Check Open Log and click Execute
- Review the debug logs to confirm the service account was added to all groups
-
Deploy Flow for automatic addition to new groups:
sf project deploy start --target-org smi --source-dir force-app/main/default/flows/Add_Chatter_Service_To_New_Groups.flow-meta.xml- Verify the Flow is Active in Setup → Flows
- The Flow will automatically add the service account to any new Chatter groups created in the future
Time: ~5-10 minutes
6. Verify Deployment¶
Test the Batch Job:
-
Create a test event:
- Create
Event_Registration__crecord - Set
Status__c = 'Approved' - Set
Activity_Group__c = 'Hiking'(or any valid activity group) - Verify
Chatter_Posted__cis unchecked
- Create
-
Run batch job manually:
Database.executeBatch(new EventChatterBatchPoster(), 200); -
Verify results:
- Check Setup → Apex Jobs for job status
- Check Chatter group for new post
- Verify
Chatter_Posted__c = trueon the event
-
Test duplicate prevention:
- Modify the event (change Location, etc.)
- Run batch job again
- Verify event is NOT reprocessed (no duplicate post)
Time: ~5 minutes
Post-Deployment¶
Monitor Initial Runs¶
- Check Setup → Scheduled Jobs after first few runs
- Review Setup → Apex Jobs for any errors
- Verify posts appear in Chatter groups
- Check debug logs if issues occur
Deactivate Old Flow (If Still Active)¶
If the old Notify_Subscribers_New_Event flow is still active:
- Go to Setup → Flows
- Find
Notify Subscribers New Event - Click Deactivate (or it should already be marked Obsolete)
Rollback Plan¶
If issues occur:
-
Stop the scheduled job:
- Go to Setup → Scheduled Jobs
- Find "Event Chatter Batch Posting - Daily 5am"
- Click Abort
-
Revert code (if needed):
- Deploy previous version of classes
- Or comment out batch job scheduling
-
Re-enable old flow (if needed):
- Reactivate
Notify_Subscribers_New_Eventflow
- Reactivate
Total Deployment Time¶
- Minimum: ~15-20 minutes (field + code + schedule)
- With Service Account: ~25-35 minutes
- With Testing: ~30-40 minutes
Quick Reference¶
Required Field: Chatter_Posted__c (Checkbox) on Event_Registration__c
Apex Classes:
EventChatterBatchPoster(batch class)EventChatterPostHelper(helper with batch methods)
Schedule: Daily at 5:00 AM Pacific (0 0 5 * * ?)
Query Logic: Status__c = 'Approved' AND Activity_Group__c != null AND Chatter_Posted__c != true