Visualforce {!$API.Session_ID} Documentation: $API Variable Methods Apex String SessId = Userinfo.getSessionID(); Salesforce Documentation: UserInfo Methods Note: The session ID generated in the Visualforce page will not be the same as Userinfo method.
Read moreCategory: Development
Sort a list of sObjects: quick and dirty -or- elegant
Quick and Dirty Here is a method that I’ve implemented to sort lists of objects by combinations of fields. I don’t claim that it is pretty, but it has worked for me. public static list SortTrf (list iMyObjList) { list SortStringList = new list(); list SortedObjList = new list(); map ObjMap = new map(); MyObj__c…
Read morePad Number with Leading Zeros
Left pad a number with leading zeroes Thanks to mauricekremer.dyndns.org for the concept and code. Below is my take on the function. public static String PadZeros(Integer Num, Integer Len) { String s = String.valueOf(Num); while (s.length() < Len) s = '0' + s; return s; }
Read moreURL Parameters within Apex and Visualforce
Get a URL parameter from a Visualforce page String MyParameter = ApexPages.currentPage().getParameters().get(‘urlparm’); Get a map of URL parameters from a Visualforce page Map UrlParameterMap = ApexPages.currentPage().getParameters(); // check for a specific parameter if (UrlParameterMap.containsKey(‘urlparm’)){ //do something with the parameter… UrlParameterMap.get(‘urlparm’) } Get URL Parameters in a Visualforce page This assumes the URL is looks like…
Read moreApex Loops, The Simple Things
For loop over a map’s keys (KeySet) map MyAwesomeMap; //… other code for (String KeyStr: MyAwesomeMap.keySet()){ system.debug(KeyStr); } For loop over a map’s values map MyAwesomeMap; //… other code for (CustomObject__c AnObject: MyAwesomeMap.values()){ system.debug(AnObject); } For loop over a list list MyAwesomeList; //… other code for (CustomObject__c AnObject: MyAwesomeList){ system.debug(AnObject); } For loop over a…
Read more