Skip to content

Instantly share code, notes, and snippets.

View zachelrath's full-sized avatar

Zach McElrath zachelrath

View GitHub Profile
@zachelrath
zachelrath / gist:3976677
Created October 29, 2012 21:32
Dynamic Method invocation in Apex
public interface Executable {
void execute(String method);
}
public class DoAwesomeStuff implements Executable {
public override void execute(String method) {
if (method == 'method1') method1();
else if (method == 'method2') method2();
}
@zachelrath
zachelrath / gist:4488190
Created January 8, 2013 21:34
SOQL query for all Profiles with delete Permissions on an Sobject
SELECT Id,PermissionsDelete,Parent.Profile.Name,SobjectType
FROM ObjectPermissions
WHERE Parent.IsOwnedByProfile = TRUE
AND PermissionsDelete = TRUE
ORDER BY Parent.Profile.Name, SObjectType
@zachelrath
zachelrath / quantityRenderer
Created March 30, 2013 14:54
Inline Snippet field renderer for the Quantity field on OpportunityLineItem object. Forces a concurrent update of the UnitPrice/SalesPrice field whenever Quantity is updated.
var field = arguments[0],
value = arguments[1];
if (field.mode == 'read') {
skuid.ui.fieldRenderers.DOUBLE.read(field,value);
} else {
skuid.ui.fieldRenderers.DOUBLE.edit(field,value);
skuid.utils.delayInputCallback(
@zachelrath
zachelrath / truncateDecimalPoints
Created April 15, 2013 21:17
Inline Snippet field renderer for Skuid --- eliminates decimal places on any Double, Percent, or Currency display type fields that it is applied to
var field = arguments[0],
value = arguments[1],
metadata = field.metadata,
dt = metadata.displaytype;
// For currency, double, and percent fields,
// manually override the field's metadata
// related to how many decimal points to display
if (dt == 'CURRENCY' || dt == 'DOUBLE' || dt == 'PERCENT') {
metadata.scale = 0;
@zachelrath
zachelrath / Load Skuid using <skuid:page> component instead of page action method
Last active December 18, 2015 16:09
How to use the <skuid:page> Visualforce component to load Skuid instead of page action method
// If your Visualforce Page currently looks like this:
<apex:page action="{!redirect}&objecttype=Account&actiontype=View" standardController="Account"/>
// Change it to look like this:
<apex:page standardController="Account" readonly="true" doctype="html-5.0">
<skuid:page objectType="Account" actionType="View"/>
</apex:page>
@zachelrath
zachelrath / Multi-select Picklist renderer
Created October 1, 2013 15:40
Skuid custom field renderer to make any Field into a Multi-select Picklist
//
// SETTINGS
//
var POSSIBLE_PICKLIST_VALUES = [
'Education',
'College Counseling',
'Job Club',
'Full Medical & Dental Care',
'Mental Health',
@zachelrath
zachelrath / Sync PermissionSetAssignments with Custom Setting field
Created October 1, 2013 18:54
Skuid Snippets for adding/removing PermissionSetAssignments based on the value of a field in Custom Setting record(s)
// Row Action snippet
skuid.snippet.registerSnippet('SyncPermSets_RowAction',function(){
skuid.snippet.getSnippet('UpdatePermissionSetAssignmentsForUsers')({
rows:[arguments[0].item.row]
});
});
// Mass Action snippet
skuid.snippet.registerSnippet('SyncPermSets_MassAction',function(){
var rows = [];
<skuidpage showsidebar="false" showheader="true" tabtooverride="Contact">
<models>
<model id="Contact" limit="100" query="true" createrowifnonefound="false" sobject="Contact">
<fields>
<field id="CreatedDate"/>
<field id="AccountId"/>
<field id="Account.Name"/>
<field id="Birthdate"/>
<field id="Name"/>
</fields>
<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" showheader="true">
<models>
<model id="Input" limit="20" query="true" createrowifnonefound="true" datasource="Ui-Only" processonclient="true">
<fields>
<field id="Data" displaytype="TEXT" label="Data"/>
<field id="ImportStatus" displaytype="PICKLIST" label="Import Status" ogdisplaytype="TEXT" picklistsource="manual" returntype="TEXT" defaultvaluetype="fieldvalue" defaultValue="ready" enclosevalueinquotes="true">
<picklistentries>
<entry value="inprogress" label="In Progress"/>
<entry value="ready" label="Ready"/>
</picklistentries>
id first_name last_name email gender username birthdate
1 Freda Scotland fscotland0@purevolume.com Female fscotland0 6/20/85
2 Martainn Manners mmanners1@cpanel.net Male mmanners1 8/18/94
3 Benjy Biers bbiers2@multiply.com Male bbiers2 5/1/62
4 Jean Ickovits jickovits3@boston.com Male jickovits3 9/26/55
5 Cyrus Hamlett chamlett4@forbes.com Male chamlett4 9/7/53
6 Shayne Estabrook sestabrook5@cam.ac.uk Male sestabrook5 1/17/75
7 Nolie Szymonwicz nszymonwicz6@chicagotribune.com Female nszymonwicz6 9/4/95
8 Janette Ratchford jratchford7@deliciousdays.com Female jratchford7 2/17/93
9 Alissa Oloshkin aoloshkin8@about.com Female aoloshkin8 8/16/92