Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Hot answers tagged

7

The savepoint specifies the point to roll back to. All DML that occurs between setting the savepoint and performing the rollback is included in the rollback. If you did an update someAccount; inside your try block, you'd see the effect of that DML operation be rolled back. But that doesn't include the trigger event that started the whole process. The DML ...


4

The CPU time limit is a cumulative limit across the whole transaction. Essentially, what is happening is that your Flow, plus your Process invocations, plus the NPSP triggers that are run consequent upon the updates you are making, are taking too long to execute in a single transaction (10 seconds of CPU time). Because the CPU time limit is a cumulative ...


3

Yes, we can add more complicated logic in a trigger. Traditionally, we offload the trigger logic in to a "trigger handler" class, as demonstrated in this answer. However, to keep things simple, this is how we'd add the new logic to your trigger: trigger AutoConvert on Lead (before insert, after insert) { switch on Trigger.operationType { when ...


2

The cleanest way to generate JSON in Apex code is to use the JSON Class and that now includes this method: public static String serialize(Object objectToSerialize, Boolean suppressApexObjectNulls) that will not serialize null values when suppressApexObjectNulls is set to true. PS If the source of the data is an SObject (or some other sort of map where ...


2

Your trigger will fail any time there is more than one OpportunityTeamMember on a record. It'll update the Opportunity.Opportunity_Shared__c field to false even when there is still an OpportunityTeamMember present other than the one deleted. You'd need to perform a query before you decide which records to update. One approach would run roughly like this: ...


2

By far the simplest way to have a field on Contact that reflects the value of a field in Account is to make the Contact field a formula field that automatically presents the value from the Account field.


2

Your code is a bit hard to follow: always worth stating what you are aiming to do in the question in words and also explaining exactly what has gone wrong. Here are some general suggestions that may help: A benefit of using a handler class is that you can break pieces of logic out into separate methods so what is going on is made clearer. Don't declare all ...


2

The ChildRelationship itself has these methods: getChildSObject() Returns the token of the child sObject on which there is a foreign key back to the parent sObject. getField() Returns the token of the field that has a foreign key back to the parent sObject. getRelationshipName() Returns the name of the relationship. that provide enough ...


2

Process builders are meant to replace workflow rules. They aren't meant to replace triggers. Workflows vs. PB Process Builder lets you automate more things. Process Builder lets you control the order of your criteria. Process Builder lets you access fields on every related record. Process Builder is the future. Here is a trailhead with ...


1

I would not do business logic inside a trigger, hand that off to a "Handler" class. That being said you don't have many options here other than to query for it, which happens to be on most organizations largest datasets. Trigger AutoConvert on Lead (after insert) { LeadStatus convertStatus = [ select MasterLabel from LeadStatus ...


1

@DavidReed has a pretty clever answer but is not necessarily a guarantee of success without more knowledge of which specific Accounts and their Opportunities incur the CPU time restriction I'm going to offer two suggestions Option1 Data Loader (The tried and true) I get the impression that this task you have is a relatively infrequent event. If so, use ...


1

That's not how the relationship between front end and back end functionality works on Salesforce. A trigger is invoked when some DML event occurs to change a record. The source of that event could be a Visualforce or Lightning session, interaction with a standard UI page, a Batch or Scheduled or Queueable or Future Apex call with no associated UI context, ...


1

This sounds like a perfect use case for batch apex You can create a batch class that loops through all your contacts and populates the fields based on the logic you define. To run the batch, you have two options: Run in manually through the developer console using anonymous apex (which is a way of calling apex on the fly) Create a scheduled class that can ...


Only top voted, non community-wiki answers of a minimum length are eligible