Skip to content

Instantly share code, notes, and snippets.

View capeterson's full-sized avatar

Chris Peterson capeterson

View GitHub Profile
@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 / 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 / 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);
@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];
Iterator<Schema.sObjectField> i = fields.iterator();
while(i.hasNext())
result += i.next() + i.hasNext() ? ',' :'';
{
// 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",
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;
}
@capeterson
capeterson / gist:8326438
Created January 8, 2014 23:08
Apex List.addAll doesn't allow adding subclasses of the list's type properly.
List<SObject> l = new List<Sobject>();
l.addAll(new List<Contact>());
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
}
},
<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>