Skip to content

Instantly share code, notes, and snippets.

@farikh
farikh / new_gist_file_0
Created September 29, 2015 17:25
Dynamically create sObject from type.
Type t = Type.forName('Account' );
sObject o = (sObject)t.newInstance();
@farikh
farikh / cloneObjHierarchy
Last active August 29, 2015 14:26
Apex algorithm to clone an object hierarchy starting with a bottom-level descendant. Useful for generating test objects from an existing org. Anticipate later attachment to code for creating static resources.
Id objId = 'a4XS0000000DNjWMAW';
// Variables for Managing Iteration
List<Id> objsToProcessLst = new List<Id>();
Set<Id> objsToProcess = new Set<Id>(); // Set Ids of objsToProcess to process to prevent double-processing from a second reference
Set<Id> objsProcessed = new Set<Id>(); // Set Ids transferred from objsToProcess to Processed objs to prevent re-processing from a second reference
Map<Id, Id> oldIdtoNewId = new Map<Id, Id>();
Map<Id, Id> newIdtoOldId = new Map<Id, Id>();
Map<Id, Integer> origIdtoLevel = new Map<Id, Integer>();
Map<Integer, Map<Id, sObject>> levelMaptoOldIdtosObject = new Map<Integer, Map<Id, sObject>>();
@farikh
farikh / field_set_with_conditional_link
Last active August 29, 2015 14:17
Visualforce field set with conditional reference link
@farikh
farikh / standardsetcontroller.cls
Last active August 29, 2015 14:17
StandardSet Controller
public class listView {
ApexPages.StandardSetController controller;
public listView(ApexPages.StandardSetController controller) {
this.controller = controller;
controller.setPageSize(5);
}
public pageReference ShowAll() {
controller.setPageSize(controller.getResultSize());
return null;
@farikh
farikh / dynamic_vf_resize.page
Created March 13, 2015 13:28
Dynamically resize visualforce includes on standard page layout. Must replace standard page with the following code.
<apex:page standardController="Custom_Object__c">
<apex:detail subject="{!Custom_Object__c.Id}" relatedList="true"/>
<apex:includeScript value="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"/>
<script>
var j$ = jQuery.noConflict();
j$("iframe").each(function(){
j$(this).load(function() {
j$(this).height( j$(this).contents().find("body").height() );
});
});
@farikh
farikh / 0_reuse_code.js
Created July 18, 2014 10:37
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console