Skip to content

Instantly share code, notes, and snippets.

@salesforceBen
salesforceBen / Get dynamic picklist values without using the Salesforce UI API
Last active February 2, 2020 13:27
Gist for SalesforceBen.com article about how to get dynamic picklist values without using the Salesforce UI API
// .cmp file:
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,lightning:actionOverride,force:lightningquickActionWithoutHeader">
<aura:attribute name="RecordTypeId" type="String" access="public"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<lightning:recordEditForm aura:id="recordEditForm" recordId="{!v.RecordId}" recordTypeId="{!v.RecordTypeId}" objectApiName="Account" class="slds-p-top_small">
<span class="slds-hide slds-required" aura:id="required">*</span>
<lightning:inputField aura:id="picklist" fieldName="Industry" />
<lightning:inputField fieldName="RecordId" value="{!v.RecordId}" class="slds-hide" />
<lightning:inputField fieldName="RecordTypeId" value="{!v.RecordTypeId}" class="slds-hide" />
</lightning:recordEditForm>
@salesforceBen
salesforceBen / Build a client side Data Loader app
Last active February 2, 2020 13:27
Gist for SalesforceBen.com post 'Build a client side Data Loader app'
// Create a Visualforce page:
<apex:page controller="CSVParser" docType="html-5.0" lightningStylesheets="false" showHeader="false" sidebar="false" standardStylesheets="false">
<head lang="en">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js" />
<apex:includeScript value="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.1.0/papaparse.js"/>
<!--<apex:includeScript value="{!$Resource.papaparse2}"/>-->
<link rel="stylesheet" href="https:maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
<link rel="stylesheet" href="https:maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"/>
// GitHub repo link: https://github.com/salesforceBen/governorLimitsExercise
// Exercise 1 issue:
Task taskObject;
for (Contact contactObject : [SELECT Id, AccountId, LastName FROM Contact])
{
taskObject = new Task(WhoId = contactObject.Id);
insert taskObject;
}
// SOQL in a for loop issue:
List<Account> accounts = [SELECT Id, Name FROM Account];
List<Integer> contactCount = new List<Integer>();
for (Integer i = 0; i <= accounts.size(); i++)
{
Integer count = [SELECT COUNT() FROM Contact WHERE AccountId IN : accounts ];
contactCount.add(count);
}
// SOQL in a for loop fix:
// GitHub repo link: https://github.com/salesforceBen/governorLimitsExercise
// Exercise 1 issue:
Task taskObject;
for (Contact contactObject : [SELECT Id, AccountId, LastName FROM Contact])
{
taskObject = new Task(WhoId = contactObject.Id);
insert taskObject;
}
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,lightning:actionOverride,force:lightningquickActionWithoutHeader">
<aura:attribute name="RecordTypeId" type="String" access="public"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<lightning:recordEditForm aura:id="recordEditForm" recordId="{!v.RecordId}" recordTypeId="{!v.RecordTypeId}" objectApiName="Account" class="slds-p-top_small">
<span class="slds-hide slds-required" aura:id="required">*</span>
<lightning:inputField aura:id="picklist" fieldName="Industry" />
<lightning:inputField fieldName="RecordId" value="{!v.RecordId}" class="slds-hide" />
<lightning:inputField fieldName="RecordTypeId" value="{!v.RecordTypeId}" class="slds-hide" />
</lightning:recordEditForm>
<!--<lightning:recordEditForm aura:id="recordEditForm" recordId="{!v.RecordId}" recordTypeId="{!v.RecordTypeId}" objectApiName="Account" class="slds-p-top_small">
({
doInit : function(component, event, helper) {
console.log('the doInit was called');
var fullURL = window.location.href;
var recordTypeId = fullURL.substring(fullURL.indexOf("recordTypeId") + 13,fullURL.indexOf("recordTypeId") + 31);
console.log('the recordTypeId is: ' + recordTypeId);
if (recordTypeId != null) {
function sendAccountNames(cellData) {
Visualforce.remoting.Manager.invokeAction(
CSVParser.insertAccounts(cellData,
function(result, event) {
console.log('@@@ result is: ' + result);
console.log('@@@ event is: ' + event);
}));
}
global class CSVParser
{
@RemoteAction
global static void insertAccounts(List<String> accountNames)
{
system.debug('The Account Names from the .csv are: ' + accountNames);
List<Account> accounts = new List<Account>();
Account account;
<apex:page controller="CSVParser" docType="html-5.0" lightningStylesheets="false" showHeader="false" sidebar="false" standardStylesheets="false">
<head lang="en">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js" />
<apex:includeScript value="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.1.0/papaparse.js"/>
<!--<apex:includeScript value="{!$Resource.papaparse2}"/>-->
<link rel="stylesheet" href="https:maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
<link rel="stylesheet" href="https:maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"/>
<div class="main">