This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @isTest | |
| public class TestClassWithMultipleCallouts { | |
| @isTest | |
| public static void testMethodMultipleCallouts(){ | |
| String contactResource = 'ContactsMock'; | |
| String invoiceResource = 'InvoicesMock'; | |
| StaticResourceCalloutMock contactMock = getStaticResourceCalloutMock(200, contactResource); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Having problems with test coverage, this will fix it | |
| */ | |
| public class BigClass { | |
| public static String getValue(String input){ | |
| String output; | |
| output = input; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @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' | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @description: Using Docomotion: create PDF via Process Builder using Form Name. Rather than using Form IDs which are different in each Org | |
| * @documentation: https://www.docomotion.com/support/generating-documents/silent-mode-generating-output-through-an-api/?highlight=API | |
| **/ | |
| public class GeneratePDFAction { | |
| @InvocableMethod( | |
| label='Custom Generate PDF' | |
| description = 'Generate PDF using a Form Name and What Id' | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static HttpResponse makeHttpCallout(String url, String method, String body, Map<String,String> headers){ | |
| HttpRequest request = new HttpRequest(); | |
| Http http = new Http(); | |
| if(method == 'PATCH'){ | |
| request.setMethod('POST'); | |
| url += '?_HttpMethod=PATCH'; | |
| } else { | |
| request.setMethod(method); |