Skip to content

Instantly share code, notes, and snippets.

View dancinllama's full-sized avatar

James Loghry dancinllama

View GitHub Profile
<apex:repeat var="fs" value="{!$ObjectType.Lead.FieldSets.My_Fs}">
<apex:inputField value="{!currentLead[fs]}" rendered="{!editableFields[fs.fieldPath]}" required="{!fs.required}" />
<apex:outputField value="{!currentLead[fs]}" rendered="{!NOT(editableFields[fs.fieldPath])}" />
</apex:repeat>
Map<String,String> strMap = new Map<String,String>();
strMap.put('pig','lowercasepig');
strMap.put('PIG','uppercasepig');
strMap.put('PiG','mixedCasePig');
//spits out 3
System.debug(strMap.size());
//spits out 3
System.debug(strMap.keySet().size());
for(String str : strMap.values()){
//Spits out 3 different values, 1 at a time
@dancinllama
dancinllama / gist:5404238
Created April 17, 2013 13:20
Apex code for implementing a custom clone quote button for Big Machines related work. The following takes a child opportunity and clones the Big Machines quote from the parent object onto the child opportunity
PageReferene pageRef = Page.BigMachines__QuoteEdit;
Map<String,String> parms = pageRef.getParameters();
//Get First (Primary) Big Machine Quote From current Opportunity's parent opportunity
parms.put('Id',parentOpp.BigMachines__BigMachines_Quotes__r.get(0).Id);
//Clone the parent into the the current aka child opportunity.
parms.put('oppId',opp.Id);
/**
* ManagedPackageUtils
* @description Utility class for finding info out regarding managed package
* @author James Loghry
* @date 2/12/2013
*/
public class ManagedPackageUtils{
/**
* @description determines the namespace prefix of the managed package
trigger mytrigger on object(before update){
for(Object current : Trigger.new){
Object olObject = Trigger.oldMap.get(current.Id);
if(olObject.MyField__c != current.MyField__c && otherConditionsGoHere){
//Option1
olObject.MyField__c.addError('Cannot do that, Hal..');
//Option2
current.MyField__c = olObject.MyField__c;
}
}
@dancinllama
dancinllama / gist:6581945
Last active November 25, 2019 15:54
Using Kevin 080's trigger handler setup for kicking off batch jobs based on data load
protected override void afterInsert() {
boolean isSuccessfulRun = false;
for(Integer i=0; i < Trigger.new.size() && isSuccessful == false; i++){
isSuccessfulRun |= (((DL__c)Trigger.new.get(i)).Status__c == 'Completed');
}
if(isSuccessfulRun){
//Kick off batch jobs
Database.executeBatch(new MyNotSoFirstBatchJob(),50);
}
@dancinllama
dancinllama / gist:7826948
Created December 6, 2013 15:50
Schedulable class
global class MySchedulableClass implements Schedulable{
global void execute(SchedulableContext sc){
Database.execute(new MyBatchClass());
}
}
public class OpportunityTriggerHandler extends TriggerHandler {
private Map<Id, Opportunity> newOpportunityMap = new Map<Id, Opportunity>();
private Map<Id, Opportunity> oldOpportunityMap = new Map<Id, Opportunity>();
private List<Opportunity> triggerNew = new List<Opportunity>();
private List<Opportunity> triggerOld = new List<Opportunity>();
public OpportunityTriggerHandler() {
this.triggerNew = (List<Opportunity>) Trigger.new;
this.triggerOld = (List<Opportunity>) Trigger.old;
toolingSoapSForceCom.SessionHeader_element sessionEl = new toolingSoapSForceCom.SessionHeader_element();
sessionEl.sessionId = UserInfo.getSessionId();
toolingSoapSForceCom.SforceService service = new toolingSoapSForceCom.SforceService();
service.SessionHeader = sessionEl;
//service.endpoint_x = //Adjust this to your endpoint, if needed...
toolingSoapSForceCom.ApexCodeCoverageAggregateQueryResult queryResult = service.queryApexCodeCoverageAggregate('Select NumLinesCovered From ApexCodeCoverageAggregate');
System.debug(queryResult);
{{#each this.product.prodBean.subscriptionLabels}}
{{this}}
{{/each}}
//Iterate over a seperate array, but with same length.
//returns empty string for each subscription label, when it should return some text
{{#each this.product.prodBean.subscriptionDurations}}
{{this.product.prodBean.subscriptionLabels.[{{@index}}]}}]
{{/each}}