Salesforce Category

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

Apex Coding Challenge for Iterating Lists

Here is the problem statement: Given an expectedSum value find the sum (n+ (n+1) = expectedValue) from a list that equals the expectedSum. I am using the following list 1,3,4,4,5,9 and looking for the sum to be 8 (3+5, 4+4) *Note the list is sorted Solution 1: The above time complexity for a nested for […]

Rate this:

Read More

Salesforce Object Level and Field Level Security Architecture

The Salesforce Security review require that both: Object Level (OLS) Field Level (FLS) Security is applied for the following areas: Query of data – Selectors Triggers – Domains DML – Unit of Work To check both (OLS) and FLS we can use fflib_SecurityUtils it has all the to methods to check if a user can access […]

Rate this:

Read More

Apex Interview Question > FizzBuzz

Consider the following problem: Write a short program that prints each number from 1 to 100 in one line For each multiple of 3, print “Fizz” instead of the number. For each multiple of 5, print “Buzz” instead of the number. For numbers which are multiples of both 3 and 5, print “FizzBuzz” instead of […]

Rate this:

Read More

Apex Test Active Case Assignment Rules Assertion Fails

If you are testing active assignment rules you need to add it as an DMLOptions during testing else your assignment rule(s) will not get called and your assertion(s) may fail. If you have one active Case Assignment Rule you can use dmlOpts.assignmentRuleHeader.useDefaultRule = true else you need to query for AssignmentRules. To query AssignmentRules you […]

Rate this:

Read More

Apex DocumentLink Trigger to Share Documents to Community Contacts

Trigger to check if the custom object has the correct file shared to community user Test class to check that sharing is done correctly

Rate this:

Read More