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:
Super thanks!
ReplyDeleteGreat!.. thanks for sharing.
ReplyDeleteRight on. Daniel strikes again.
ReplyDeleteHow to get length of other fields like number, currency, content, url, etc?
ReplyDeleteHave a look at the DescribeFieldResult and associated methods. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_fields_describe.htm
Delete