Skip to content

Instantly share code, notes, and snippets.

@Mycoola
Mycoola / TaskUtility.cls
Created June 15, 2023 18:26
Created with Copy to Gist
public class TaskUtility
{
public static String getTaskPriority(String leadCountry)
{
if(String.isBlank(leadCountry)||leadCountry.length()>2)
{
return null;
}
String taskPriority;
@Mycoola
Mycoola / TaskUtilityTest.cls
Created June 15, 2023 18:25
Created with Copy to Gist
@isTest
public class TaskUtilityTest
{
@isTest static void testGetTaskPriority()
{
String priority=TaskUtility.getTaskPriority('AU');
System.assertEquals('Normal', priority);
}
@isTest static void testTaskHighPriority()
{
@Mycoola
Mycoola / TemperatureConvertorTest.cls
Last active June 15, 2023 18:19
Created with Copy to Gist
@isTest
public class TemperatureConvertorTest {
@isTest static void testWarmTemp()
{
Decimal celsius=TemperatureConvertor.FahrenheitToCelsius(70);
System.assertEquals(21.11, celsius);
}
@isTest static void testFreezingPoint()
@Mycoola
Mycoola / TemperatureConvertor.cls
Last active June 15, 2023 18:18
Created with Copy to Gist
public class TemperatureConvertor
{
public static Decimal FahrenheitToCelsius(Decimal fh)
{
Decimal cs=(fh-32)*5/9;
System.debug('temperature in Celsius='+cs.setScale(2));
return cs.setScale(2);
}
@Mycoola
Mycoola / FutureMethodExample.cls
Created May 27, 2023 17:22
FutureMethodExample
global class FutureMethodExample
{
@future(callout=true)
    public static void getStockQuotes(String acctName)
{
// Perform a callout to an external service
}
}
@Mycoola
Mycoola / FutureClass.cls
Created May 27, 2023 17:21
FutureClass
global class FutureClass
{
@future
    public static void myFutureMethod()
{
// Perform some operations
}
}
@Mycoola
Mycoola / AccountTriggerHelper.cls
Last active May 27, 2023 14:38
AccountTriggerHelper
public without sharing class AccountTriggerHelper {
    public AccountTriggerHelper() {
        System.debug('Inside AccountTriggerHelper Constructor');
    }
    public void doTask1() {
        System.debug('Inside Task 1');
    }
    public void doTask2() {
        System.debug('Inside Task 2');
    }
@Mycoola
Mycoola / AccountTriggerHandler.cls
Last active May 27, 2023 14:36
AccountTriggerHandler
public without sharing class AccountTriggerHandler implements TriggerHandler {
    private boolean triggerIsExecuting;
    private integer triggerSize;
    public AccountTriggerHelper helper;
    public AccountTriggerHandler(boolean triggerIsExecuting, integer triggerSize) {
        this.triggerIsExecuting = triggerIsExecuting;
        this.triggerSize = triggerSize;
        this.helper = new AccountTriggerHelper();
    }
    public void beforeInsert(List<Account> newAccounts) {
@Mycoola
Mycoola / TriggerHandler.cls
Last active May 27, 2023 14:35
TriggerHandler Interface
public interface TriggerHandler {
    void beforeInsert(List<SObject> newRecords);
    void beforeUpdate(List<SObject> oldRecords, List<SObject> newRecords, Map<ID, SObject> oldRecordMap, Map<ID, SObject> newRecordMap);
    void beforeDelete(List<SObject> oldRecords, Map<ID, SObject> oldRecordMap);
    void afterInsert(List<SObject> newRecords, Map<ID, SObject> newRecordMap);
    void afterUpdate(List<SObject> oldRecords, List<SObject> newRecords, Map<ID, SObject> oldRecordMap, Map<ID, SObject> newRecordMap);
    void afterDelete(List<SObject> oldRecords, Map<ID, SObject> oldRecordMap);
    void afterUndelete(List<SObject> newRecords, Map<ID, SObject> newRecordMap);
}
@Mycoola
Mycoola / AccountTrigger.cls
Last active May 27, 2023 14:34
Single trigger for the Account object
trigger AccountTrigger on Account (before insert, before update, before delete, after insert, after update, after delete, after undelete) {
    if (Org_Specific_Setting__mdt.getInstance('Run_All_Triggers')?.Value__c == true) {
        TriggerHandler handler = new AccountTriggerHandler(Trigger.isExecuting, Trigger.size);
        switch on Trigger.operationType {
            when BEFORE_INSERT {
                // handler.beforeInsert(Trigger.new);
            }
            when BEFORE_UPDATE {
                // handler.beforeUpdate(Trigger.old, Trigger.new, Trigger.oldMap, Trigger.newMap);
            }