Pages

Thursday, March 10, 2011

Find the length of a Salesforce field in Apex

Usually through the Partner API I can use describeSObject() to determine the maximum allowed length of a field.

To do this in Apex use the following - changing CustObj__c and CustField__c as required:

integer fieldLength = Schema.SObjectType.CustObj__c.fields.CustField__c.getLength();

See Also:

3 comments: