Skip to content

Instantly share code, notes, and snippets.

@surajp
surajp / CreateNamedCredsController.cls
Created May 28, 2021 04:26
Create Named Credentials in Salesforce via Apex
public with sharing class CreateNamedCredsController {
public static final String CLIENT_ID = '<clientid>';
public static final String CLIENT_SECRET = '<clientsecret>';
public static final String API_VERSION='v51.0';
public static final String TOKEN_ENDPOINT_URL = 'https://login.salesforce.com/services/oauth2/token';
public static final String AUTHORIZE_ENDPOINT_URL = 'https://login.salesforce.com/services/oauth2/authorize';
public static final String REDIRECT_URL = URL.getSalesforceBaseUrl().toExternalForm()+'/apex/AuthHandler';
public static final String NAMEDCRED_TOOLING_ENDPOINT_URL = URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/'+API_VERSION+'/tooling/sobjects/NamedCredential/';
public static final String AUTH_PROVIDER_NAME = 'SF_Auth';
/************************************************************
*** @author: Suraj Pillai
*** @description: A universal class for mocking in tests. Contains a method for setting the return value for any method. Another method returns the number of times a method was called
*/
@isTest
public with sharing class UniversalMocks implements System.StubProvider {
public static Map<String, Object> returnValuesMap = new Map<String, Object>();
public static Map<String, Integer> callCountsMap = new Map<String, Integer>();
@surajp
surajp / CheckFeatureController.cls
Created April 3, 2020 01:40
Check Feature in lwc
public with sharing class CheckFeatureController {
@AuraEnabled
public static boolean checkFeature(String featureName){
return FeatureManagementCheckerFactory.getFeatureManagementChecker().checkPermission(featureName);
}
}
@justin-lyon
justin-lyon / sfdc-postMessage.md
Last active March 1, 2021 19:57
Some things I learned about window.postMessage on Salesforce

Salesforce and window.postMessage

I have a visualforce page in lightning console, and I need it to send messages other components in the page. This is troublesome because Salesforce always embeds VF Pages in an iframe, even in classic.

In my research, and from folks in a few different communities I heard about window.postMessage as a possible solution.

I found that the Locker API Viewer did not block it, so I sent about figuring it out.

The following regails my misconceptions and pitfalls along the way.

@surajp
surajp / webpack.config.js
Created November 6, 2019 21:20
basic webpack config
const path = require('path');
module.exports = {
mode: "production",
entry: "./src/index",
output: {
// options related to how webpack emits results
path: path.resolve(__dirname, "dist"), // string
// the target directory for all output files
// must be an absolute path (use the Node.js path module)
@gbutt
gbutt / JsonReader.cls
Created August 15, 2019 18:39
JsonReader
public class JsonReader {
public Map<String, Object> jsonMap {get; set;}
public JsonReader(Map<String, Object> jsonMap) {
this.jsonMap = jsonMap;
}
public String getString(String path) {
return (String)getFieldAtPath(path);
}
@gdoenlen
gdoenlen / AccountSelector.cls
Last active December 12, 2024 15:51
Simple dependency injection within SFDC
/**
* Selector for the `Account` entity
*/
public class AccountSelector {
public static final AccountSelector INSTANCE = new AccountSelector();
/**
* Finds all accounts that are child accounts of
* the given opportunity's account.