Archives

Apex Return Diff fields between records

Sometimes you want to determine what has changed between an existing record in the database and an update to the record. The diffRecord method will return all the fields that changed for a specific record. Compare the difference between to records and return changed fields Test that only changed fields are returned Advertisements

Rate this:

Read More

Apex Compare two Records and Merge updated fields

When you have two record, one being the existing queried record and the other the updated record. To merge the original with the updated field without committing the changes you can iterate the current record’s fields and check which of the fields changed. Update the changed fields to the new updated fields value. Now we […]

Rate this:

Read More

Apex One Endpoint to Rule them all

Most systems need to do CRUD on some objects and also query some information. Why not have one endpoint to do it all?I have created a endpoint that can do all that using mapping between systems field and Salesforce fields. System field does not contain any underscores or Salesforce specific syntax like (__c). With that […]

Rate this:

Read More

Apex Convert String To Camel Case

Convert string to camelCase for one underscore Convert string to camelCase for multiple underscore To Camel Case Test Class

Rate this:

Read More

Catch Apex Callout Loop not Allowed

Getting the following error: Apex Callout Loop not Allowed when you are doing a callout to the same Salesforce org and then calling out to another external service. In this case I was doing a callout to the same salesforce org and then doing a callout to the my logging service. Further you can write […]

Rate this:

Read More

Apex workaround for doing callout after DML

If you are trying to do a callout after a DML operation you would have seen this error message: You have uncommitted work pending. Please commit or rollback before calling out A way around doing callouts after a DML is to do the DML as its own internal callout. This is possible by creating a […]

Rate this:

Read More

Apex Sorting Objects with Comparable Interface

Sorting objects generic class Compare Strings Compare Dates Test Class

Rate this:

Read More

Apex Cache RecordTypes for fast retrieval

Apex class to lookup record types and cache them Test Class

Rate this:

Read More

Apex Check User Session Still Valid

Checking if a user has a valid session before making a query or call else an INVALID_SESSION error will be returned. The value of time remaining for the session can be cached and referenced so this query only runs a few times. Every time a user makes a request we can check the cache and […]

Rate this:

Read More

Apex Logging Using Static Resources

Define the Error messages detail in json format as static resource Define a ResponseCode class to parse the json into a List of ResponseCodes Define a ResponseCode Manager to translate the Codes into a map to get by id Catch exceptions and log exceptions to logging provide

Rate this:

Read More