APEX関連

Using Promise for Apex Server-Side request in Lightning Component

In Lightning Components, each communication with Apex Server-Side is handled as a Javascript async request, and the callback you set is called after the server-side action is completed. A server-side action can return any JSON object, such as sObject or a map of name-value pairs. The followoing sample code shows how a server-call works in […]

read more

KISS principle for apex code with List and Map in Salesforce

Here are some KISS (Keep it simple, stupid) principles for cleaning our apex code with List and Map in Salesforce, as Linus Torvalds said: “Talk is cheap. Show me the code”, let me show you as below: Initialize Map Normal KISS principle Select(SOQL) to Map Normal KISS principle Initialize List Normal KISS principle Map keys […]

read more

Batch Apex running mode (parallel and series) and how to maintain state in it

In my early post, I’d shared about how to write a Schedulable Batch Apex in Salesforce, and I’ll show you how transactions run in batch Apex and how to maintain their state across these transactions in this post. Batch Apex running mode (parallel / series) As we know, each execution of a batch Apex job […]

read more

Instantiating an Apex class based on dynamic string name with Type class

Somtimes we need to instantiate a Apex class by dynamic value in Salesforce, which can make our program more modular and more readable, such as the below case : 1. Each Contact has its socail fields : “Type__c” and “AccessToken__c” 2. Needs to request its profile via socail api in Apex First we need to […]

read more

Writing a Schedulable Batch Apex in Salesforce

To use batch Apex, you have to create an Apex class that implements interface Database.Batchable in Salesforce, like the following sample code: Execute batch Then you can use Database.executebatch method to execute it. Schedule Apex job To schedule your batch Apex to run at regular intervals, you also need an Apex class that implements interface […]

read more

Using Aggregate SOQL queries/results in Batch Apex

In previous post, we had created a schedulable batch apex that implements Database.Batchable<sObject> in Salesforce, but if you want to use SOQL having aggregate functions like SUM(), MAX(), COUNT() on results grouped by “GROUP BY” clause in start execution, changing to interface Database.Batchable<AggregateResult> isn’t a workable way, because it fails with the below compile error […]

read more

Zip attachments only with Apex in Salesforce

Before this post (about 2 years ago), I’d shared a post that is about how to zip attachments with JSZip and Apex in Salesforce, and recently I found a more simple way to do that thing, which is only using an Apex library named “Zippex” ( view on Github). Here is the outline of my […]

read more

To fix MIXED_DML_OPERATION error(setup and non-setup objects) in Salesforce

The following error will be occured if you’re trying to perform DML operation on both setup and non-setup objects in the same transation. ` MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): CustomObject__c, original object: User: [] ` Here is the sample code that […]

read more