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.

Filter by
Sorted by
Tagged with
9 votes
4 answers
9k views

Debug Record-Triggered Flow

Love the new Summer '20 release features for flow, excited to use Flows in place of Process Builder. One consideration I wanted to verify with the community. Is there a way or a best practice for ...
Xtremefaith's user avatar
  • 4,560
8 votes
4 answers
6k views

Best use of After Update Trigger and Before Update

Please read my post before marking as duplicate or irrelevant. :pray: I have a scenario where I want to update the associated Asset record on Status update. I have implemented this scenario using ...
Sagar Hinsu's user avatar
6 votes
1 answer
2k views

Is it possible to write Trigger for Before & After DML?

I'm wondering if I can write the trigger on Case, that works before and after DML in one file? I have two triggers on Case - first with method working on records before insert, and second for records ...
fabtosz's user avatar
  • 181
6 votes
1 answer
9k views

ContentDocumentLink Apex after insert trigger error

Edit: I've built an after insert trigger on ContentDocumentLink. On cropredy's direction, I've bulkified my code and I think improved it generally. It "works" in that it accomplishes my ...
tim shores's user avatar
5 votes
1 answer
840 views

Check whether an sObject is read-only

Question - How can I determine that an sObject is read-only (due to being part of Trigger.New in an after trigger or otherwise). Explaination - I've been making a method to try and generically get ...
IllusiveBrian's user avatar
4 votes
1 answer
609 views

Insert and return in test data factory

Why do we sometimes add a new record to an object and then just return the variable and sometimes we insert it too. I am confused, can somebody clarify me on this?
user3920709's user avatar
4 votes
1 answer
196 views

Why won't Apex IF statement work in Production Unit Testing after working in sandbox?

this is driving me NUTS and any thoughts are MUCH appreciated after looking at this for far too long. Use case: users in certain profiles need to be automatically added/removed from a particular ...
NNPPOINTER's user avatar
4 votes
1 answer
3k views

Obtaining Prior Record Values Using Asynchronous Flows

I created a flow that launched asynchronously and leverage the prior record values. {!$Record__Prior} The flow was unable to launch because I was referencing the prior record. So what I did was remove ...
Matthew Metros's user avatar
4 votes
1 answer
66 views

Need help in optimizing the below helper class

Logic : For any new record inserts for 'Properties' object, check if its Account_Ref_Ext_ID__c equals to 'Account' object's Chris_Account_Number__c. If it matches, assign Account id to properties ...
SFDC Sydney's user avatar
4 votes
1 answer
6k views

How can we find out the deleted record in After delete trigger?

I am writing a trigger to handle after insert,after update and after delete events. I am using trigger.old for after delete.But, how to differentiate the deleted record from the rest of the records of ...
Shobhit Saxena's user avatar
3 votes
3 answers
1k views

How can I know if it's the last execution of an After Trigger?

