Skip to content

Instantly share code, notes, and snippets.

View richardvanhook's full-sized avatar

Richard Vanhook richardvanhook

View GitHub Profile
/*
REQUIRES https://github.com/financialforcedev/apex-mdapi
Exports all instances of field-layout items into CSV format:
Object,Field,Layout,Behavior
"account","AccountNumber","account-account %28marketing%29 layout","Edit"
"account","AccountNumber","account-account %28sales%29 layout","Edit"
......
final String PAYLOAD_ORIGINAL = 'abc<123>def';
final String PAYLOAD_ESCAPED = PAYLOAD_ORIGINAL.escapeXml();
final String XML = '<foo><bar>' + PAYLOAD_ESCAPED + '</bar></foo>';
//READER
String PAYLOAD_FROM_READER = '';
final XmlStreamReader reader = new XmlStreamReader(XML);
for(Integer i=0; i<2; i++) reader.next();
for(Integer i=0; i<5; i++){
reader.next();
@richardvanhook
richardvanhook / gist:b128e0a44a59595832e4
Created August 25, 2014 16:36
Insert new account and attachment thru salesforce.com REST API
# REPLACE THE FOLLOWING VALUES
USERNAME=XXXXXXXXXXXXXXXXX
PASSWORD=XXXXXXXXXXXXXXXXX
# LOGIN
curl https://login.salesforce.com/services/Soap/u/31.0 -H "Content-Type: text/xml; charset=UTF-8" -H "SOAPAction: login" -d "<Envelope xmlns=\""http://schemas.xmlsoap.org/soap/envelope/\""><Header/><Body><login xmlns=\""urn:partner.soap.sforce.com\""><username>$USERNAME</username><password>$PASSWORD</password></login></Body></Envelope>"
# INSPECT RESPONSE AND SET FOLLOWING VALUES
# DOMAIN SHOULD BE na1, acme.my, etc
DOMAIN=na1
@richardvanhook
richardvanhook / SetChatterGroupMemberNotificationFrequency.cls
Created March 28, 2013 13:38
Set Notification Frequency for all members of a Chatter Group
final String NEW_FREQ_FOR_ALL_GROUP_MEMBERS = 'P'; //P=>On each post, D=>Daily, W=>Weekly, N=>Never
final String GROUP_ID = 'CHANGE_ME'; //select id,name from CollaborationGroup
final List<CollaborationGroupMember> members = [
select id, NotificationFrequency
from CollaborationGroupMember
where CollaborationGroupID = :GROUP_ID
and NotificationFrequency != :NEW_FREQ_FOR_ALL_GROUP_MEMBERS
];
if(members != null && members.size() > 0){
@richardvanhook
richardvanhook / SimpleProxyClient.page
Last active July 11, 2016 01:47
Simple VF page that demonstrates how to hit REST API. NOTE: User must have access to Chatter REST API for this exact demo to work.
<apex:page docType="html-5.0" sidebar="false" showHeader="false"
standardStylesheets="false" cache="true">
<!-- TRANSFORM PARTNER URL INTO TRUE PROXY URL -->
<apex:variable var="PARTNER_URL" value="{!$Api.Partner_Server_URL_290}" />
<apex:variable var="PARTNER_URL_SPLIT" value="{!
LEFT(PARTNER_URL,FIND('.visual.force.com',PARTNER_URL)-1)
}"/>
<apex:variable var="POD" value="{!
MID(PARTNER_URL_SPLIT,FIND('.',PARTNER_URL_SPLIT)+1,LEN(PARTNER_URL_SPLIT))
@richardvanhook
richardvanhook / QuickTest.cls
Created October 6, 2011 14:02
Apex code showing unit tests both schedule and batch interfaces
global class QuickTest implements Schedulable, Database.Batchable<SObject>{
//schedule hooks
global void execute(SchedulableContext sc){ Database.executeBatch(this); }
//batch hooks
global Database.QueryLocator start(Database.BatchableContext context){
return Database.getQueryLocator([select id from account]);
}
global void execute(Database.BatchableContext context, List<SObject> records){ System.debug('ola'); }
@richardvanhook
richardvanhook / ApexOrg2Org
Created September 27, 2011 13:43
Apex code demonstrating how to log in from one salesforce org to another
/*
======================================================================
The following apex code demonstrates logging into another salesforce
org via the SOAP/XML web service api and then using session id to
query the standard REST API as well as the Chatter REST API.
To run this code, simply copy and paste into execute anonymous,
then replace the value of the first three variables accordingly.
NOTES:
(1) You'll need to create a remote site setting for both the login
@richardvanhook
richardvanhook / gist:982803
Created May 20, 2011 12:24
Normal, Simple SOQL Query
SELECT name FROM account WHERE employees < 10