Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Peterson capeterson

View GitHub Profile
View Stuff.page
<apex:page controller="Thingy">
This blank canvas with our controller applied lets us invoke the remoting methods from the dev console via:
<ul>
<li><code>Thingy.regularLimits(function(response){console.log('Regular limits are:',response);});</code></li>
<li><code>Thingy.readOnlyLimits(function(response){console.log('Regular limits are:',response);});</code></li>
</ul>
</apex:page>
View map.cls
new Map<String,Object>{
'isBooleanType' => true,
'integerType' => 42,
'strings' => 'are stringy',
'this is where it gets tripy' => new Map<String,Object>{
'down the rabbit hole' => true,
'through the looking glass' => new Map<String,Object>{
'isThisEnoughToGetThePointAcross' => true
}
},
@capeterson
capeterson / gist:8326438
Created Jan 8, 2014
Apex List.addAll doesn't allow adding subclasses of the list's type properly.
View gist:8326438
List<SObject> l = new List<Sobject>();
l.addAll(new List<Contact>());
View MyControllerThing.cls
public with sharing class MyControllerThing{
@RemoteAction
public static MyWrapperThing getWrapper(){
MyWrapperThing result = new MyWrapperThing();
result.isSomething = true;
result.name = 'my wrapper obj';
result.version = 7;
return result;
}
View SublimeAstyleFormatter.sublime-settings
{
// NOTE: You should always edit options in user file, not this file.
// Auto format on file save
"autoformat_on_save": false,
// Please visit http://astyle.sourceforge.net/astyle.html for more information
"options_default": {
// Default bracket style
// Can be either "allman", "ansi", "bsd", "break", "java", "attach", "kr", "k&r",
View gist:5879152
Iterator<Schema.sObjectField> i = fields.iterator();
while(i.hasNext())
result += i.next() + i.hasNext() ? ',' :'';
View TestCumulative.cls
@isTest
private class TestCumulative{
@isTest
private static void cumulativeTest(){
List<test_obj__c> objs = [select id from test_obj__c];
for(integer i = 0; i < 99; i++){
insert new test_obj__c();
}
System.debug(LoggingLevel.Error,'Finished the loop. About to die.');
objs = [select id from test_obj__c];
@capeterson
capeterson / Invoice_PostAction.trigger
Created Aug 22, 2012
FinancialForce Posting via checkbox
View Invoice_PostAction.trigger
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 Jun 19, 2012
Dynamic SOQL + var binding
View gist:2955412
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);
View TransactionTest.cls
@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',