Questions tagged [after-trigger]
After triggers are used to access field values that are set by the system (such as a record's Id or LastModifiedDate field), and to affect changes in other records.
458
questions
0
votes
1
answer
31
views
ContentDocumentLink Trigger referencing User Object for LInkedEntityID
I have a requirement to create an Email notification when an attachment is added to a custom object. I have seen other questions and resolutions here that reference the fact that LinkedEntityId cannot ...
0
votes
0
answers
19
views
Setting a custom field with value of LeadOrContactOwnerId isn't working in before update trigger but working fine in after update trigger
I am trying to set a custom field (FCRM__FCR_First_Owner_Worked__c) on CampaignMember equals to LeadOrContactOwnerId in certain situations.
I tried it using before flow on Campaign Members but I am ...
0
votes
1
answer
24
views
Send email in AfterUpdate of new record using the new record for merge fields
We have a record for which an email needs to be sent, but the sendEmail process is happening in the AfterUpdate of the triggerhandler.
The email template being used is a VF component/HTML one with a ...
0
votes
0
answers
48
views
Before Trigger on User also firing as an After Update Event
I have a before trigger on user which checks if a checkbox is selected and assign a manager if user's team matches another user's.
The issue is that the trigger should only run on before insert or ...
0
votes
1
answer
48
views
I am trying to write a trigger on opportunity that will create order and order item on opportunity update event but facing issue
here is the senerio" when an Opportunity is closed as "Won", the trigger should automatically create a new Order and populate it with Order Line items based on the products and ...
0
votes
1
answer
47
views
Creates the number of contacts which are equal to the numberwhich we will enter in the Number of Locations field on the Account Object
//Code Sniippet
public static void createNewContacts(list<account>AccountHasManyList) {
list<contact> ListOfContact = new list<contact>();
for(account acc:...
0
votes
3
answers
96
views
How to find the max amount of an opportunity without using aggregate result in apex trigger?
Trigger Handler:
public class oppHandler {
public static void updateoppName(List<Opportunity> oppList,Map<Id,Opportunity> mapoldOpp)
{
Set<Id> accIds=new Set<...
0
votes
1
answer
64
views
create the location records when the Account is created and the “Number of Locations” field has some value in it
Prerequisite
Create a Custom Object and Name it Location. Relate this location object with Account using Lookup relationship.
Create a field on Account “Number of Locations” of type Number
Develop a ...
0
votes
1
answer
32
views
Error while updating Lookup field on Case recprd after insert from Web-to-Case form
I'm trying to update the lookup field (Account ID) using the trigger after inserting the Case record by using the Web-to-Case form. But it is throwing the error "FATAL_ERROR|System.FinalException:...
1
vote
0
answers
92
views
Can we override the System defined Exception message using the Custom Exception Handling?
I have tried to handle the system defined Exception using the Custom Exception in Apex but only the message part gets overriden. Is there any chance that we can override the entire system defined ...
1
vote
2
answers
71
views
Nested for loop causing error "System.LimitException: Too many DML rows: 10001"
I have a trigger handler class afterInsert() with following code:
public void afterInsert() {
if(Handlerclass.isafterInsert){
Handlerclass.isafterInsert = false;
...
4
votes
1
answer
205
views
Debug Log shows Flows executing in a different order to Flow Trigger Explorer
Just wondering if someone can help me to understand what I'm seeing in our org. I'm trying to document the order in which our automation runs when a Lead is created. My problem is that I'm seeing ...
0
votes
1
answer
53
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.
...
-1
votes
1
answer
97
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 ...
0
votes
0
answers
32
views
Error when running a bulk update to trigger a trigger: Required fields are missing: [Status]: [Status] (LabsActionPlans): []
I have created a trigger on the Task object which executes afterUpdate, afterInsert and beforeDelete. This trigger will get the relevant Opportunity using the WhatId field on the task, run some logic, ...
0
votes
0
answers
146
views
Best practice for designing flows that require recursion and same-record updates
I'd like some inputs on the current best practice for building Flow automation which a) needs to update the same triggering record but only after an action (like sending an email) that isn't available ...
0
votes
0
answers
48
views
Several updates on Case record withing short period of time causing "duplicate value found: <unknown>"
I have pretty complex process starting with scheduled Batch Apex, calling my Mulesoft endpoint to retrieve some data and save it on Case record:
Batch apex request from Salesforce to Mule is ...
0
votes
0
answers
21
views
Manager Id is not updating whenver the user is deactivated using apex trigger [duplicate]
My implementation:
trigger userTrigger on User (after update) {
Switch on Trigger.OperationType
{
when AFTER_UPDATE
{
userHandler.checkUser(Trigger....
0
votes
0
answers
78
views
ManagerId is not assigning for inactive user using apex trigger?
My Trigger Scenario:
𝑾𝒉𝒆𝒏𝒆𝒗𝒆𝒓 𝒂 𝒖𝒔𝒆𝒓 𝒊𝒔 𝒅𝒆𝒂𝒄𝒕𝒊𝒗𝒂𝒕𝒆𝒅 𝒂𝒔𝒔𝒊𝒈𝒏 𝒂𝒍𝒍 𝒉𝒊𝒔/𝒉𝒆𝒓 𝒂𝒄𝒄𝒐𝒖𝒏𝒕𝒔 𝒂𝒏𝒅 𝒄𝒐𝒏𝒕𝒂𝒄𝒕 𝒕𝒐 𝒕𝒉𝒆 𝒓𝒆𝒔𝒑𝒆𝒄𝒕𝒊𝒗𝒆 𝒖𝒔𝒆𝒓'𝒔 𝒎𝒂�...
0
votes
1
answer
87
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 ...
-1
votes
2
answers
79
views
I'm getting error like Invalid id value for this SObject type in after update call using apex trigger
My Trigger Scenario:
write an apex trigger to update the related contacts with the latest country field value
whenever it changes on the parent account record.
My Implementation:
public static void ...
0
votes
1
answer
44
views
For update operation,average amount is not updating in apex trigger
Trigger scenario:
𝐖𝐫𝐢𝐭𝐞 𝐚𝐧 𝐀𝐩𝐞𝐱 𝐭𝐫𝐢𝐠𝐠𝐞𝐫 𝐭𝐡𝐚𝐭 𝐜𝐚𝐥𝐜𝐮𝐥𝐚𝐭𝐞𝐬 𝐭𝐡𝐞 𝐚𝐯𝐞𝐫𝐚𝐠𝐞 𝐨𝐟 𝐚𝐥𝐥 𝐫𝐞𝐥𝐚𝐭𝐞𝐝 𝐎𝐩𝐩𝐨𝐫𝐭𝐮𝐧𝐢𝐭𝐲 𝐀𝐦𝐨𝐮𝐧𝐭𝐬 𝐚𝐧𝐝
𝐮𝐩𝐝𝐚𝐭𝐞𝐬 𝐚 �...
0
votes
1
answer
41
views
What is the best approach for inserting large data set in Apex trigger?
my trigger scenario:
𝐖𝐫𝐢𝐭𝐞 𝐚𝐧 𝐀𝐩𝐞𝐱 𝐭𝐫𝐢𝐠𝐠𝐞𝐫 𝐭𝐡𝐚𝐭 𝐜𝐚𝐥𝐜𝐮𝐥𝐚𝐭𝐞𝐬 𝐭𝐡𝐞 𝐚𝐯𝐞𝐫𝐚𝐠𝐞 𝐨𝐟 𝐚𝐥𝐥 𝐫𝐞𝐥𝐚𝐭𝐞𝐝 𝐎𝐩𝐩𝐨𝐫𝐭𝐮𝐧𝐢𝐭𝐲 𝐀𝐦𝐨𝐮𝐧𝐭𝐬 𝐚𝐧𝐝
𝐮𝐩𝐝𝐚𝐭𝐞𝐬 �...
0
votes
0
answers
52
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(...
0
votes
1
answer
56
views
Trigger Error Handling
I have an after update trigger on Account which updates the child contacts Industry field.
Sample Code:
Trigger accountTrigger on Account(After Update){
Map<Id, Account> acMap = new Map<...
-1
votes
2
answers
63
views
Preventing Trigger Recursion codeLive Questions
A minor questions from the Preventing Trigger Recursion CodeLive.
One main purpose of this video is to create a trigger that will work on bulk DML. The static boolean doesn't work because only the ...
0
votes
1
answer
208
views
Apex Trigger rollback DML operation if error occurs in bulk insert
So I'm using the XL-Connector add-on to insert some 30k records into the database. The records are inserted in batches of 200. Based on some complex logic in the insert trigger, I'm determining if ...
0
votes
1
answer
110
views
there must be only one primary contact on account by utilising isprimary checkbox
stuck in here What if someone uses dataloader and make 2 contacts for same account as primary, then my code is not working
public class Contactispr {
public static void Conta(List<Contact> ...
2
votes
1
answer
788
views
Create ContentDocumentLink after insert ContentDocument error
I have pretty simple requirement but I am facing error and I can't understand what is going wrong.
I need to add ContentDocumentLink to add file to CollaborationGroup after insert with C permission. I ...
0
votes
2
answers
45
views
AfterInsert caused by: System.FinalException: Record is read-only
I want to update a record that has recently been created.
Trigger:
trigger TTCaseTrigger on Custom_Case__c (after insert) {
if(Trigger.isInsert && Trigger.isAfter){
if(...
-1
votes
2
answers
39
views
I'm not able to Insert New releted contact with with 'Primary Contact' checkbox checked. help me out there
trigger PrimaryContactTrigger on Contact (before delete, before update, before insert) {
if (Trigger.isBefore) {
if (Trigger.isDelete) {
for (Contact con : Trigger.old) {
...
0
votes
2
answers
100
views
How to update values in related object fields after record is deleted
I have two objects ObjA__c and ObjB__c which are in many-many relation. Now there is a field on ObjA__c which is sum__c and this value is a sum of rank__c field on ObjB__c.
For ex:
If ObjA__c has 3 ...
-2
votes
1
answer
844
views
Field is not writeable: Account.ShippingAddress
I was coding a trigger for automatically fill up shipping address when a account is created with billing address.
code down below
trigger BillingAdd on Account (before insert) {
List<Account> ...
1
vote
1
answer
155
views
How to rearrange the priorities of the records using Apex?
I have a requirement to auto update priorities based on the input from the user.
On Object Requests__c I have 2 fields Priority__c(Number) and Board__c (Picklist values A, B, C and D).
Suppose if I ...
0
votes
0
answers
54
views
Unable to fetch the most up-to-date value from Trigger
I've encountered an issue with retrieving the latest BillingLatitude value through a trigger. It consistently retrieves the old value in an 'After Update' Trigger, even when the entire address is ...
0
votes
1
answer
169
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 ...
-2
votes
3
answers
111
views
caused by: System.SObjectException: Opportunity.AccountId does not belong to SObject type AggregateResult
I simply wanted to update inserted line item count on Account field Name Line_Item_Counts but ended up with this issue. code is errorless but at the UI I am unable to insert Quoteline Items
Here is ...
0
votes
0
answers
189
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 ...
0
votes
0
answers
24
views
Unable to get full code coverage for a SF trigger after update [duplicate]
I have a simple Apex trigger, written for an object called Application__c, and it fires after the "Shipping_City__c" field changes:
1.trigger MyTrigger on Application__c (after update) {
...
-2
votes
1
answer
80
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....
2
votes
1
answer
205
views
Trigger IF statement will not fire
I have a trigger that has an If statement in it, that if statement should pick up any new lead assigned to the Pre Qual queue. This Queue is set when I manually create a new lead and click the use ...
0
votes
1
answer
210
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 ...
-1
votes
2
answers
793
views
List index out of bounds: 0 in IF condition
There is an error on line 36: List index out of bounds: 0
Why am I getting this error when I'm not actually using the value, instead I'm just checking if it's null?
1
vote
1
answer
51
views
Updated triggering record with value from related record
I have a Flow that gets triggered when a User Lookup field (Support Specialist User) is changed/set. In an After-Update Record element two fields on the same record should be updated with the user.id ...
0
votes
1
answer
397
views
How to get the Lead Record using ConvertedContactId field in after Insert Trigger on Contact?
Scenario: I have a Lead record and it's single child record.
On this child record of Lead I have a look up of Contact and Account also.
Whenever a Lead is converted to Account and Contact, I want to ...
0
votes
0
answers
115
views
EmailMessage Trigger causes missing EmailStatus records
An apparent problem we have found using an Apex Trigger on the standard 'EmailMessage' object is as follows:
The trigger handles the 'after insert' event and when an email is sent (e.g. from an Apex ...
0
votes
2
answers
88
views
Adding a local variable into a trigger gives error
I'm working on creating a trigger that uses one of the methods from the URL class and has a local variable. When I don't use a local variable it works but when I try to introduce a string it give me ...
0
votes
1
answer
162
views
when converting lead i want to check lead email is equal to existing account email if it is then i want to create opportunity under existing account
i have 2 methods in trigger ,one is if the lead have initial and final fields values then i want to create opportunity line items and subscription and this is working fine.
second is when converting ...
0
votes
1
answer
409
views
TriggerHandler Question about New/ Old Values
I am trying to compare the 'old' value with the 'new' value on a record after it is updated using a TriggerHandler. Below is my code for the TriggerHandler class and also the Trigger.
Specifically, I ...
0
votes
1
answer
159
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 ...