Skip to content

Instantly share code, notes, and snippets.

View mhamzas's full-sized avatar

Hamza Siddiqui mhamzas

View GitHub Profile
@mhamzas
mhamzas / find_values.js
Created November 20, 2020 06:14 — forked from shakhal/find_values.js
Find values in JSON by key, recursively
function findValues(obj, key){
return findValuesHelper(obj, key, []);
}
function findValuesHelper(obj, key, list) {
if (!obj) return list;
if (obj instanceof Array) {
for (var i in obj) {
list = list.concat(findValuesHelper(obj[i], key, []));
}
@mhamzas
mhamzas / UpdateFieldAction.cls
Created March 10, 2021 08:21 — forked from SalesforceBobLightning/UpdateFieldAction.cls
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);
@mhamzas
mhamzas / AccountPage.vfp
Created March 11, 2021 06:55 — forked from douglascayers/AccountPage.vfp
Example Visualforce page that displays the Classic Attachments and Salesforce Files related lists.
<apex:page standardController="Account">
<!-- classic attachments related list -->
<apex:relatedList subject="{!account.id}" list="CombinedAttachments" />
<!-- new salesforce files related list -->
<apex:relatedList subject="{!account.id}" list="AttachedContentDocuments" />
</apex:page>
@mhamzas
mhamzas / dataload.bat
Last active June 1, 2023 12:28
Setup FSC Scratch ORG - BATCH file (Windows)
@echo off
TITLE Data Migrate for FSC
ECHO this batch file will Migrate the data from 1 org to another (FSC). Press any key to continue
PAUSE
set /p sourceOrgAlias="Enter Source Org Alias (Example: ABCScratch): "
set /p targetOrgAlias="Enter Target Org Alias (Example: XYZScratch): "
set /p jsonpath="Enter export.json Path (Example: C:\Users\USER\Documents\SFDMU_APP\data\Default): "
sfdx sfdmu:run --sourceusername %sourceOrgAlias% --targetusername %targetOrgAlias% -p %jsonpath%
@mhamzas
mhamzas / InvocableApexTemplate.cls
Created March 25, 2021 15:22 — forked from douglascayers/InvocableApexTemplate.cls
Example structure of an invocable apex class
public with sharing class InvocableApexTemplate {
@InvocableMethod(
label = 'Name as displayed in Process Builder'
description = 'Tooltip as displayed in Process Builder'
)
public static List<Response> execute( List<Request> requests ) {
List<Response> responses = new List<Response>();
@mhamzas
mhamzas / method.cls
Created April 16, 2021 08:20
Get Object and Field Label value using API Names
public static void getLabelsfromAPINames(String ObjectApi, String FieldApi){
if(!String.IsBlank(ObjectApi) && !String.IsBlank(FieldApi)){
system.debug('Object : '+(String)Schema.getGlobalDescribe().get(ObjectApi).getDescribe().getLabel()+', Field : '+ (String)Schema.getGlobalDescribe().get(ObjectApi).getDescribe().fields.getMap().get(FieldApi).getDescribe().getLabel()+' \n';
}
}
// Usage
getLabelsfromAPINames('Account', 'Name');
@mhamzas
mhamzas / dynamicInsert.cls
Created April 26, 2021 10:32
Inserting sObject Record Dynamically in Salesforce
String objName = 'Account';
String recordName = 'Salesforce';
sObject sObj = Schema.getGlobalDescribe().get(objName).newSObject();
sObj.put('Name', recordName) ;
Insert sObj ;
@mhamzas
mhamzas / dynamicsoql.cls
Created April 30, 2021 09:50
Accessing Parent Field Values from sObjects in Dynamic Queries Using Dynamic Apex
/*------------Accessing parent field values in child to parent dynamic query----//
//Below is static method which can be used to fetch field values.//
//You need to pass sObject and fieldAPIName to get field value---*/
// CREDITS: https://www.sfdcstuff.com/2019/06/accessing-parent-field-values-from.html
public static string ExtractFieldValues(sObject sb, string fieldAPIName) {
string fvalue = '';
if (fieldAPIName.contains('.')) {
List < string > splitedFields = fieldAPIName.split('\\.');
try {
@mhamzas
mhamzas / gist:039f865e242e7f20b1947e88a32fe7be
Created May 28, 2021 12:09 — forked from f1code/gist:858086
SalesForce Apex CSV Parser
/**
* Used to read a delimited file.
*/
public class SSSCsvReader {
private String delim = ',';
// the input data
private String[] buffer;
public SSSCsvReader(String data){
this.buffer = data.split('\n');
@mhamzas
mhamzas / package.xml
Created July 1, 2021 08:12 — forked from shanerk/package.xml
Salesforce package.xml file to get all metadata from your org. Works great with vscode and cli.
<?xml version="1.0" encoding="UTF-8" ?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>*</members>
<name>ApexClass</name>
</types>
<types>
<members>*</members>
<name>ApexComponent</name>
</types>