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 moreCategory: Salesforce
URL 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 moreCode Snipits for Converting Salesforce Collections
Convert a Map to a List of keys Map MyMap = new Map(); List IdList = new List(); // … logic to load map … IdList.addAll(MyMap.keySet()); Convert a Map Values to a List of values Map MyMap = new Map(); List CustomObjectList = new List(); // … logic to load map … CustomObjectList.addAll(MyMap.values()); Convert an…
Read moreReport on Field Changes in Salesforce
Tracking field history in Salesforce allows you to report on the original and new values of a field. This functionality can be very useful when determining who changed a field value and when it happened. This built-in change tracking has some limits: Only the following standard objects allow field history tracking: Accounts, Cases, Contacts, Entitlements,…
Read more