Skip to content

Instantly share code, notes, and snippets.

View dancinllama's full-sized avatar

James Loghry dancinllama

View GitHub Profile
@dancinllama
dancinllama / gist:3136488
Created July 18, 2012 14:24
Creating a portal user
public static Account createPortalAccount(){
User u = [Select Id From User Where Id=:UserInfo.getUserId()];
Id roleId = [Select Id From UserRole Where PortalType='None' Limit 1].Id;
User accountOwner = null;
System.runAs(u){
Map<String,Object> acctOwnerInputParams = new Map<String,Object>();
acctOwnerInputParams = new Map<String,Object>();
acctOwnerInputParams.put('UserRoleId',roleId);
acctOwnerInputParams.put('Username','[email protected]');
@dancinllama
dancinllama / Batch processor controller
Created July 24, 2012 18:35
Batch Execution Page
/**
* P2_BatchProcessController
* @description VF controller class for a VF tab
* allowing user to select a batch / schedule apex job
* and execute it immediately
* @author dancinllama
* @date 4/17/2012
*/
public class P2_BatchProcessController {
@dancinllama
dancinllama / VF Page
Created August 2, 2012 14:44
Apex Controller Class
<apex:page controller="CustomSettingController">
<apex:pageMessages id="msgs" />
<apex:form id="theform">
<apex:inputField value="{!cs.Field1__c}" />
<apex:inputField value="{!cs.Field2__c}" />
<apex:commandButton value="{!$Label.CSTab_Save}" action="{!update}" rerender="msgs,theform" />
</apex:form>
</apex:page>
private Map<String,Set<String>> parseCsv(Integer numRecords){
//csvFile is public Blob member variable...
String csvData = csvFile.ToString();
csvData = csvData.replace('"','');
List<String> records = csvData.split('\r?\n');
Map<String,Set<String>> ans = ...
//Start at 1 to skip header row
for(Integer i=1; i < records.size() && (numRecords == null || i <= numRecords); i++){
//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;
}
@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());
}
}
@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: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: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);