Imagine one object with 20 fields, field1 to field20. Some of these fields I have Process Builder in place, some of them I have Worflow Updates, and some of them are 'bare field' (i.e. PB and WF does ...
Leandro Ferreira Fernandes's user avatar
3 votes
2 answers
5k views

Why do we need to update related records in an after trigger but not before?

Why do we need to write the logic to update a related record in an after trigger but not before? Update triggers(Before/After) will have both the record ID and the related record's ID so why can I not ...
User2529's user avatar
  • 703
3 votes
1 answer
301 views

trigger working as expected from UI but not from data loader/workbench

I have written one trigger.It is working as expected when i am updating owner from UI. but it is not working when i am updating from DataLoader. Requirement :- in Lead description - add Lead owners ...
Aditi's user avatar
  • 35
3 votes
1 answer
703 views

How do I avoid a Duplicate-value during update in Trigger?

I'm changing the Clients__c value in Mopping__c if the StartDate__c, Status__c or Opportunity__c have changed in the needed Rent__c. Structure: if Mopping 1 is related to Rent 1 which is related to ...
Apelsinova's user avatar
2 votes
1 answer
4k views

APEX Lock and Unlock a Record

I wanted to lock and unlock records based on a check box. I know that you can do this stuff via a validation rule but I think that is difficult to maintain if adding fields. I wrote an apex trigger ...
Brooke's user avatar
  • 389
2 votes
2 answers
14k views

How do reference a related object within a Salesforce Trigger?

How do reference a related object within a Salesforce Trigger? I am creating a record for a related object and need to assign a value to one of the fields in the new related object (relatedOject1) ...
SECBullDawg's user avatar
2 votes
2 answers
860 views

trigger to update field on Account record whenever a new Contact, opportunity record is inserted or deleted

Number fields on Account : "No of Contacts" Write trigger to populate/update field on Account record whenever a new Contact record is inserted or deleted. -- whenever i am deleting last contact ...
Dave's user avatar
  • 480
2 votes
2 answers
3k views

How to avoid this "Too many query rows: 50001"?

I have an afterInsert trigger for finding duplicates leads and if duplicate lead is inserted take its values and put it in a custom object record and lastly delete this new duplicate Lead record. It ...
Dnyaneshwar's user avatar
2 votes
1 answer
397 views

Do trigger.newMap and trigger.oldMap have the same keySet() in apex after update triggers?

My potential use case by knowing the answer to this question would be, if I'm working with a legacy code and I can't make modification to the method signature and I only have access to trigger.new and ...
Bahman.A's user avatar
  • 838
2 votes
1 answer
1k views

Trigger After Insert Error : Record is read-only

still learning the apex ropes I've created a trigger which should create a contact after a custom object (School_bookings__c) record is created. My code is as follows: trigger CreateSchoolContact on ...
Rufus K.'s user avatar
  • 505
2 votes
1 answer
3k views

Method does not exist or incorrect signature: void valueOf(Object) from the type Decimal

I am getting errors when storing my aggregate result value in the currency field. I have tried to look into a similar error but not getting anything. Below is the logic which I am trying to implement. ...
Avesh's user avatar
  • 137
2 votes
1 answer
1k views

Apex Trigger Is Firing Twice on Record Insert?

EDIT: SOLVED by Nagendra Singh I had messed up my trigger calling for an ifBefore > all triggers, then calling for all the triggers again after the ifBefore clause. I added an else clause to fix ...
User's user avatar
  • 111
2 votes
1 answer
1k views

How to bulkify a flow launched FROM Apex Trigger?

I am launching a flow from APEX and I want to pass it a list of IDs. The issue that I am coming across right now is that I will need to look up each ID in the flow because there is no "IN" clause for ...
Matthew Metros's user avatar
2 votes
2 answers
1k views

How to retrieve Parent's Id of a triggered child record, inside the trigger - Solved

Certification__c(Parent object) --> Exam__c(Child object) Trigger triggers when Child is updated. trigger certificationToFailedNew on Exam__c (after update) { //List out all the exams associated ...
Niveth Kumar's user avatar
2 votes
1 answer
59 views

Failure setting lookups in triggers when upserting multiple records of different types very quickly

I have an integration app that polls records of different types from an internal database every few seconds and upserts them into Salesforce. I have two pollers that run independently from one another ...
zed917's user avatar
  • 35
2 votes
1 answer
1k views

Unit test keeps failing an "Insert" Campaign Member Status Apex Trigger (works in UI)

I am trying to write a Unit Test that passes an Apex trigger for inserting 2 custom CampaignMemberStatus records. The trigger is performing as expected in the Sandbox UI as an end user, however it ...
GPP's user avatar
  • 553
2 votes
3 answers
260 views

Comparing @future vs non-future and beforeUpdate vs afterupdate when using DMLOptions to perform LeadAssignment in an Apex Trigger

When using Apex Database.DMLOptions for invoking standard Lead Assignment Rules, is it sane to use beforeUpdate instead of afterupdate? And is it sane to do this in non-future apex vs (as opposed to) ...
Peter Noges's user avatar
  • 1,110
2 votes
2 answers
604 views

Pass Trigger.old to constructor

I am not able to pass Trigger.old to constructor, Trigger trigger Test on Student_Details__c (after insert, after update,after delete) { studentupdatehandler studobj = new ...
Niknit's user avatar
  • 115
2 votes
1 answer
47 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 ...
Matt's user avatar
  • 51
2 votes
2 answers
1k views

Queueable being called from a trigger by an Asynchronous Process

Recently we moved our logic in our trigger to be asynchronous and now the helper method that the triggers call looks something like this (specifics obfuscated since it's company code): global static ...
J. Larson's user avatar
2 votes
2 answers
1k views

trigger to update Custom field on Account record whenever a new opportunity record (Whose Title contains 'CEO') is inserted or deleted

Trigger to update Custom field(Count_Of_Title_in_Opp__c) on Account record whenever a new opportunity record (Whose Title contains 'CEO') is inserted or deleted Trigger trigger OppSizeOnAccount on ...
Dave's user avatar
  • 480
2 votes
1 answer
2k views

Formula not having updated value in After Trigger : Apex Trigger

updateTemplate((List<Object>)tp.newList, (Map<Id, Object>)tp.newMap, (Map<Id, Object>)tp.oldMap); In the method I am querying updateTemplate I have a query as below Map<Id, ...
Nagendra K S's user avatar
2 votes
2 answers
497 views

Record is Read Only on After Insert Method

I wrote a method that works when it is before insert in my trigger handler. A problem I encountered is that the after insert method that already existed failed to run. I cannot figure out why it does ...
Dan Wooding's user avatar
  • 3,538
2 votes
1 answer
137 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 ...
Sgrove 's user avatar
2 votes
1 answer
259 views

Why am I getting an error about recursive update in my trigger when I add a rollup summary field?

I have a trigger on a parent object that manages master detail child records. This trigger needs to check a given flag field on the parent record to determine whether it needs to process the child ...
Phil W's user avatar
  • 36.2k
2 votes
1 answer
1k views

Hitting Standard Duplicate Rule

I'm playing with a trigger exercise, that consists of creating a trigger to create 10 Opportunities whenever a account with more than 100 employees are created. I made the following: trigger ...
RedMan's user avatar
  • 107
2 votes
3 answers
159 views

Limitation with callouts

I want to listen to the change in permissions of salesforce records. For that, I am thinking to fire a callout from an afterUpdate method of a trigger. Whenever a record is updated through any means, ...
Rajeev's user avatar
  • 151
2 votes
1 answer
282 views

Logic written in AfterInsert does not finish when beforeUpdate is called

We are creating OpportunityLineItem through Apex, now in isAfterInsert we are creating a Test object record whose Unique_Key is same as OpportunityLineItem unique_key. Now attaching the 'Test' to ...
Nagendra K S's user avatar
2 votes
1 answer
287 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 ...
Maciej's user avatar
  • 45
2 votes
1 answer
1k views

How to Capture Approval Comments in Case Object Custom field called comments ? Below code i am getting an error trigger depth exceeded?

trigger CaseApprover1 on Case (after update) { List<ProcessInstance> instances = [SELECT Id,TargetObjectId,(SELECT Id, StepStatus, Comments FROM Steps) ...
Santhosh's user avatar
2 votes
1 answer
856 views

Delete/Prevent trigger on Feed Item

The initial idea was to block all chatter feed from external batch jobs which run nightly. We had a trigger do it. trigger PreventPost on FeedItem (before insert) { if(UserInfo.getProfileId() == '...
Rohit's user avatar
  • 23
2 votes
1 answer
362 views

Getting 101 SOQL error when updating bulk records through data loader

I have a trigger which updates the total amount of child record values into parent record fields. It is working fine when I do the single records insertion. I have 50000 child records which are ...
KSL's user avatar
  • 512
2 votes
0 answers
117 views

Problem with trigger time executions

I have 2 triggers after insert wich call one apex class each one. One of them call an apex class for make a query to get an Id from the first trigger execution. I need this ID to match two differents ...
Emanuel Mayo's user avatar
2 votes
0 answers
1k views

DescribeFieldResult.getReferenceTo returns only one type in a specific scenario

I am seeing some strange behavior where DescribeFieldResult.getReferenceTo returns only one type for the Lead.OwnerId field in some cases when invoked in a trigger context. The code below displays ...
Jelle van Geuns's user avatar
2 votes
0 answers
1k views

AgentWork trigger is not firing before or after insert events

I have created an after/before insert trigger defined on AgentWork object. When a case is created from Email to Case, the record is automatically routed to an available Agent from a queue by Omni-...
Renu Kumar's user avatar
1 vote
2 answers
214 views

Is my after insert trigger efficient and safe to port to production?

Recently I created an after insert trigger to update a field in my sponsorship object. it works so far in sandbox and has passed the unit test that I have created and has 100% code coverage. here is ...
Apex_rookie's user avatar
1 vote
1 answer
99 views

Update trigger for Custom object having 470 custom fields

I am having a custom object with 470 fields in it. And in After update trigger I am making some call outs. If a value is changed in any of the field then I need to have lengthy check for all the ...
SFDC-Beginner's user avatar
1 vote
2 answers
2k views

Apex Trigger Order of Execution Transaction

I am a bit confused lately regarding the order of execution of multiple updates: Consider the following scenario: I have Three Records: A and B and C A fires an after update trigger that updates ...
Z33dawg's user avatar
  • 1,411
1 vote
1 answer
654 views

Trigger runs twice but Trigger.Old does not change?

Creating a record (of a custom sObject) when the record type is changed (by the user) on the Case record. Org has a variety of Process Builder and Workflows and the trigger is running twice. This is ...
Bobbygllh's user avatar
  • 731
1 vote
1 answer
3k views

pass list of sObject from one queueable job to another

I am trying to pass Sobject from trigger to a queueable and then i am calling another queueable and trying to pass the same sObject. But i am unable to get the values in queueable . Trigger - ...
sfdc_to_learn's user avatar

1
2 3 4 5
9