Questions tagged [trigger]

A trigger is a feature of the Salesforce platform consisting of Apex code that executes before or after DML operations.

1,451 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
16 votes
2 answers
611 views

Using the Tooling API to create trigger, getting Error No such column 'Email' on entity 'User'

I'm using the Tooling API to dynamically create an Apex Trigger. The trigger itself consists of one line, calling a method in a Util class. Creating this trigger by hand works fine. When I try to ...
Jochen's user avatar
  • 663
9 votes
1 answer
356 views

Bulk Delete operation in trigger does not split the data in chunks of 200

As far I know, while processing bulk operations in Trigger, the data is split in chunks of 200 per batch. I have around 40K accounts in org and I wanted to delete around 1000 of them. To understand ...
Dev Arya's user avatar
  • 475
8 votes
1 answer
217 views

Query highest value of custom Field on Large Object

Existing Logic: We have a trigger that gets the highest value of a custom Field "UIN__c" on various Objects and increments the value by 1 on each new Record. This Field functions as an ID ...
César Antonio Villalta's user avatar
6 votes
0 answers
392 views

How to detect a size change for a ContentDocument or a ContentNote in a trigger?

Both ContentDocument and ContentVersion have a ContentSize field documented to be: Size of the document in bytes but after adding debug code to check that field for both types for these events: ...
Keith C's user avatar
  • 134k
5 votes
1 answer
296 views

How to Activate a File Drop Automation via the API

I can create a file drop triggered automation through both SOAP and REST API's but I cannot figure out how to switch them from "Inactive" to "Active". Any help would be be greatly appreciate, thanks!
Brett's user avatar
  • 153
5 votes
2 answers
2k views

Preventing Recursive Future Calls

I have a usecase where when an account is updated, an after update trigger is fired. This trigger will call a future method which will call a SOAP API to assign the relevant territory assignment rules....
snl's user avatar
  • 1,328
5 votes
0 answers
775 views

Execute some code after all trigger batches complete?

Suppose I update 1000 records and I have an after update trigger. That trigger will run 5 times for each batch of 200. Is there any possible way to collect data over the course of the 5 executions and ...
Charles T's user avatar
  • 10.9k
5 votes
0 answers
1k views

Trigger addError method is not working from past 1 week on after triggers

I have created a trigger which fires only after insert, update & delete on opportunityLineItems. I am checking if custom setting values does not exists then generate error. It was working till ...
Ajay Gupta's user avatar
4 votes
0 answers
479 views

Baffling compile error: "A non foreign key field cannot be referenced in a path expression: ChangeEventHeader"

Why is it that this will not compile: trigger AccountChangeTrigger on AccountChangeEvent (after insert) { String dmlType = Trigger.new[0].ChangeEventHeader.changetype; ... A non foreign key ...
Brent Bowers's user avatar
  • 3,004
4 votes
0 answers
627 views

AfterInsert Trigger on ContentVersion addError not working

In Apex using a AfterInsert Trigger on ContentVersion (cv) object, the method cv.addError ('Custom message') is not working as expected. Instead of showing the custom error message the error that is ...
Saroj Bera's user avatar
  • 14.4k
4 votes
0 answers
202 views

Can a Change Event Trigger include the same record multiple times?

I'm starting to play with Change Event Triggers, building a handler framework and I'm not sure if I need to handle a scenario where the same record would be included in the same Change Event trigger ...
Mike's user avatar
  • 1,169
4 votes
1 answer
183 views

Invoking trigger when an answer is marked as Best Answer in Chatter

I am trying to invoke a trigger when an answer is marked as 'Best Answer' in Chatter Question. I tried a trigger on FeedItem and FeedComment objects, but the triggers were not invoked when I mark an ...
yeselkay's user avatar
  • 321
4 votes
0 answers
955 views

Triggering on Account territory changes (ObjectTerritory2Association)?

Has anyone figured out a reasonable solution to detecting in real-time when an Account's Territory or Territories (stored in ObjectTerritory2Association) has been changed? We aren't allowed to create ...
Jamie G's user avatar
  • 298
4 votes
1 answer
67 views

problem using ExclusionFilter without emailaddress

I am trying to setup a filter for my triggered sends. I want to exclude all of my users who exist in a certain Data extension: "DE_1" and have the column 'Email_Hater' with value 'True'. DE_1 has two ...
dupes's user avatar
  • 355
4 votes
0 answers
142 views

Trigger Design Question

A bit of context: Our company sells vacation rentals and has over 60 properties. When a customer chooses a property, it is stored in a look-up field called Lead.Property__c. They will also choose ...
Alex Brigham's user avatar
  • 1,139
4 votes
1 answer
3k views

How to catch Validation error in Flow

I have created flow + Process Builder to do a lookup relationship Count on parent object. My issues is I have a validation rule which fires when user try to deleted last child record from the related ...
Tamil's user avatar
  • 710
4 votes
0 answers
135 views

impact of critical updates 'Enable CSRF protection on GET and POST requests' & 'Require secure connections (HTTPS)'

We are in the process of activating critical updates in our production environment. 1) Require secure connections (HTTPS) 2) Enable CSRF protection on GET and POST requests Can someone explains me in ...
user6747's user avatar
4 votes
1 answer
644 views

