Questions tagged [trigger]

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

Filter by
Sorted by
Tagged with
-1
votes
1answer
51 views

execution of AfterDelete caused by: System.NullPointerException: Attempt to de-reference a null object

I have tried to write a trigger on custom object Project(), which is having lookup to asset. an asset can have many type of projects including "Collocation", what i am trying to achieve is: to ...
5
votes
2answers
130 views

DML operation simultaneity from different users

If I have a trigger on Account for example , What happens if several users update different accounts on the same time (user 1- Account a, user 2 - account b, user 3 - account c)? Is there one trigger ...
0
votes
2answers
32 views

How to write a test list of the Trigger [duplicate]

I am very new at the development. I finish writing the Trigger but have no idea with the test code. I trying to write the test code but get 0% of code coverage. Here is my Trigger and test code. ...
0
votes
2answers
48 views

Trigger and its test class

I am new to Salesforce. I have written a trigger to update contact based on account field. The Trigger code is below. trigger Update_contact_based_on_acc on Account (before update) { List<...
1
vote
0answers
33 views

Create dynamic triggers based on user selection from managed package [duplicate]

I have a requirement where I need to create two triggers inside a managed package. So, when the package is installed, the admin has a choice to either use the default objects available in the package ...
3
votes
1answer
55 views

Does locking of account lock related contact during insert?

I have a WSDL Apex service that consumes XML and creates a series of objects. XML received and parsed, queries for and finds a single account "Potential Customer" to relate potential customer ...
1
vote
1answer
31 views

iterating list values to update multiple fields

Though the below code is working fine, since its not the right practice to hardcode index numbers so is there any alternate approach for the below code. - thanks List<Contact> cntList = [...
0
votes
0answers
53 views

Break a list of id's to multiple list into equal number of records [duplicate]

I have created a list of id where i am adding record id of a custom object. List<Id> validProjectId = new List<Id>(); validProjectId.add(project.id); Now that this list has suppose 1000 ...
0
votes
1answer
31 views

After Insert trigger behaviour if insertion execution fails

I have a custom object named 'shift_cancellation__c'. This custom object records are being populated by parsing an email. I have a class named 'shiftCancellationListener' that parses the emails and ...
0
votes
1answer
67 views

APEX CPU Limit Exceeded

I am currently receiving an APEX CPU Limit Exceeded error when trying to save work orders. This is happening with any field updated. The error received is RG_WorkOrderTgr: System.LimitException: Apex ...
0
votes
1answer
43 views

Code Coverage=0%

my developer createed the following trigger and Apex Test Class. For some reason, the coverage is 0%. I need to deploy it ASAP and he already left for the rest of the week. any help is highly ...
0
votes
1answer
55 views

Unable to update to null value

I have the following code. The SAP Matrix__c Field is a lookup field. When it references another object. If it finds a match it will update to the proper Id but when it does not find a match, it does ...
1
vote
1answer
34 views

How to make sure managed package trigger can be executed by everybody

Our managed package adds a trigger on Contact and Lead insert/update. After an organization installs the package, the trigger is executed whenever a Contact or Lead is inserted/updated, even if the ...
-2
votes
2answers
38 views

Trigger to update Account on updating contact

Can someone please tell why below sample code is not working Trigger UpdateParent on contact (After Update){ List<Account> acc = new List<Account>(); for(Contact c : Trigger....
1
vote
1answer
23 views

Access Approval Step comments from trigger

I have a custom object that has approval process on it. When I'm submitting something for approval I provide some comments, and when I'm approving/rejecting, I'm also providing some comments. I wanted ...
1
vote
0answers
41 views

Issue with test class coverage

@isTest public class SchedulableStartVendorCases_Test { @testSetup static void setup() { Account acct = TestUtil.getLegalEntityAccount(); insert acct; DateTime ...
0
votes
1answer
44 views

How to get record from id map

I have a before trigger to compare dates on entry. I want to get a recond based on an id from a map, How do I achieve this. Below is my example with my question on line AAddress__c dummy = ...
2
votes
2answers
570 views

How do I do a universal SOQL?

I made a Trigger for an Object1 that gets Id from Object2. Rather, Object1 entries already have Object2 IDs, but now I need to make a lookup based on it. The Object2 can be any object you want: system ...
0
votes
1answer
412 views

HTML Body: data value too large. Can I truncate it in trigger or any other way?

We are using email to case and users are replaying to customer emails. First when we hit this issue we asked SF to extend size form 32 000 to maximum 131 000 but still for long email chains users hit ...
1
vote
1answer
35 views

Trigger to start a Screen Flow

I would like to know is it possible to start a Screen Flow using custom trigger? I tried searching but I'm only seeing samples for auto launched flows. If it's possible can anyone provide me a ...
0
votes
1answer
28 views

trigger throwing error on bulk insert for opportunity object

I worked on one trigger which will update the related account and contacts related to that account on insert or update. but on inserting bulk opportunities for single account then I am getting below ...
2
votes
1answer
40 views

State and Country/Territory picklist enabled

Why is apex Trigger unable to get value from Country/BillingCountry field in a BEFORE INSERT/UPDATE trigger when State and Country/Territory picklist enabled and data created from salesforce UI in ...
0
votes
1answer
63 views

Lookup relationship - Opportunity and Custom Object

I have two objects - one is the Opportunity and the other one is a custom Object. There is a lookup field from the Opportunity to the Custom object, but also from the Custom Object to the Opportunity. ...
0
votes
1answer
26 views

Test Class for PDF Reader Trigger

I have written one trigger for a PDF reader and Case creation based on that PDF. Now I am trying to coverage by the Test Class but it is showing only 0% Coverage. Can anyone please help me with the ...
-2
votes
1answer
30 views

I want to populate Last Record of child Due Date value in Parent Record Due Date Field value & I am getting error after insert record Read Only

In this trigger I am Getting After insert record Read only in this Condition, if(i == MapInvoice.get(invId).Line_Count__c){<br/> MapInvoice.get(invId).Due_Date__c = invl.Due_Date__c;<br/&...
1
vote
0answers
45 views

trigger works for system admin/integration user but not for other profiles in salesforce

Trigger CaseTrigger on Case (after update, after insert, Before Insert, Before Update){ Trigger_Switch__c objTriggerSwitch = Trigger_Switch__c.getValues('Case'); Boolean checkRecType=false; ...
1
vote
2answers
282 views

What is the difference between before delete and after delete?

For Apex triggers, the before and after contexts for insert and update operations makes sense in that the records can be modified during before and not during after. In the case of delete operations, ...
0
votes
2answers
50 views

Connect an apex trigger to an authorized user's account

I'm authorizing users through oAuth (Connected app) via a PHP app. I then want to enable an Apex trigger on every user's account; in short, I want to send all contacts to my app as they're added. I ...
10
votes
4answers
916 views

Should trigger handlers be static or non-static?

For a generic trigger, are there circumstances where one of the following patterns is better than the other? trigger ObjectTrigger on Object (after event) { ObjectTriggerHandler oth = new ...
0
votes
2answers
46 views

How can I get my class to pull the exact record that made the trigger run?

Trigger: trigger UpdateLastActivitySubject_trigger on Lead (before update) { List<Lead> lead = Trigger.new; for (Lead ld : lead) { if (ld.Last_Activity_Date__c != trigger.oldMap.get(ld.Id) ...
0
votes
0answers
35 views

How to mass refresh records

Is there any way to mass refresh an object with records over 1 million? Based on the values of this object, the related parent records will be updated I tried using formula field but that didnt work ...
0
votes
0answers
36 views

Bulkifying a trigger or send everything in a Future method (with a callout inside)

I would like to anticipate a "mass update" of my accounts. I need to bulkify my code which contains a Callout. What happens when a mass update is done ? Like importing a list of account. Is the ...
0
votes
0answers
24 views

Trigger on List of Objects

I need an approach to get notified whenever a Objekt changes. The Objects i want to be notified is configured within a custom Setting. Conditions: No changes on the object itself. Generic approach ...
-2
votes
1answer
38 views

Want to update a lookup field in related object

We have case object and another custom object Clans__c, the custom object(Clan__c) is having a lookup field(Case_Number__c) to case. Here I am trying to update Case_Number__c with the case related to ...
0
votes
0answers
40 views

trigger not inserting records

I have two object MP_Claims__c(custom object) and Case, having lookup relationship from MP_Claims__c to Case and Case to MP_Claims__c. Trying to insert(create a case) a record after insert/create ...
0
votes
2answers
42 views

Benefit of actually excluding records with logic directly in Trigger vs. TriggerHandler

Is there any performance benefit of excluding records in logic directly in the trigger to avoid instantiating another class (TriggerHandler) that would essentially do the same thing? I know best ...
-3
votes
1answer
25 views

How we write trigger on campaignMember, When we added any contact A into the campaignMember [closed]

How we write a trigger on campaignMember. When we added any contact A into the campaign member. I need to add all contact into the campaign member who is associated with the account of contact A. ...
1
vote
2answers
68 views

Before/After Trigger

Question When a Billing Address is modified, get the new Postal Code. Then check which Contacts on the Account are outside that Postal Code. If 1 or more Contacts are outside of the Postal Code, mark ...
9
votes
4answers
127 views

Run more than one async jobs from Future/Quable context

We have created a process which must work asynchronously (limits and architecture reasons) and it was working fine. Some time later we have started to work with BigObject. And as long as writing to ...
0
votes
0answers
28 views

Unit Test is Providing 0% Coverage for Apex Trigger - Test class for trigger [duplicate]

trigger Splittrigger_newclass on Indexing__c (before delete,after insert) { list<C_Voyage__c> lstvoyage=new list<C_Voyage__c>(); list<string> q = new list<string>(); ...
0
votes
1answer
68 views

Trigger fires multiple times recursively

I have a trigger with a trigger handler class on Opportunity. I am writing a batch class to update the stage in Opportunity which should call the trigger to create a record in "Order" object. In the ...
0
votes
1answer
40 views

I have written a trigger and class to first create an account and then 10 identical opportunities. It is working but only creating 1 opportunity

trigger IdenticalopportunityAccount on Account (after insert) { List<opportunity> oppt = new List<opportunity>(); for(Account acctOpp1 : Trigger.new) { if(acctOpp1....
0
votes
2answers
108 views

Disable the Apex Trigger for Perticular user login

Is it possible to disable the Apex trigger when a particular user logged in? Or Is any possibility to restrict the Apex trigger execution depends on user. Ex. My trigger should execute with User 1 and ...
0
votes
1answer
33 views

reason: Apex CPU time limit exceeded (refine the codes)

Im struggling to fix this CPU time problem, I have tried to refine my code as good as possible by implementing maps and as can be seen below; public class dailyUpdates2{ /// used for converting ...
0
votes
2answers
49 views

Trigger on ContentDocument/ContentVersion Firing before “After Insert”

So I've seen related questions to this about triggers not firing on ContentDocument, however my trigger is firing - just before the record is saved. I am trying to make an After Insert Trigger on ...
0
votes
2answers
83 views

Before Insert Trigger SOQL Limits

I am building a before insert trigger on hed__Program_Enrollment__c. What I am trying to do is delete everything in the hed__Program_Enrollment__c table based on a certain condition and this seems to ...
1
vote
1answer
75 views

Debugging Apex Triggers

I am attempting the Apex Superbadge trigger and have bugs in my code. In the past, I have only written Apex controllers attached to a LWC. So, when I open a page/use the LWC, I can then see my debug ...
1
vote
0answers
24 views

Bulk testing being restricted by limitation with Database.batchExecute() - How to overcome?

I was getting an occasional UNABLE_TO_LOCK_ROW error when two records were saved very close to each other. Related records were getting locked by one trigger invocation, and a second trigger ...
0
votes
1answer
59 views

only root queries support aggregate expressions

I was working on one trigger and using sum in query but I am getting the following error when I tried to save record. only root queries support aggregate expressions Can anyone helps me out in this ...
2
votes
0answers
84 views

Surprising compilation 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 ...

1
3 4
5
6 7
130