Hot answers tagged

6

The easiest way to do this is to use the Developer Console, capturing the debug logs for a request that exercises your trigger and the related code then open the debug log and switch to the excellent Analysis perspective via the Debug menu's Switch Perspective option. This allows you to drill down through the call flow and call stack and lets you see amount ...


5

It is impossible explicitly, however, you can deserialize you String into List< Object> and then cast your Object in for-loop to Map< String, Object>: String jsonString = '[{"id":2,"name":"Abc_SS","description":"Abc"},{"id":100,"name":"sales","description":"sales"}]'; List<Object> items = (List<Object>) JSON.deserializeUntyped(jsonString);...


4

Is it failing because a Batch job is NOT running in System mode as triggers? No, system mode has no effect on if the batch will run. What will be affected is if the user is allowed to edit records. What is the recommended way (documented where?) to prevent such errors in packaged code using UserInfo.isCurrentUserLicensedForPackage()? Are there libraries ...


3

You should be able to achieve this through the use of named credentials: https://help.salesforce.com/articleView?id=named_credentials_about.htm&type=5 ...A named credential specifies the URL of a callout endpoint and its required authentication parameters in one definition. To simplify the setup of authenticated callouts, specify a named credential as ...


3

In the Developer Console, you can go to Debug > Change Log Levels > Add/Change, and change the Profiling flag to FINEST. Perform an operation on a record, then open the log. At the bottom of the log, you'll see each method, how many times it was called, and the total time consumed by each method.


3

I'd revisit the idea that you should only ever have one trigger per sObject - Apex Trigger Tip: Using One Trigger Per Object To Control Logic. Generally speaking - this is very good advice. But why? We do it to maintain control over the order of execution. If you just piled new triggers into the org every time you needed something new and Salesforce is ...


3

There is no way to load more than a total of 50K records in a given synchronous session/transaction (as per the documentation), and certainly no way to do this in a trigger. The only way to deal with this sort of thing is to use async processing such as in a Batchable as you mentioned. It is possible to execute certain types of aggregate query across more ...


3

To deploy: Your trigger must be exercised by a testmethod Your @future class need not be exercised by a testmethod in order to deploy provided that you have at least 75% coverage across all Apex You can specify which tests to run when you deploy. You do not need to run all tests That said, it is "developer negligence" to not write testmethods for each ...


2

You can't do both, in most cases. Using addError() blocks the transaction from committing successfully to the database (assuming the originator of the DML operation is not using a partial-success operation). When the transaction does not commit, it also blocks all other transactional operations, such as sending email, enqueuing future methods, scheduling ...


2

IP address information is not available in Apex (at least not natively). A better approach here would likely be to reject these on your site (i.e. block it before it gets sent to Salesforce. Take advantage of the reCAPTCHA option.), but the details of how to approach that are likely off-topic for this site. From https://help.salesforce.com/articleView?id=...


1

Use a Field Set, instead. That's one of their primary purposes. Your code can then be written as follows: for(Integer i = 0, s = Trigger.new.size(); i < s; i++) { sObjectField[] changes = new sObjectField[0]; for(Schema.FieldSetMember member: Schema.sObjectType.ObjectName__c.fieldSets.fieldSetName.getFields()) { sObjectField field = member....


1

My overlapping answer that converts to the list of map of string to object is very like Mariia's: String theJsonString = '[{"id":2, "name":"Abc_SS", "description":"Abc"}, {"id":100, "name":"sales", "description":"sales"}]'; Object theJsonObject = JSON.deserializeUntyped(theJsonString); List<Object> theJsonList = (List<Object>) theJsonObject; ...


1

I suggest this sort of code if there is only ever one Task at most per Account: Map<Id, Task> whatIdToTasks = Map<Id, Task>(); for (Task t : [...]) { whatIdToTasks.put(t.whatId, t); } for (Account acc : [...]) { // Update existing Task or create new one Task gTask = whatIdToTasks.get(acc.Id); if (gTask == null) gTask = new Task(...


1

You can make your existing trigger call a packaged class method , so both of the behaviours are processed in the same trigger. Create a new class TrgAccount in your new package (namespace MyNs). global class TrgAccount { global static Account execute(Account account) { // Add more arguments if necessary // Do whatever you need here ...


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