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
6
votes
0answers
2k 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 business ...
5
votes
1answer
899 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 ...
4
votes
1answer
108 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 ...
4
votes
1answer
58 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 ...
3
votes
3answers
355 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 ...
3
votes
1answer
112 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 ...
2
votes
1answer
1k 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 ...
2
votes
2answers
48 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 ...
2
votes
2answers
2k 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 ...
2
votes
1answer
996 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 ...
2
votes
1answer
42 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 ...
2
votes
2answers
3k 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) ...
2
votes
3answers
94 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) ...
2
votes
2answers
45 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 ...
2
votes
1answer
65 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?
2
votes
1answer
2k 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 ...
2
votes
2answers
132 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 ...
2
votes
1answer
70 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 ...
2
votes
1answer
158 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 ...
2
votes
1answer
468 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() == '...
2
votes
1answer
119 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 ...
2
votes
1answer
27 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) ...
2
votes
0answers
463 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-...
2
votes
2answers
357 views

After insert trigger not reading lookup values

I have object customObjectA__c which has a lookup fields - lookupfield1__c I have an after insert trigger which, at some point, checks if that field is populated. The whole issue is, it's reading ...
1
vote
2answers
487 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 ...
1
vote
2answers
51 views

How to convert this trigger to apex Class

I've written this trigger to Update Total Numbers of Contact in related Account Custom Field... All Code is written in Apex Trigger However, I've been told that it's best practice to split this into ...
1
vote
2answers
53 views

Best way to process the records in After Update triggers - Sets or Lists

This may be a very primitive question but am failing to choose the best way and am trying to follow the best practices. We have many Salesforce Apps implemented, as a result there are many record ...
1
vote
2answers
279 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 ...
1
vote
2answers
59 views

Trying to update Values in Standard Object from metaData

Trigger is updated to Before UPdateI am using Trigger isBefore In System.debug(opp.get(metaData.get(0).Opportunity_Field_Name__c) it is showing correct Values but not Updating in Opportunity Object ...
1
vote
1answer
72 views

How write tigger Insert & update other records same object with update query

I have this trigger where I insert a record. On the insert I want to check on birthdate and set a checkbox on true for the record with the oldest birthdate related to same Household/Huishouden__c. ...
1
vote
1answer
271 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 ...
1
vote
1answer
1k views

Execution of AfterInsert caused by: System.FinalException: Record is read-only

I am creating a cross-objects trigger that whenever a new opportunity is opened, the trigger goes to check whether the company has sold the same product to the customer before; if so, the type of the ...
1
vote
2answers
61 views

Creating/updating new object based on a logic in a trigger

I have two object , abc__c and xyz__c. xyz__c has a field named key__c which should store the id of abc__c object. abc__c has a picklist field status__c which can have different value "In-progress" , ...
1
vote
2answers
391 views

Cross-Object SOQL Query

I have a set of custom fields on my Accounts object that depict weather an Account is approved for business with our company. The Approved Date is added via an Approval Process, and Account Status is ...
1
vote
1answer
109 views

how to know Orderitem trigger is triggerred by order trigger

some fields on orderitem can only be changed when the order is changed, so I need orderitem trigger to know if it's triggered by order trigger. how can I do this? Thanks
1
vote
3answers
70 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, ...
1
vote
2answers
38 views

Hari Krishnan based Trigger Framework executes twice on After Update

I have a trigger framework based on the work by Hari Krishnan: An architecture framework to handle triggers on the Force.com platform, however I have functionality on After Update in wich a trigger ...
1
vote
1answer
36 views

System.TypeException: Invalid integer: (Lead-0002)

I have created a round robin assignment of leads to users. I am getting the following error Lead_Trigger: execution of AfterUpdate caused by: System.TypeException: Invalid integer: (Lead-0002) ...
1
vote
1answer
463 views

How to perform DML operation in after insert, after update trigger

I am new in developing apex. Here is my trigger. When I try to update an account record, I get the error: " Error:Apex trigger pfUpdate caused an unexpected exception, contact your ...
1
vote
1answer
47 views

Change lookup relation parent on convert

I may have my terminology off as far as who the parent in the relationship is. However what I am trying to accomplish is take a custom object email_campagin__c attached to a lead and switch it over to ...
1
vote
1answer
158 views

Incompatible key type object for Map<id,account>

I am trying to write apex code (and I'm learning how) to roll up data from the on the Account from an object with a lookup relationship to the object. Fields from Account: ID, DealCount__c Fields ...
1
vote
1answer
41 views

how to finding the duplicates in the map of lists?

I have a requirement.for that I create a trigger. on that trigger I am using the Opportunity -Sobject and List of OpportunityContactRoles comes under the opportunity. Now I form the map as ...
1
vote
1answer
5k views

Trigger to update field values from another object

I got this scenario where there's two object say A and B, both of them having a field called BCode and Code . Now, if the values match then another field called X in A has to be populated with the ...
1
vote
1answer
22 views

trigger to update a custom field in account when related opportunity is created with same value as in custom field of Opportunity

Can someone please elaborate what is mapAccounts.get(opp.AccountId) is getting here MapAccount acc = mapAccounts.get(opp.AccountId); trigger OppTrigger on Opportunity (after insert) { if(...
1
vote
1answer
34 views

Why doesn't my code enter for loop when record found?

I have an object(Huishouden__c) with a related list. I loop trough the object records with a for loop on the related record. When I debug the object in the first loop I get an Id but it does not enter ...
1
vote
1answer
268 views

Test class silently fails to add product?

I have a trigger that executes on after insert and after create on the Opportunity that updates fields on the OpportunityLineItem Object. Code works but the test class opportunity does not appear to ...
1
vote
1answer
119 views

Case owner not able to change case owner after insert

I am trying change the case ownerid to Queue but getting System.FinalException: Record is read-only error in after insert. Below is the my code: if(Trigger.isInsert && Trigger.isAfter) ...
1
vote
0answers
17 views

Does Apex lead conversion trigger Contact before/after insert triggers? [duplicate]

I have some updates I'd like to make on converted leads. I had it in my lead code - first convert the lead, then query for the converted contact and update. However, that was triggering ...
1
vote
0answers
151 views

Insert operation triggering NOT(ISNEW())

I would like to ask for help regarding why an insert operation would trigger and fail this validation rule: AND(NOT(ISNEW()), ISPICKVAL(Pipeline_Type__c,'Licence'), ISBLANK(Related_Pipeline__c)) The ...
1
vote
1answer
52 views

When Managed Package Deletes Records via Bulk Data Load Job, Before/After Delete Apex Doesn't Run

Background: We have a Managed Package that syncs data with our system via Bulk Data Loads. Occasionally, based on a change in Salesforce, record(s) are sent to the external system and then ...