+ Start a Discussion
Mark Allerton (E.ON)Mark Allerton (E.ON) 

Trigger Outbound SocialPost

I would like to be able to send a reply to customers automatically after a certain period of time inviting them to fill out an NPS survey. I have been unable to figure out a way of triggering an outbound social post reply to customers. Does anyone know if it is possible to send a SocialPost via apex rather than immediately via the Social Published Action?
ShashankShashank (Salesforce Developers) 
It should be possible using scheduled apex. However, I would also recommend you to try out Workflows/Processes before you opt for code as they already have support for time based actions.
Mark Allerton (E.ON)Mark Allerton (E.ON)

I am unable to used Workflows or Processes as neither of them seem to offer the ability to send a SocialPost.
Ben EdwardsBen Edwards
Old post but adding here for completeness sake. This is possible via Apex. You need to first instantiate a SocialPost record, and then execute the SocialPublisher QuickAction (as simply creating the SocialPost record doesn't physically push the message to your social network).

Example code here:
// First, instantiate the new SocialPost record
SocialPost newPost = new SocialPost();
newPost.ParentId = '5000l000001rUDU'; // Id of the parent record, in this instance my Case Id
newPost.OutboundSocialAccountId = '0AL0l0000004CARGA2'; // Id of the SocialAccount record
newPost.ReplyToId = '0ST0l0000008QmL'; // Id of the original SocialPost message that this is replying to
newPost.MessageType = 'Private'; // In my instance I'm doing a Private Message, so setting this here
newPost.Content = 'Hey Ben!'; // The actual message to send

// Now instantiate the "QuickAction" that we want to execute. In this instance, I'm using
// the standard SocialPublisher action on the Case object.
QuickAction.QuickActionRequest req = new QuickAction.QuickActionRequest();
req.quickActionName = Schema.Case.QuickAction.SocialPublisher;
req.record = newPost; // Assign the post instatiated above to the QuickAction
req.contextId = '5000l000001rUDU'; // Set the Case ID to set context for the QuickAction

// Now execute the action, yay!
QuickAction.QuickActionResult res = QuickAction.performQuickAction(req);
Hi Ben,

Are you able to send attachments as well using this quick action?