Skip to content

Instantly share code, notes, and snippets.

View capeterson's full-sized avatar

Chris Peterson capeterson

View GitHub Profile
public static List<Object> getFieldValues(List<SObject> data, String fieldName){
List<Object> results = new List<Object>();
for(SObject record:data){
results.add(record.get(fieldName));
}
return results;
}
@capeterson
capeterson / Invoice_PostAction.trigger
Created August 22, 2012 02:57
FinancialForce Posting via checkbox
trigger Invoice_PostAction on c2g__codaInvoice__c (after insert, after update) {
List<c2g.CODAAPICommon.Reference> toPost = new List<c2g.CODAAPICommon.Reference>();
for(c2g__codaInvoice__c document:Trigger.new){
if( document.Action_PostDocument__c == true ){
if(document.c2g__invoiceStatus__c != 'In Progress'){
System.debug(LoggingLevel.Warn,'Cannot post invoice, invoice is '+document.c2g__invoiceStatus__c);
}else{
c2g.CODAAPICommon.Reference ref = new c2g.CODAAPICommon.Reference();
ref.id = document.id;
toPost.add(ref);
@capeterson
capeterson / gist:2955412
Created June 19, 2012 17:26
Dynamic SOQL + var binding
Set<String> names = new Set<String>{'Me','Myself','I'};
String query = 'SELECT id, name FROM User WHERE LastName IN :names';
List<sObject> objs = Database.query(query);
System.debug(objs);
@capeterson
capeterson / TransactionTest.cls
Created June 14, 2012 02:41
TransactionTest
@isTest
private class TransactionTest{
@isTest(seeAllData=true)
static void test(){
String companyName = 'Company 1';
c2g__codaCompany__c company = [SELECT id, name FROM c2g__codaCompany__c WHERE name = :companyName];
User usr = new User(alias = 'standt',
email='standarduser@testorg.com',
@capeterson
capeterson / LolEnums.cls
Created June 7, 2012 00:00
Replication of an issue with enum quality after summer12 salesforce upgrade.
global class LolEnums implements Database.batchable<sObject>, Database.Stateful{
public enum Places {FIRST, SECOND, THIRD}
public Places val;
global Database.QueryLocator start(Database.BatchableContext bc) {
val = Places.FIRST;
return Database.getQueryLocator('SELECT id FROM User');
}
global void execute(Database.BatchableContext BC, List<sObject> work){
System.assertEquals(val,Places.FIRST);
@capeterson
capeterson / Component_Query.cls
Created February 28, 2012 06:03
Visualforce Query Component. Particularly useful for visualforce email templates.
global with sharing class Component_Query {
global String queryString {get; set;}
global List<sObject> results {get{
List<sObject> result = Database.Query(queryString);
return result;
} set; }
private static testmethod void contactTest(){
Contact c = new Contact(lastName = 'apex test contact');
insert c;
@capeterson
capeterson / gist:1857114
Created February 18, 2012 03:02
PushTopic deactivate
String pushTopicId = '0IFD0000000008jOAA';
PushTopic pt = [SELECT Id FROM PushTopic WHERE Id = :pushTopicId];
pt.Id = pushTopicId;
pt.IsActive = false;
update(pt)
@capeterson
capeterson / gist:1642180
Created January 19, 2012 19:54
getObjectType
public static Schema.SObjectType getObjectType(id subject){
if(subject == null)
return null;
Schema.SObjectType result;
string target = subject;
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
string keyPrefix;
for(Schema.SObjectType describe: gd.values() ){
keyPrefix = describe.getDescribe().getKeyPrefix();
@capeterson
capeterson / gist:1630454
Created January 18, 2012 02:26
apex:repeat indexes in visualforce pages
<apex:actionFunction name="removeItem" action="{!removeItem}" rerender="theForm">
<apex:param name="rowIndex" value="" />
</apex:actionFunction>
<apex:pageBlockTable var="index" value="{!memberIndexes}">
<apex:column width="18">
<apex:image value="{!URLFOR($Resource.RemoveItem)}" title="Remove Family Member" width="16" onClick="removeItem({!index});" />
</apex:column>
<apex:repeat var="field" value="{!$ObjectType.Person__c.FieldSets.NewFamily}">
<apex:column >
<apex:facet name="header">{!field.label}</apex:facet>
/**
* Simple wrapper class to represent a record type sObject and RecordTypeInfo object all in one.
* This object needs to be used in any ui-facing record type operations going forward
* in order to support record type label overrides. See: http://www.ca-peterson.com/2011/10/tales-of-isv-supporting-override-labels.html
* @author cpeterson
**/
global with sharing class RecordTypeDescribe {
private static Map<String,Map<id,RecordTypeDescribe>> cache {
get{
if(cache == null)