Skip to main content
New
Stack Overflow Jobs powered by Indeed: A job site that puts thousands of tech jobs at your fingertips (U.S. only). Search jobs

Questions tagged [before-trigger]

Before triggers are used to update or validate record values before they’re saved to the database.

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

Record triggered flow-deletion trigger

I want to create a flow where when an account gets deleted so does the related contacts and finally it updates the account name field on related opportunities with Unknown. How to do it? I have tried ...
rameesha's user avatar
0 votes
1 answer
46 views

Why is my WhoID not pre-populated when creating a task for opportunity

I have a custom field on opportunity SalesContact__c which I want to use to pre-populate the WhoId field on task. It does not get pre-populated but after insert the field is filled. Why does it not ...
Thomas's user avatar
  • 2,298
0 votes
0 answers
17 views

System.DmlException: [duplicate]

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, TaskTrigger1: execution of BeforeInsert caused by: System.SObjectException: DML ...
Khalil Abbaoui's user avatar
0 votes
1 answer
43 views

Field not being written to in helper class

I am trying to schedule a batch job, take the Id of said batch job and then write it to a field on the triggering record.The scheduling works successfully, it just doesn't write to the record. Trigger ...
stormy's user avatar
  • 51
0 votes
1 answer
42 views

Why we need before update for roll up summary calculation in apex trigger?

My trigger scenario: Once an account will update then that Account will update with the total amount from All Opportunities on Account level. Account field name would be Total Opportunity Amount. ...
Sridhar's user avatar
  • 49
-1 votes
1 answer
51 views

Why we need to use before delete event instead of after delete in apex trigger

For example: My trigger scenario: when account record is deleted then contact record should also be deleted. My Implementation: when account record is deleted then contact record should also be ...
Sridhar's user avatar
  • 49
0 votes
2 answers
55 views

Prevent duplication of contact record phone using map with apex trigger

