Skip to content

Instantly share code, notes, and snippets.

@pcon
Created March 28, 2014 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcon/9832142 to your computer and use it in GitHub Desktop.
Save pcon/9832142 to your computer and use it in GitHub Desktop.
How to make a trigger not run based on a static variable
//This would actually be your CaseTrigger.trigger but the hilighting wouldn't work then
List<ChatterPost> postsToInsert = new List<ChatterPost>();
for (Case c: trigger.new) {
if (c.Status == 'collab') {
postsToInsert.add(new ChatterPost(...));
}
if (!postsToInsert.isEmpty()) {
GenericUtils.UPDATE_CASE_VIA_CHATTER_POST = false;
insert postsToInsert;
for (ChatterPost post: postsToInsert) {
//Logic to copy chatterPost.Id to Case
}
}
if (!GenericUtils.UPDATE_CASE_VIA_CHATTER_POST) {
return;
}
//Trigger logic
public static Boolean UPDATE_CASE_VIA_CHATTER_POST = true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment