Skip to content

Instantly share code, notes, and snippets.

View dancinllama's full-sized avatar

James Loghry dancinllama

View GitHub Profile
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;
}
}
/**
* 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
@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);
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
<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>
@dancinllama
dancinllama / gist:4772135
Created February 12, 2013 18:39
Method for retrieving managed package prefix
/**
* @description determines the namespace prefix of the managed package
*/
public static String getNamespacePrefix(DescribeFieldResult fr){
String prefix = null;
String fieldName = fr.getName();
String localname = fr.getLocalName();
Integer idx = fieldName.indexOf(localname);
@dancinllama
dancinllama / gist:4074621
Created November 14, 2012 20:37
vf page to redirect to login page
<apex:page showHeader="false" standardController="Trial__c" extensions="PAM1_ProvisioningLoginTrial">
<head>
<apex:includeScript value="{!URLFOR($Resource.jquerymin182, '/jquery-1.8.2.min.js')}" />
<script>
$j = jQuery.noConflict();
$j.post("{!url}", { username: "{!username}", password: "{!password}" },
function(data) {
if(data) {
window.href('{!url}');
}
@dancinllama
dancinllama / gist:3800800
Created September 28, 2012 16:30
partial success handling
//sobjList is my array of records inserted..
this.currentIndex = 0;
for(Database.SaveResult sr : Database.insert(objects,false)){
if(!sr.success){
exceptions.add(createException(batchId,sr.getErrors().get(0),sobjList.get(currentIndex)));
}
currentIndex++;
}
@dancinllama
dancinllama / gist:3749781
Created September 19, 2012 13:49
java connection error handling examp
for (int i=0; i< saveResults.length; i++) {
if (saveResults[i].isSuccess()) {
System.out.println(i+". Successfully deleted record - Id: " + saveResults[i].getId());
} else {
Error[] errors = saveResults[i].getErrors();
for (int j=0; j< errors.length; j++) {
System.out.println("ERROR deleting record: " + errors[j].getMessage());
}
}
//Apex Controller code
public List<SelectOption> filterCriteria{
get{
//TODO change the names to labels
List<SelectOption> options = new List<SelectOption>();
for(Account a : [Select Name,Value__c From Account Limit 10]){
options.add(new SelectOption(a.Value__c,a.Name);
}
return options;
}