Archives

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

Apex HttpCalloutMock DML workaround

When doing a callout it has to happen before the DML action. If it happens after the DML it will throw an error or will not execute. Workaround I used is to manually keep track of the mock response, and call the respond method to intercept Http.send when running a test. By checking for Test.isRunningTest() […]

Rate this:

Read More

Apex Dynamic Object Mapping for REST endpoints

Writing rest endpoints in Apex can be hard and exposing Salesforce fields to external application may not make allot of sense as custom fields end with __c and some fields are not writable or systems fields. I have worked on creating a Serializer that could serialize a Salesforce object mapping and translate that back to […]

Rate this:

Read More