Skip to content

Instantly share code, notes, and snippets.

View xgeek-net's full-sized avatar

Xiaoan Lin xgeek-net

View GitHub Profile
@xgeek-net
xgeek-net / Map.java
Created March 17, 2017 07:10
KISS principle map
Map<String, String> sampleMap = new Map<String, String>{
'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'
};
@xgeek-net
xgeek-net / Map.java
Last active March 17, 2017 06:56
Initialize Map
Map<String, String> sampleMap = new Map<String, String>();
sampleMap.put('key1', 'value1');
sampleMap.put('key2', 'value2');
sampleMap.put('key3', 'value3');
@xgeek-net
xgeek-net / List.java
Last active March 17, 2017 06:53
Map keys to List
Map<Id, Account> accountMap = new Map<Id, Account>([SELECT Id, Name FROM Account LIMIT 10]);
List<Id> idList = new List<Id>(accountMap.keySet());
@xgeek-net
xgeek-net / List.java
Last active March 17, 2017 06:53
Map keys to List
Map<Id, Account> accountMap = new Map<Id, Account>([SELECT Id, Name FROM Account LIMIT 10]);
List<Id> idList = new List<Id>();
for(Account acc : accountMap.keySet()){
idList.add(acc.Id);
}
@xgeek-net
xgeek-net / Map.java
Last active March 17, 2017 07:56
sObject List to Map
Map<Id, Account> accountMap = new Map<Id, Account>([SELECT Id, Name FROM Account LIMIT 10]);
@xgeek-net
xgeek-net / Map.java
Last active March 17, 2017 07:04
sObject List to Map
List<Account> accountList = [SELECT Id, Name FROM Account LIMIT 10];
Map<Id, Account> accountMap = new Map<Id, Account>();
if(accountList != null && !accountList.isEmpty()){
for(Account acc : accountList){
accountMap.put(acc.Id, acc);
}
}
@xgeek-net
xgeek-net / System.debug.java
Created January 31, 2017 08:57
System.debug
System.debug(Logginglevel.INFO,'[INFO] Account : ' + account);
System.debug(Logginglevel.WARN,'[WARN] Account : ' + account);
System.debug(Logginglevel.ERROR,'[ERROR] Account : ' + account);
System.debug(Logginglevel.DEBUG ,'[DEBUG] Account : ' + account);
@xgeek-net
xgeek-net / debuglog.log
Last active February 10, 2017 20:21
Apex Batch debuglog
/******* 1ST TRANSACTION *********/
USER_DEBUG|[19]|DEBUG|>>> execute start at 2017/01/08 04:48:43
USER_DEBUG|[28]|DEBUG|>>> publicValue : 1
USER_DEBUG|[29]|DEBUG|>>> privateValue : 1
USER_DEBUG|[30]|DEBUG|>>> execute end at 2017/01/08 04:48:48
/******* 2ND TRANSACTION *********/
USER_DEBUG|[19]|DEBUG|>>> execute start at 2017/01/08 04:48:48
USER_DEBUG|[28]|DEBUG|>>> publicValue : 2
USER_DEBUG|[29]|DEBUG|>>> privateValue : 2
@xgeek-net
xgeek-net / SampleBatchWithState.java
Created January 8, 2017 11:16
SampleBatchWithState batch Apex
global class SampleBatchWithState implements Database.Batchable<sObject>, Database.Stateful {
public Integer publicValue;
private Integer privateValue;
global SampleBatchWithState() {
publicValue = 0;
privateValue = 0;
}
@xgeek-net
xgeek-net / SampleBatch.java
Created January 8, 2017 11:07
SampleBatch
global class SampleBatch implements Database.Batchable<sObject> {
// The batch job starts
global Database.Querylocator start(Database.BatchableContext bc){
String query = 'SELECT Id, Name FROM BatchData__c LIMIT 1000';
return Database.getQuerylocator(query);
}
// The batch job executes and operates on one batch of records
global void execute(Database.BatchableContext bc, List<sObject> scope){