Last active
March 12, 2020 11:51
-
-
Save justin-lyon/b5e30c20186c3db90591411a7a511bf6 to your computer and use it in GitHub Desktop.
POC to insert a feeditem as a guest user on salesforce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class without sharing AccountHandler { | |
public static void postToChatter() { | |
FeedItem fi = new FeedItem(/*Add required fields*/); | |
insert fi; | |
} | |
@future | |
public static void asyncPostToChatter() { | |
postToChatter(); | |
} | |
public class PostToChatterQueueable implements Queueable { | |
private List<Account> newAccounts; | |
public PostToChatterQueueable(List<Account> newAccounts) { | |
this.newAccounts = newAccounts; | |
} | |
public void execute (QueueableContext ctx) { | |
AccountHandler.postToChatter(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger AccountTrigger on Account (after insert) { | |
if (Trigger.IsAfter && Trigger.IsInsert) { | |
// Synchronous | |
AccountHandler.postToChatter(); | |
// Async Future Method | |
AccountHandler.asyncPostToChatter(); | |
// Async Queueable | |
System.enqueueJob(new AccountHandler.PostToChatterQueueable()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment