New answers tagged

3

When used in bulk, yes, it could hit the SOQL governor limit. You should use the normal Aggregate-Query-Update pattern. Set<Id> contactIds = new Set<Id>(); // Put contactIds in to Set for(Case record: Trigger.new) { contactIds.add(record.ContactId); } // Use AggregateQuery to find cases with 2+ for same Contact contactIds.retainAll( new Map&...


0

For future wanderers - you can run addError() on a particular field of a record and messages from different fields don't override each other.


0

Yes. Salesforce implements transaction-level database isolation. This means that two records inserted in two different transactions wouldn't be able to "see" each other until the transaction completes, but within one transaction (including all cascading triggers, etc), you can query those results in an after DML trigger or later. If this were not ...


0

Does a trigger execution happen on a separate thread? No. All synchronous Apex is executed in a single thread for each transaction. Note that threads are rarely a useful framework for describing Salesforce execution contexts because you have no control over threading; rather it's usually more helpful to think in terms of transactions and synchronous versus ...


1

To add an error to record in a trigger, you must use the records in Trigger.new/Trigger.newMap/Trigger.old/Trigger.oldMap. You're looping over the wrong variable to use for the error. public with sharing class DuplicateAccount { public static void DuplicateAccountHandler(List<Account> listAccount){ Set<String> accountName = new Set<...


1

you must be marking the opp field Final_Approved__c as true on last approval by approval field update. In this case your approval field update is hapenning before approval data is commited to the data base i.e before save point. to fix this, in case when your field Final_Approved__c is true you can run the future method from the trigger which will run after ...


1

Your current Apex Trigger on Return_Shipment__c will only perform before update trigger when it detects that your "Final_Approved__c" field = TRUE. Since you are SOQL-ing out the Return_Shipment__c Approval, just run an IF check for ProcessSteps.Comment != Null. In that IF loop, copy the ProcessSteps.Comment to Return_Shipment__c.Approver_Comments(...


0

There is a mistake in the Loop object. The return arrow from the 'Assignment' object, needs to go to the Loop object, and not the 'Decision' object. A way to identify this was also to use the 'Auto-Layout' feature. It mentioned the error, only I had to figure out what it meant.


1

If Line 51 is indeed Integer noOfDays = oldOppr.daysBetween(newOppr); the problem should be pretty clear from the debug logs you already have in place: system.debug('oldOppr===='+oldOppr); system.debug('newOppr===='+newOppr); That should immediately show you where you have a null value that you need to write appropriate business logic to deal with. You ...


2

Your update of Opportunity at the end of the trigger causes the Opportunity trigger to run again, resulting in a never ending loop. But it looks like you are modifying OpportunityLineItem and so should be adding those to a list and updating that list. That change is likely to fix the problem. In general, only doing an update when the data actually changes ...


1

Sounds like you need a recursion blocker for your trigger handling. If not familiar with the concept - this knowledge article is a good start. (There are many approaches and opinions on offer out there.)


Top 50 recent answers are included