Skip to content

Instantly share code, notes, and snippets.

View SalesforceBobLightning's full-sized avatar
💭
Easy-peasy

Salesforce Bob Lightning SalesforceBobLightning

💭
Easy-peasy
View GitHub Profile
@SalesforceBobLightning
SalesforceBobLightning / SendEmailAndPDFAction.cls
Last active July 26, 2018 22:48
Generate PDF using Email Template Developer Name and Docomotion Form Name with and send as email attachment via Salesforce Process Builder. Rather than using Email Template ID and Docomotion Form ID which change per Org
/**
* @description: Using Docomotion: create PDF and send via Email from Process Builder using Email Template Developer Name and Form Name
* @documentation: https://www.docomotion.com/support/generating-documents/silent-mode-generating-output-through-an-api/?highlight=API
**/
public class SendEmailAndPDFAction {
@InvocableMethod(
label='Send Email with PDF'
description = 'Send email with PDF attachment, which takes an Form Name, Email Template Developer Name, who Id and What Id'
)
@SalesforceBobLightning
SalesforceBobLightning / CustomExceptionWithConstructor
Created July 26, 2018 22:36
Custom Salesforce Apex Exception With Constructor
private class CustomExceptionWithConstructor extends Exception {
Private Object obj;
public CustomExceptionWithConstructor(Object obj){
this.obj = obj;
}
public override String getMessage() {
List<String> args = new String[]{obj.property1, obj.property2};
return String.format('Custom exception message with multiple arguments: {0} and {1}', args);
}
}
@SalesforceBobLightning
SalesforceBobLightning / CustomExceptionWithoutConstructor.cls
Created July 26, 2018 22:33
Custom Salesforce Apex Exception Class Without Constructor
private class CustomExceptionWithoutConstructor extends Exception {
public override String getMessage() {
List<String> args = new String[]{super.getMessage()};
return String.format('Your custom message here with one argument: {0}', args);
}
}
@SalesforceBobLightning
SalesforceBobLightning / BigClass.cls
Created July 26, 2018 09:46
Increase your Salesforce Apex code coverage by cheating
/*
* Having problems with test coverage, this will fix it
*/
public class BigClass {
public static String getValue(String input){
String output;
output = input;
@SalesforceBobLightning
SalesforceBobLightning / SimpleEmailAction.cls
Created July 26, 2018 09:25
Simple InvocableMethod for Sending Email using Email Template Developer Name via Process Builder
public class SimpleEmailAction {
@InvocableMethod(
label='Simple Email Action'
)
public static List<Result> sendEmails(List<Request> requests) {
List<Result> results = new List<Result>();
for(Request request : requests){
@SalesforceBobLightning
SalesforceBobLightning / ChangeRecordTypeAction.cls
Last active July 21, 2018 16:18
Change Object Record Type via Salesforce Process Builder using Record Type Developer Name
public class ChangeRecordTypeAction {
Private static final String RECORD_TYPE_ID = 'RecordTypeId';
@InvocableMethod(
label = 'Change Object Record Type'
description = 'Change Record Type by Developer Name'
)
public static List<Response> execute(List<Request> requests) {
@SalesforceBobLightning
SalesforceBobLightning / TestClassWithMultipleCallouts.cls
Created July 19, 2018 15:50
Using Multiple Callouts in a Single Unit Test
@isTest
public class TestClassWithMultipleCallouts {
@isTest
public static void testMethodMultipleCallouts(){
String contactResource = 'ContactsMock';
String invoiceResource = 'InvoicesMock';
StaticResourceCalloutMock contactMock = getStaticResourceCalloutMock(200, contactResource);
@SalesforceBobLightning
SalesforceBobLightning / FormattingDateAndDateTimeHelpers.cls
Created July 19, 2018 12:49
Apex Date & DateTime Formatting Helpers
// Useful Apex snippets for formatting date and datetime to String
String value = String.format('{0}T00:00:00', new List<String> {DateTime.newInstance(Date.today(), Time.newInstance(0, 0, 0, 0)).format('YYYY-MM-dd')});
System.debug(value);
// expected output:
// YYYY-MM-ddT00:00:00
@SalesforceBobLightning
SalesforceBobLightning / UpdateGrandChildRecordsAction.cls
Last active July 10, 2018 22:43
InvocableMethod for updating grand child records in Salesforce Process Builder
public class UpdateGrandChildRecordsAction {
private final static String TARGET = '{0}';
private final static String REPLACEMENT = '\'\'{0}\'\'';
private final static String FORMAT = 'SELECT Id, {0} FROM {1} WHERE Id = \'\'{2}\'\'';
@InvocableMethod(
label='Update Grand Child Records Action'
description = 'Query child and grand child records and then update grand child records'
)
@SalesforceBobLightning
SalesforceBobLightning / UpdateFieldAction.cls
Last active March 10, 2021 08:21
Generic InvocableMethod for updating a field on an object from Salesforce Process Builder
public class UpdateFieldAction {
@InvocableMethod(
label='Update Field Action'
description = 'Update a field on another object'
)
public static void updateFields(List<Request> requests) {
for(Request request : requests){
updateField(request);