Skip to content

Instantly share code, notes, and snippets.

View jamessimone's full-sized avatar

James Simone jamessimone

View GitHub Profile
@surajp
surajp / goauth.js
Last active December 28, 2020 21:11
Google OAuth using LWC + VF
import { LightningElement } from 'lwc';
const BASE_URL='https://accounts.google.com/o/oauth2/v2/auth';
export default class Goauth extends LightningElement {
doAuth(){
let client_id='<your client id>';
@gbutt
gbutt / DependencyResolver.cls
Created November 3, 2020 20:00
DependencyResolver.cls
public class DependencyResolver {
@TestVisible
private static Map<Type, Object> cachedDependencies {get; set;}
static {
cachedDependencies = new Map<Type, Object>();
}
// core methods abstract the core logic
public static Object getInstance(Type classType) {
@jmdohn
jmdohn / gist:ad0b466a886c7edc9210b60a9044ef3e
Created December 17, 2020 20:40
Sobject Description made easy
String obj = 'PermissionSet';
SObjectType r = ((SObject)(Type.forName('Schema.'+obj).newInstance())).getSObjectType();
Map<String,Schema.SObjectField> fields = r.getDescribe().fields.getMap();
for(String field : fields.keyset()){
Integer padding = 50 - field.length();
system.debug(fields.get(field) + '-'.repeat(padding) + fields.get(field).getDescribe().getLabel());
}
@jongpie
jongpie / convert-dlrs-rules.cls
Last active April 26, 2021 22:14
Convert DLRS rules to Rollup rules
// This script converts any DLRS rules (stored in dlrs__LookupRollupSummary2__mdt) to Rollup__mdt records and deploys them to the current org
// Use the org defaults for all converted rules
static final RollupControl__mdt ROLLUP_CONTROL = [SELECT Id, DeveloperName FROM RollupControl__mdt WHERE DeveloperName = 'Org_Defaults'];
// Prepare the converted Rollup__mdt CMDT records for deployment
Metadata.DeployContainer deployment = new Metadata.DeployContainer();
for (dlrs__LookupRollupSummary2__mdt dlrsRule : dlrs__LookupRollupSummary2__mdt.getAll().values()) {
String customMetadataTypePrefix = Schema.Rollup__mdt.SObjectType.getDescribe().getName().replace('__mdt', '');
{
// NOTE: WorkspaceAPI implementation in LWC directly. To be explored
invokeWorkspaceAPI(methodName, methodArgs) {
console.log('invokeWorkspaceAPI: ');
return new Promise((resolve, reject) => {
const apiEvent = new CustomEvent("internalapievent", {
bubbles: true,
composed: true,
cancelable: false,
@jongpie
jongpie / Example_usage.cls
Created February 16, 2022 22:55
Handle (some of) the annoyances of working with SObjects
Account acct = [SELECT Id, Name, CreatedDate FROM Account LIMIT 1];
Datetime fakeCreatedDate = System.now();
List<Contact> contacts = [SELECT Id, LastName, AccountId FROM Contact LIMIT 5];
acct = (Account) new SObjectAnnoyanceHelper(acct)
.setReadOnlyField(Schema.Account.CreatedDate, fakeCreatedDate)
.appendChildren(contacts, 'Contacts')
.getRecord();
System.debug('The updated account: ' + acct);
System.debug('The new CreatedDate: ' + acct.CreatedDate);
@gdoenlen
gdoenlen / Workflows.md
Last active July 18, 2024 12:38
Workflows, bugs, and encapsulation

Recently at work I was tasked to fix a bug that was occuring when a user would get assigned new roles. In our product we use roles to dictate what actions a user can do within the app. A user obtains a role either via an administrator assigning them a role or they can request a role and that request can later be approved by an administrator. Whenever a role gets assigned, the user's role requests for that role should also be approved. We have 2 main workflows where a user may be assigned a role:

  1. An administrator edits the user and assigns the role to a user via the user interface.
  2. An administrator can import a csv file with the user's email and their roles to be assigned.

The bug we were encountering was that in the bulk import workflow the user's requests were not getting auto approved. The product would then say the user had the role but was also requesting it. I discovered that both of the workflows were implemented individually and were both directly modifying the backing entity records. The