Archives

Apex Rest API Architecture – Best Practices

What’s a Service/API A service/API is a function that is well-defined, self-contained, and does not depend on the context or state of other services. 1. Abstract vs Concrete When developing software we often use abstraction and polymorphism to get most of our applications. We want to reuse as much of the code as possible. Should […]

Rate this:

Read More

Apex Coding Interview Challenge #3

Coding question asked by Google Develop a Trigger on asset to count the amount of assets for a specific account. The value of the asset should increate on insert or undeleteand decrease on delete or reparent to a new account. Assumption: an asset cannot have a null AccountId, validation rule will fail and not save the record. […]

Rate this:

Read More

Apex SFDC99 Final Project Challenge Solution

Here is a fun Apex challenge to test your Apex skills: SFDC99 Final Project Challenge! Optimizations: 1. Add static variables to custom variables/custom metadata 2. Cache mapOfZipOwner for faster retrieval + less SOQL queries Assumption: updating an account owner can only be when: 1. Zip code was empty (null) and now has a value 2. […]

Rate this:

Read More

Apex extend standard objects to add business logic

Currently it is not possible to extend a standard or custom object in Salesforce. Why would you want to do that you may ask, think about the following, how would you check the age of a contact, if they have a mobilephone, sort list of objects, serialize, deserialize, . Define an Obj class that will […]

Rate this:

Read More

Apex Coding Interview Challenge #5

Given an encoded string, return its decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer. DecodeHelper class DecodeHelper Test

Rate this:

Read More

Apex passing parameters to Batch job during scheduling

Here it the use case: You have 1 job that you want to run weekly and monthly but the monthly job also has to generate a notification. You don’t need to create two classes but can pass a parameter to the schedule to know it is a weekly or monthly job. The batch Job class […]

Rate this:

Read More

Apex Cache Tracker to remove session cache

Here is the problem that needed to be solved: 1. Use session cache to cache some user information like their profile or user settings 2. When a external systems update the information and try to remove the session cache as it got updated it fails because it does not have access to a users session […]

Rate this:

Read More

Apex Coding Challenge Find Highest Frequency of Numbers

Problem: Find the number that has the highest frequency in a list of integers. Input: 1,6,2,1,6,1 Output: 1 //because 1 occurs 3 times in the list Option 1: Use Hashmap to iterate list Option 2: Use wrapper class with compare to sort wrapper Option 3: Using buckets to group index of frequencies together

Rate this:

Read More

Apex Clear all fields for a SObject record

The clearOutRecords would iterate all the fields passed as the currentRecord, then: 1. Exclude the fields as part of the fieldsToExcludeForClearOut Set and relationship fields 2. Check if the field is not null and updateable 3. Special logic to set fields to predefined values 4. Set all other fields to null 5. Return the SObject […]

Rate this:

Read More

Apex remove sensitive data from json

When you need to remove sensitive data from json before logging the following method will remove a predefined list of keywords removeAttributes method will iterate all the keys in the payload and remove the sensitive keys from the payload

Rate this:

Read More