Skip to content

Instantly share code, notes, and snippets.

View patmcclellan's full-sized avatar

Pat McClellan patmcclellan

View GitHub Profile
@patmcclellan
patmcclellan / gist:3a38dfe07ffab7011ab67009d8ffc5b9
Created October 27, 2022 23:22
RAD2 JSON demo (static vs. non-static methods)
//get a Contact
Contact c = [
SELECT Id, Name, AccountId, Account.Name, Email, Phone
FROM Contact
LIMIT 1
];
// METHOD SIGNATURE
// public static String serializePretty(Object objectToSerialize, Boolean suppressApexObjectNulls)
@patmcclellan
patmcclellan / gist:1f91f138fed89a70142864d84d360ff8
Last active October 28, 2022 15:37
RAD2 Demo: Datetime functions (static vs non-static)
/**
* Let's look at the method signature for newInstance()
* public static Datetime newInstance(Integer year, Integer month, Integer day, Integer hour, Integer minute, Integer second)
*
* it says right there that it's a static method, so we invoke it by using the Class name
*
*/
Datetime appointment = Datetime.newInstance(2022,10,29,11,15,0);
Datetime nextWeekAppt = appointment.addDays(7);
@patmcclellan
patmcclellan / gist:86c2cb3fcc267887eac8ad3899be12b7
Last active October 2, 2020 05:17
Lists vs. Maps example
List<Account> accountList = [SELECT Id, Name, BillingState FROM Account LIMIT 3];
System.debug('accountList: ' + accountList);
/* output from the log— just what you picture for a list of SObjects
USER_DEBUG [2]|DEBUG|accountList: (
Account:{Id=0013t00001YbRqrAAF, Name=Edge Communications-top, BillingState=TX},
Account:{Id=0013t00001YbRqsAAF, Name=Burlington Textiles Corp of America-top, BillingState=NC},
Account:{Id=0013t00001YbRqtAAF, Name=Pyramid Construction Inc.-top}
)
@patmcclellan
patmcclellan / gist:d366744ac69ac6e59a821e70a754a796
Created October 1, 2020 00:24
Example of using Maps in Apex Trigger Handler
public with sharing class AccountTriggerHandler {
public static void handleBeforeInsert(List<Account> newAccounts){
for (Account a : newAccounts) {
if (a.Est_Annual_Sales__c >= 5000000) {
a.Priority__c = 'Highest';
} else if (a.Est_Annual_Sales__c >= 3000000) {
a.Priority__c = 'High';
} else if (a.Est_Annual_Sales__c >= 1000000) {
a.Priority__c = 'Standard';