What mechanisms are available for firing Update triggers on Opportunity during a "Mass Transfer" action?

In this case the "Mass Transfer" action being performed is clicking the Change Owner link on the parent Account record which subsequently bulk-reassigns the child Opportunity owners and does not ...
Mark Pond's user avatar
  • 22.8k
4 votes
1 answer
2k views

How to add the Public group in Managed Package

How to add the public group in managed package and how to get the notification when delete or renamed the group name. Is there any possibilities in SFDC?
Lemon's user avatar
  • 885
3 votes
0 answers
280 views

Blob to PDF not retaining HTML CSS

I have the following HTML - htmlBody += '<table width="100%" style="background:#16284c;max-width: 900px;margin: auto;">'; htmlBody += ...
Matthew Metros's user avatar
3 votes
0 answers
1k views

LWC Error: appendChild is not a function / Cannot add property innerHTML, object is not extensible

I am trying to add an iframe element to a container div: <template> <div class="container" lwc:dom="manual"></div> </template> JavaScript: import { ...
Robs's user avatar
  • 8,907
3 votes
0 answers
204 views

Sporadic "Insufficient Privileges"

We sometimes receive screen shots from business users indicating they are seeing "Insufficient Privileges" errors. These errors come up in a variety of contexts, but they appear to mostly be ...
Matthew Souther's user avatar
3 votes
0 answers
487 views

Platform Event Trigger won't execute in subscriber org but in scratch org

In my Managed Package, I have a trigger for the Platform event Notification__e. The publish behavior is Publish Immediately. When I publish an event via Workbench or Developer console in one of the ...
Sushant Srivastava's user avatar
3 votes
0 answers
556 views

In a Task trigger, is there any way to know if a Task is an Email before it has been inserted?

In the "before insert" section of my Task Trigger, I want to check if a Task is an email. But from what I can tell, the only way to know is by checking the Task.TaskSubtype field, but that field is ...
Ian Horner's user avatar
3 votes
1 answer
506 views

Apex class invalid for community user but not standard

UPDATE: this might be a Spring 19 only issue. Will try to confirm this. If I create an opportunity with a standard Salesforce license, no problem. But if I try the same operation as a community ...
Todd's user avatar
  • 193
3 votes
0 answers
640 views

Platform Events allow REST API JSON inputs to bypass field Required-ness?

We are finding that when feeding data to a SF Platform Event via the REST API (/services/data/v43.0/sobjects/My_Pletform_Event__e), Required field inputs can bypass endpoint validation by supplying an ...
Eric Fournier's user avatar
3 votes
0 answers
197 views

Case Assignment Community Portal. Insufficient access rights on cross-reference id when enabling email

I have a trigger to assign cases when they are entered in our community portal. It works great for guest users, and for regular salesforce users, but for users in the community users profile I get an ...
Chris Mullins's user avatar
3 votes
0 answers
522 views

Implementing Financial Force Lib built-in trigger recursion handling?

I'm looking at implementing the fflib_DomainClass in an org as our trigger handler. I know from @AndrewFawcett blog that there's a built in means of handling it. There's also been discussion on Github ...
crmprogdev's user avatar
  • 40.8k
3 votes
1 answer
792 views

Case Owner changing upon case insert (all case triggers are inactive)

I'm trying to run a unit test to see if the case owner upon insertion matches an expected value. In this case, the expected case owner will be the account owner. However, upon inserting the case, the ...
Brohan's user avatar
  • 437
3 votes
2 answers
238 views

Why is my task trigger test failing

I have a task trigger which updates two custom fields on the Account object : Last_Call_Date and Last_Meeting_Date. I have tried logging a task in sandbox and it updates the fields correctly. However,...
nadajp's user avatar
  • 31
3 votes
0 answers
3k views

OP_WITH_INVALID_USER_TYPE_EXCEPTION, Error while inserting a CaseTeamMember using Trigger

I have a trigger which inserts a "CaseTeamMember" when we add a feed comment to a Case object. The issue is that once we login as a Community User and create a case with it and then try to add a feed ...
Rushabh Shah's user avatar
3 votes
0 answers
111 views

Failures during bulk insertion of records not executing @Future methods

I have a requirement to populate the GeoCode whenever the Account records are inserted or updated. I have written after insert, after update trigger to fire a geolocation google API it works perfectly ...
konatham swathireddy's user avatar
3 votes
2 answers
2k views

How to avoid creation of duplicate Opportunity Contact Role for every newly created Opportunity?

I have written a after insert trigger on Opportunity to create a Opportunity Contact Role. Here is the part of code if( trigger.isAfter && trigger.isinsert){ Set<Id> accIds = new Set&...
user3524041's user avatar
3 votes
0 answers
142 views

Filter "Last Activity Field" by Task Subject / MapAnything

I'm using MapAnything with Salesforce and would like to color code all of my Sales Representatives' accounts based on how long it has been since they have last visited the account. This would be easy ...
Devon's user avatar
  • 31
3 votes
0 answers
544 views

ContentVersion Trigger not fired upon upload of private Chatter File

We have create an APEX Trigger with following Type: trigger TestContentVersionUpsertTrigger on ContentVersion (after insert, after update) { system.debug('Trigger for ContentVersion invoked'); ........
Zeeshan Zahid's user avatar
3 votes
1 answer
54 views

Custom Mapping Parameter File

This is kind of an odd scenario and I was wondering if anyone had seen anything like this before. We have a custom object called Financial_Account__c which stores information about our customers' ...
mitchspano's user avatar
3 votes
1 answer
193 views

Issue while firing an event using ContactEvents method in Journey builder

I am trying a simple example of firing an event using Rest API in journey builder.Followed exactly the same steps as were mentioned in the link below. https://github.com/mattcam/Salesforce-Marketing-...
Divyam's user avatar
  • 41
3 votes
3 answers
1k views

Email BCC to Salesforce Function Not Triggering Workflow Rule (Task Field Update)

I've set up a workflow rule to update the activity TYPE field based on the subject of the email. AND( BEGINS(Subject, "Email: Fwd:"), ISPICKVAL(Type, "4. Email Out"), NOT(ISBLANK(WhoId)) ...
Sandy's user avatar
  • 41
3 votes
1 answer
576 views

ExactTarget - Salesforce Integration: Adding the report or Campaign to the 'Individual Email Results' record in Salesforce

I am asking the following on behalf a client. A features in a system requires the ‘Campaign’ and ‘Report’ field to be completed on the Individual Email Result (and for that matter on the ‘Email ...
user8344's user avatar
3 votes
0 answers
136 views

Strange TypeException errors in Account triggers

I have a very basic trigger that once particular object is updated serializes it to JSON (all fields) and posts to external web service. (This trigger is installed on the organization via managed ...
Sergio Kozlov's user avatar
3 votes
0 answers
63 views

Anyone run into this: "DeleteRestrictedByFkException not found in section Exception"

I came across this earlier today while working on a custom VF page and I was trying to delete a record from an object. Seems its stemming from the delete trigger or delete action but the exception ...
diablodeveloper's user avatar
3 votes
1 answer
117 views

Packaging trigger on UserTerritory2Association object (part of Enterprise Territory Management 2.0)

Our managed package (1gp) has a dependency from Enterprise Territory Management (ETM 2.0). And we've created a trigger on UserTerritory2Association object to track moments when user is assigned to a ...
wesaw's user avatar
  • 2,929
3 votes
1 answer
4k views

System.DmlException: Delete failed.SELF_REFERENCE_FROM_TRIGGER

Hi All I have written the apex trigger.It working in sandbox but not in Production.While upload the csv file by using apex data loader in production it throws an exception below. Exception: 31:04....
Ramesh S's user avatar
  • 1,036
2 votes
1 answer
58 views

Reducing loop runs and code repetition in a trigger where junction records are created which match several criteria

I'm new to Apex and coding in general and trying to get the best practices down where possible. This trigger challenge came from David Liu's Apex Academy series and gives the following requirements: ...
cwrcyn's user avatar
  • 21
2 votes
1 answer
112 views

Update field on related object

:) I want to update field on WorkOrderLineItem when the value on related product is changed (Product2). I don't have any error, but the field is not updated. Can you please take a look? @...
NewToApex's user avatar
2 votes
0 answers
336 views

Visibility InternalUsers is not permitted for this linked record only in Test context

I am receiving the following message when trying to insert a ContentDocumentLink in a trigger but only in test context : Visibility InternalUsers is not permitted for this linked record I checked ...
THEDJA's user avatar
  • 107
2 votes
0 answers
62 views

newlist empty on BeforeUpdate when using TDTM

newList and oldList is empty when using HED TDTM - unsure why... code snippet global class GM_TDTM_OpportunitiesDuplicateFilter extends hed.TDTM_Runnable { global override hed.TDTM_Runnable....
dzh's user avatar
  • 4,204
2 votes
0 answers
84 views

How to handle triggers with dependent objects?

I have a problem regarding triggers on objects that effect other objects. When a Contact is saved on Salesforce, in my case it also saves an Affiliation. I have a trigger on each object that when ...
Patrick Packham's user avatar
2 votes
1 answer
543 views

Have a validation on knowledge article publish

We are trying to add a validation on knowledge article before publishing. This can not be done with validation rule since it involves data category. However, when I do that via trigger, I find that ...
Lance Shi's user avatar
  • 12.9k
2 votes
0 answers
50 views

Should constructor injection have parameters for the records to be processed?

Hi we're trying to loosely couple our codebase and is implementing dependency injection via Force-DI. It's my first time working with dependency injection and would like some clarity on how to ...
jema's user avatar
  • 413

1
2 3 4 5
30