If you have encountered this error while working on Triggers. This is because once you are in an after insert/update trigger and the records are read only in that context as they have been written, but not committed, to the database. Unfortunately your trigger is relying on the ids of the records, which means you …
Category: Apex
Permanent link to this article: https://salesforcebuddy.com/2019/01/record-is-read-only-trying-to-update-in-after-insert-trigger/
Jan 24
Apex : Throwing Custom Exceptions
There will be scenarios when you want to throw an exception from your catch block, may be to propagate to the invoking class so it is handled properly. Below is a Custom Exception class which can be used to throw different types of exceptions as needed. public with sharing class CustomExceptions { public class InputDataException …
Permanent link to this article: https://salesforcebuddy.com/2019/01/apex-throwing-custom-exceptions/
Jan 22
Salesforce Collections : Map from SOQL
There must have been times when creating a map from a SOQL is required. I am showing 2 ways of doing the same. Map from List ( obtained from SOQL)Map<Id, CustomObj__c> myMap = new Map<Id, CustomObj__c>();for(CustomObj__c objCS : [Select Id Name,Status__c From CustomObj__c ]){myMap.put(objCS.Id, objCS); …
Permanent link to this article: https://salesforcebuddy.com/2019/01/salesforce-collections-map-from-soql/