Skip to content

Instantly share code, notes, and snippets.

@TheRealBenSmith
TheRealBenSmith / Simple Lead Deduping from the Salesforce Developer Console
Created July 30, 2015 18:34
Simple Lead Deduping from the Salesforce Developer Console
//Provide the id of the default user for new leads or the default queue for new leads so we can make sure we only get rid of these leads
String ownerId = '00Go0000001iGfU';
//Start with a list of all leads with email addresses that are not converted (and in our case not currently with a status of Duplicate)
//Also pull owner ID so we can use that to determine if the leads are owned by the new lead queue (or not)
List<Lead> newleads = [select id, email, ownerid from Lead where email != null and isConverted = false and Status != 'Duplicate'];
//Create a map, indexed by email, that will store lists of leads with the same email address
Map<String, List<Lead>> leadsByEmail = new Map<String, List<Lead>>();
@TheRealBenSmith
TheRealBenSmith / CreateAccountFromContact.trigger
Created December 5, 2014 19:25
SFDC Create Account from new Contact
trigger CreateAccountFromContact on Contact (before insert) {
//Collect list of contacts being inserted without an account
List<Contact> needAccounts = new List<Contact>();
for (Contact c : trigger.new) {
if (String.isBlank(c.accountid)) {
needAccounts.add(c);
}
}
if (needAccounts.size() > 0) {
@TheRealBenSmith
TheRealBenSmith / Custom Settings Instructions
Last active August 29, 2015 14:07
Simple Apex Client for HubSpot's Create Contact API Endpoint
You'll want to create a custom setting in Salesforce to store API keys, portal IDs and product__c mappings.
The settings should be named SendToHubSpot (SendToHubSpot__c) and have the following fields:
API Key 1 (API_Key_1__c), text(50)
API Key 2 (API_Key_2__c), text(50)
Portal ID 1 (Portal_ID_1__c), text(10)
Portal ID 2 (Portal_ID_2__c), text(10)
Portal 1 Product Values (Portal_1_Product_Values__c), text(255)
Portal 2 Product Values (Portal_2_Product_Values__c), text(255)