Archives

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

Apex callout to RabbitMQ Queue

Create AMQP HTTPRequest calling POST /api/exchanges/{username}/{exchangeName}/publish Setup AMQP headers Serialize AMQP Request JSON Callout RabbitMQ

Rate this:

Read More

Apex Regex Validation Factory

Validation Factory Validation Factory Test Class

Rate this:

Read More

Apex Get Enum from String

Get Enum from String Test Class

Rate this:

Read More

Apex Advanced Selector Queries

Sub Queries Pagination with Ordering Aggregate Query

Rate this:

Read More

Implementing Mocking for Apex Tests

Trying to mock a actual database query can be hard. Using the fflib_Mocks jar you can generator Selector Mocks: More info here: https://github.com/financialforcedev/fflib-apex-mocks 1. Create interface class that extends fflib_ISObjectSelector to mock the Selector  2. Create interfacemocks.properties file in root of your project 3. Run java -jar apex-mocks-generator-4.0.0.jar “{path}/src/classes” “{path}/interfacemocks.properties” “fflib_Mocks” “{path}/src/classes” “30.0” to generate mocking […]

Rate this:

Read More

Salesforce Chatter Attaching Files to SObject

There are different ways you can use salesforce to attach a file to an SObject using Chatter. Apex Code Chatter REST Api Some limitations using this is using Blob for version.VersionData = attachment.Body; will run into Apex String length exceeds maximum: 6000000. Chatter Rest API POST https://cs43.salesforce.com/services/data/v35.0/connect/communities/0DB63000000003jGAA/chatter/feed-elements/batch HEADER Authorization         Bearer {sessionToken} Content-Type […]

Rate this:

Read More

Apex Trigger for Sales Rep Scoring

This trigger is used to track and score sales rep activities as they complete Account fields. Account Trigger Handler to Track specific field updates by sales rep and give points for based on which field was completed. Account Trigger Handler calls the SalesRepActivityScoring class to loop through all the accounts see which fields have been […]

Rate this:

Read More