Skip to content

Instantly share code, notes, and snippets.

@zanstaszek9
zanstaszek9 / ParentWithNestedChildrenUtility.cls
Last active December 23, 2025 14:25
Apex ParentWithNestedChildrenUtility test class. Creates an in-memory SObject with nested related (child) records using JSON serialization and deserialization, without DMLs.
@IsTest
public class ParentWithNestedChildrenUtility {
/**
* @description Creates an in-memory SObject with nested related (child) records using JSON serialization and deserialization, without DMLs.
* @param parentRecord The parent SObject record to receive children.
* @param childrenRecords SObject records to be nested under the parent.
* @param relationshipFieldName The relationship field name on Parent ('Contacts', 'Opportunities', 'Equipment_Maintenance_Items__r'). Using String, as "SObjectField" type cannot be used due to relationship fields on parent-side are not available that way.
* @param populateFakeIds If true, fake Ids will be generated and assigned to parent and child records when their Ids are null.
* @return The deserialized parent SObject with nested children records.
@zanstaszek9
zanstaszek9 / FormSubmitToSalesforceWebToLead.gs
Created July 24, 2025 20:06
Goole App Script code that can be put into the Google Forms trigger to send data to Salesforce using Web-To-Lead
const SALESFORCE_ORG_ID = '00DQy00000TqD0T'; // Salesforce Instance Org Id, can be taken from generated Web-To-Lead link.
function onFormSubmit(e) {
const reponseFields = e.response.getItemResponses();
const payload = {
'oid': SALESFORCE_ORG_ID,
'first_name': reponseFields[0].getResponse(),
'last_name': reponseFields[1].getResponse(),
@zanstaszek9
zanstaszek9 / AvailableTimeSlotsService.cls
Created May 27, 2025 11:10
Apex code with invocable action for finding available Time Slots to book in Salesforce Scheduler
@IsTest
public inherited sharing class AvailableTimeSlotsService {
private final static String USED_API_VERSION { get { return '60.0';}}
private final static Integer MAXIMUM_DAYS_TO_SEARCH { get { return 180;}}
@InvocableMethod(Label = 'Find first free Time Slot for Scheduler' IconName='slds:standard:time_period' Description = 'Returns first found unoccupied Time Slot for given Service Territory and Work Type Group.' Category = 'Appointments')
public static List<String> getTimeSlot(final List<SchedulerSearchParams> schedulerSearchParamsList) {
final List<String> freeTimeSlots = new List<String>();