Archives

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

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 FeedItem Trigger Share to Community

When uploading a new FeedItem we want to share it to a specific community. First thing we need to do is share the FeedItem to a community by sharing it to the User. As the documentation states: Only feed items with a Group or User parent can set a NetworkId or a null value for […]

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 Run multiple batch jobs sequentially

We can run 3 batch jobs sequentially by incrementing the jobCounter and passing the integer (job index) into the batch scope This can be increased to any amount of batch jobs, the problem I solved was able to update the Contact and disable Users in the same code running as different batch job. As you […]

Rate this:

Read More

Apex Comparator compare multiple object fields

Sorting a list of Analysis messages first by boolean and then integer. First we will order by condition and then order. All records where condition is true is will be on top in descending order on top followed by all false condition in descending order. SummaryAnalysisMessages object to sort Compare object by condition and then […]

Rate this:

Read More

Apex save class when scheduled > ‘This schedulable class has jobs pending or in progress’

How do I develop in a class that is referenced in a scheduled job?You will see the following error when you try to save this class: This schedulable class has jobs pending or in progress There is the workaround, what I did is create a Job scheduler so basically 1 scheduled class from where I […]

Rate this:

Read More

Generating an Email-to-Case thread id using Apex

How to generate Email-to-Case thread id inside template: Generate the thread Id Send customEmail and Add ThreadId Putting it all together

Rate this:

Read More

Apex callout PATCH to Heroku Controller workaround

Setup a method to send Aync call to Heroku, add ‘?_HttpMethod=PATCH’ to the path to notify Heroku it’s a patch request Spring controller checks the RequestParam _HttpMethod to see if it’s a POST or PATCH request

Rate this:

Read More

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

Rate this:

Read More