Salesforce provides an Apex method for retrieving an object’s record type record id. The method accepts the record type label instead of the developer/api name, and this makes the Apex method sensitive record type label changes. Here is a typical example of the method in use. It strings together methods for the object’s schema, record…
Read moreCategory: Apex
Salesforce Apex programming language
Convert a number to a string left padded with 0s in Apex
Integer MyInt = 54; String MyString = String.valueOf(MyInt).leftPad(5, ‘0’); system.assertEquals(‘00054’, MyString);
Read moreApex File Naming Standards
Consistent file naming helps keep Visualforce and Apex classes easy to recognize and find. I’ve seen many orgs with both the good and the bad. Below is a table with naming suggestions. Some of them are mine, but most came from a presentation that I found referenced in a Trailhead module. The presentation is by…
Read moreRemove Last Comma or Other Characters from the End of a String
Apex Removing the last comma is often needed when dynamically building a SOQL Select string. Salesforce quietly released a bunch of new string methods in Winter ’13 that I have started to really appreciate. One of the new methods is removeEnd() and removeEndIngoreCase(). These are great for removing that last comma. String soql = ‘Select…
Read moreSalesforce Describe Methods – Record Types, Fields, and Global Describe
Record Type Describe Getting an object’s record type Id is simple with the statement below, and it avoids using a SOQL statment on the RecordType object. However, the method name is misleading because getRecordTypeInfosByName actually retrieves the record type with the Label and not the Name. Also, be careful because the name is case sensitive….
Read more