My Implementation: trigger contactTrigger on Contact (before insert) { Switch on Trigger.OperationType { when BEFORE_INSERT { contactHandler.checkDup(Trigger.new); } ...
Sridhar's user avatar
  • 49
0 votes
1 answer
126 views

Order of execution of before update apex trigger and after save flow

Referring to the Triggers and Order of Execution documentation. It is known that, before-save flow -> before trigger -> after trigger -> after save flow. My main question here revolves only ...
prem22's user avatar
  • 652
0 votes
1 answer
59 views

Error: Apex Trigger - Read only record (Opportunity/Quote)

I'm taking my first steps in Apex. I'm trying to make a trigger with bulk that has the following requirements: The opportunity should be advanced to the 'Value Proposition' as soon as it has your ...
Aparicio Jr's user avatar
1 vote
2 answers
26 views

can we pass someother trigger context variable in before insert operation instead of passing null?

my implementation: trigger accTrigger on Account (before update, after insert, before insert, after delete, after update) { switch on Trigger.OperationType { when BEFORE_INSERT { ...
Sridhar's user avatar
  • 49
1 vote
2 answers
84 views

How does the system know how to do the before DML operations when you create new lists off of trigger.new

So say i put trigger.new in a list then i throw that list in a forloop and change field values. Well then somewhere at some point those values are saved to salesforce. In the context of before i don't ...
ensir's user avatar
  • 383
0 votes
0 answers
49 views

While inserting a new lead update trigger is executed

Created a new trigger with below code : trigger LeadSourceUpdate on Lead (before insert,before update,after update) { for(Lead l : Trigger.new){ if(Trigger.isBefore){ if(...
Sai Bhargav's user avatar
-2 votes
2 answers
42 views

Before Update Case

Retrieve existing case, do not create a new case. trigger ValidateCase on Case (before insert) { if(Trigger.isBefore && Trigger.isInsert){ for(Case newCase : Trigger.new) { ...
Desaarollador x's user avatar
0 votes
1 answer
94 views

System.ListException: List index out of bounds

I encountered this error while deploying my code Looking at the issue, it seems everything is pointed at one particular class. I am currently unsure of where it is going wrong or what causes the ...
Jaemy Malik's user avatar
0 votes
1 answer
56 views

ContentDocumentLink Trigger successfully blocks file upload on Org but fails in Dev Console

I want to block file uploads (ContentDocumentLink) on a FundingOpportunity object when status is Canceled or Closed. It works fine in the org, but it fails when I tried it on Dev console. A File is ...
ash's user avatar
  • 1
1 vote
1 answer
83 views

Can you automatically retry a trigger if record validation fails without user intervention?

We have a custom field with the Unique Id attribute. This field represents a randomly generated string that is used as a publicly facing identifier. This public id field is randomly generated and ...
kennyc's user avatar
  • 349
1 vote
1 answer
100 views

How do you acquire an exclusive lock on an object within an Apex before insert trigger?

Inside an Apex before insert trigger, what is the correct way to get an exclusive lock all records of a particular object for the length of the trigger's transaction? This trigger needs an exclusive ...
kennyc's user avatar
  • 349
-2 votes
1 answer
45 views

Ways to Match multiple set in a trigger to give an error when match is found

Ways to Match multiple set in a trigger to give an error when match is found my below trigger is executing when its finding match with content even its with different account please suggest a way to ...
user121960's user avatar
0 votes
1 answer
295 views

Check if account is updated via Lead conversion

We want to run some logic on Account trigger only if it is created/updated via lead conversion. So far, we have tried 2 approaches: Approach 1: We tried creating a checkbox field on Account 'Is Lead ...
Megha Goel's user avatar
-1 votes
1 answer
211 views

Time Elapse Two Datetimes in Hours

I am trying to find time elapsed between two datetimes in hours. Below code attempted by me. Example: A record is saved and after 2 days we have to calculate the elapsed time in hours i.e. Number of ...
Deeksha Gaur's user avatar
0 votes
1 answer
112 views

How can I convert normal triggerHandler Method to Future method?

Im learning about Future methods so wanted to covert my triggerHandler method to Future method...where Im trying to insert contact on every user insert. but im getting an issue called "Future ...
Sajid's user avatar
  • 13
0 votes
0 answers
125 views

Question on beforeUpdate or afterUpdate trigger in Salesforce

I have some doubts on whether I should be using a beforeUpdate or an afterTrigger for the scenario enlisted below. Any pointers would be very helpful. Thanks in advance. I have a custom object ABC ...
Bharath Sridhar's user avatar
0 votes
0 answers
177 views

recalculateFormulas() returns "System.HandledException: Script-thrown exception (System Code)" when Address has State selected

In trigger action BeforeInsert Quote, recalculateFormulas() returns this error "System.HandledException: Script-thrown exception (System Code)". It happens only when State is selected in ...
Jacinth's user avatar
-2 votes
1 answer
65 views

Need to bypass this validation Rule which is causing while creating the b2b records, for the live chat, Can any one please help me how should i bypass

FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, must populate atleast contact : téléphone / e-mail.: [] Class....
Khulas Khulas's user avatar
0 votes
1 answer
171 views

Querying History Object in update trigger, not showing the new History Object record?

I have a custom object (TestObject1__c) wherein I am tracking some field changes. I also have related list under this object (TestObject1__History). The problem is the trigger I created isn't querying ...
ratRiot01's user avatar
0 votes
1 answer
227 views

Trigger to prevent duplicate records to insert

I am trying to write a trigger to prevent duplicate records to enter in my custom object. I know we can do with one list and then write SOQL . I am trying to do with Ola map but missing some where. ...
Santhosh's user avatar
0 votes
1 answer
160 views

execution of BeforeInsert caused by: System.QueryException: List has no rows for assignment to SObject

I have a trigger in place for Opportunity. This trigger is meant to fire when an opportunity reaches the 'VoB Pending' stage. trigger opportunityOwnerAlert on Opportunity (before insert,before update) ...
potato46's user avatar
1 vote
1 answer
135 views

how is Order of flows and update happen in a before create with the Flow explorer

Hia there, We are doing some code updates, we used to have all of our automations in a single flow, due to the fact, that there was no OOE that we could control. With the new Flow explorer, we are now ...
Saariko's user avatar
  • 5,610
0 votes
1 answer
54 views

Trigger is not updating custom field as expected

I have written this handler class which is called from the trigger. This code is not updating any on the below field when the trigger is executed. Can anyone please help me debug why my field update ...
Avesh's user avatar
  • 137
0 votes
1 answer
141 views

Get related id in trigger

I have an object course_reg__c with master-detail to objects course__c and Opportunity. From Opportunity, there is a lookup to Account. I have created a record triggered after insert flow on ...
Ash's user avatar
  • 5
-1 votes
2 answers
267 views

Trigger not working in my code

The problem is my trigger is not updating. I want my trigger to work even in bulk update so that is why I have a nested loop inside my function, because I need to get the parentId of the object (...
kanelopi's user avatar
0 votes
1 answer
47 views

beforeUpdate System.FinalException: Record is read-only

I'm making a Trigger that when adding a product to the Opportunities object when updating the Quantity if placed below the original value an error will appear, but when increasing the date field it ...
Kauã Roberto's user avatar
0 votes
1 answer
183 views

before update Trigger is not triggering, Debug statements not printing. With code

I need a field on this Create Ticket page to populate with data from a related object's (Company) field. I have an Apex Class, Trigger, and Test class posted below. When I run the test class I can see ...
user3918989's user avatar
0 votes
1 answer
236 views

Is it safe to perform DMLs on related records in a `before delete` trigger?

I have two custom objects: Parent__c and Child__c. Parent__c has a field called ChildId__c which is a lookup on the Child__c object. When a Child__c record is deleted, I need to check if its Id ...
user369137's user avatar
0 votes
1 answer
424 views

Trigger for Content Version (SNOTE) before Insert

I need to prevent ALL Users from creating a new Enhanced Note (we ended up creating our own object because we needed more customization). I'm trying to write a trigger but am getting stuck on an ...
Heather's user avatar
  • 51
0 votes
1 answer
154 views

Primary user Checkbox ticked for Contact with highest Commission

I'm new to Salesforce and Apex. I need help setting a trigger which checks Contacts under a specific Account. The Contact with the highest Total Commission value is marked as Primary user by ticking ...
Rad's user avatar
  • 3
0 votes
1 answer
1k views

Pass parameter to apex class method referenced in trigger through LWC

I have a trigger where I'm calling a method from handler class and I'm passing the trigger.New to that method like this: if(Trigger.isBefore && Trigger.isInsert){ List<Lead> ...
Aditya Deshmukh's user avatar
0 votes
1 answer
79 views

How can you optimize this code in my trigger? SOQL Limit

The problem that exists in production is caused by the use of the email to case tool. The case object has two lookup fields, one for account and the other for contact. When creating the case, the ...
Ramir 's user avatar
  • 29
0 votes
2 answers
377 views

How to update the Opportunity Ownerid with the current Userid in "Before Delete" Trigger

inside of a "Before Delete Trigger" I'm attempting to over-ride the record's owner ID with the User ID of the person performing the delete. if I simply assign it in the trigger like this: ...
Chris Campbell's user avatar
1 vote
1 answer
134 views

Blob is not a valid UTF-8 string error in test class though am converting base64 into normal text in apex class

Am getting case subject "?utf-8?b?QW5vbWFseSBkZXRIY3Rpb24g4oCTIERFIFNIQVc?=" In this format from third party system. So am converting into string as below: String s= case.subject; String s1 ...
Sweetie's user avatar
  • 11
3 votes
2 answers
1k views

Getting Null Pointer Exception

Happy New Year to everyone. I started salesforce Learning and getting some error while writing the trigger. Actually I created on new field on Lead object with name of UpdatedByTrigger__c and this is ...
Learn SFDC's user avatar
0 votes
1 answer
51 views

Before Update Trigger code is not working

I have written this trigger on Account oject by using trigger handler class. The before insert part of the code is working , However the before update code is not working and I checked the same using ...
Aritra Dasgupta's user avatar
0 votes
1 answer
72 views

How to write a trigger when you update an account , set its BillingCountry as a concatenation of all its related Contact's mailingCountry?

I wrote the following code but I am unsure of my solution trigger myTrigger on Account(before update){ Map<Id,Account> accMap = new Map<Id,Account>(); for(Account a : Trigger.new){ ...
Amax1's user avatar
  • 121
1 vote
1 answer
772 views

execution of BeforeUpdate caused by: System.FinalException: SObject row does not allow errors

I have this trigger to verify this condition , when and status become clos , I can't modifie the object . Now when I tried to modifie I have this error : We hit a snag. Review the errors on this page. ...
Salesforce dev98908's user avatar
0 votes
1 answer
130 views

Apply Id to the Detail record of the Master record in a trigger

Specifically, I'm trying to figure out the syntax to add the parent/master object id, to the child/detail record so the insert works without giving an error of malformed Id. I know the master name, ...
van Zylin's user avatar
-2 votes
2 answers
276 views

My trigger is not working

I tested by editing my order object and then populating a description when it runs. trigger OrderTrigger1 on Order (before insert) { switch on Trigger.operationType { when BEFORE_UPDATE { ...
FaThima Hussain's user avatar
0 votes
1 answer
585 views

How to update all records when before delete trigger is called?

Can anyone help me out? I store all the records of my TestObject__c in a List. My requirement is, if the user delete the record in TestObject__c and if the checkbox is check, one field in all records ...
ratRiot01's user avatar
0 votes
1 answer
314 views

Write field update logic in before or after trigger

I have to perform below logic to update opportunity status based on opportunity's Account's trial__c field on insert of opportunity. For(Opportunity opp : trigger.new) { If(opp.Account....
Return0's user avatar
  • 317
0 votes
1 answer
853 views

Why are we able to access the contact.AccountId in a before insert trigger during contact creation for parent account?

I am new to triggers. I saw an example where during inserting a contact a trigger set its Phone as Parent Account's Phone using the following code trigger conTrigger on Contact(before insert){ Set&...
Amax1's user avatar
  • 121
0 votes
1 answer
1k views

Check if any field of a record has change dyncamically for a bulk trigger

I am trying to run validation in before update trigger which checks if a field value has changed in a particular status for the record. If it has changed then it adds a validation error. I wanted to ...
Madhurima's user avatar
  • 1,395

1
2 3 4 5
12