Skip to content

Instantly share code, notes, and snippets.

@justin-lyon
Last active March 12, 2020 11:51
Show Gist options
  • Save justin-lyon/b5e30c20186c3db90591411a7a511bf6 to your computer and use it in GitHub Desktop.
Save justin-lyon/b5e30c20186c3db90591411a7a511bf6 to your computer and use it in GitHub Desktop.
POC to insert a feeditem as a guest user on salesforce
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();
}
}
}
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