Skip to content

Instantly share code, notes, and snippets.

View danielfreitasce's full-sized avatar

Daniel Freitas danielfreitasce

View GitHub Profile
@danielfreitasce
danielfreitasce / GenRandomString.cls
Last active November 20, 2022 17:30
Generate Random Strings in Apex
//Option 1
String myRandomString = EncodingUtil.convertToHex(Crypto.generateAesKey(128)).substring(0, 32)
//Option 2
Integer len = 32;
Blob blobKey = crypto.generateAesKey(192);
String key = EncodingUtil.base64encode(blobKey);
String myRandomString = key.substring(0,len);
//Option 2.1
@danielfreitasce
danielfreitasce / GetRecordTypeInfos.cls
Last active November 20, 2022 17:23
Get the RecordType infos - Apex Salesforce
//get RecordTypeId by Developer Name
Id theRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByDeveloperName().get('My_RecordType_Developer_Name').getRecordTypeId();
//get RecordTypeId by Name
Id theRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Record Type Name').getRecordTypeId();
//get RecordType Name by Id
String theRecordTypeName = Schema.SObjectType.Account.getRecordTypeInfosById().get('RecordTypeId').getname();
//where the 'RecordTypeId' is the Id
@danielfreitasce
danielfreitasce / UpdateNoOfOpenTask.cls
Last active November 20, 2022 18:44
Update the number of open tasks in a SObject | Exemple class
public class UpdateNoOfOpenTask {
public static void updateNoOfTasks(List<Task> newTasks) {
//WhoId holds the Lead or Contact Id
Set<Id> contactIds = new Set<Id>();
for(Task t : newTasks) {
if(t.WhoId != null && String.valueOf(t.WhoId).startsWith('003')) {
@danielfreitasce
danielfreitasce / validacoes.js
Last active December 15, 2022 11:35
Some validations
function isEmptyParam(param) {
if (param || param.length > 0)
return false;
else
return true;
}
function verifyMinCaracteres(min, str) {
if (str.length >= min)
return true;
@danielfreitasce
danielfreitasce / sfdx-retrieve.md
Last active January 7, 2023 17:27
sfdx main commands to retrieve Salesforce metadata