For a string field, is there a way to get the defined length of the field? For example say I allow a maximum of 10 chars, can I get that in apex?
I am not asking how to get the length of a string (i.e.
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.Sign up to join this community
You are looking for
For string fields, returns the maximum size of the field in Unicode characters (not bytes).
Schema.DescribeFieldResult F = Account.AccountNumber.getDescribe(); Integer lengthOfField = F.getLength();
integer fieldLength = Schema.SObjectType.CustObj__c.fields.CustField__c.getLength();
for more info