function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Apex equivalent of API call describeSObject - Trying to find length of a custom Text field.

Is there an Apex equivalent of the API call describeSObject?


Since API 15.0 moving a string to the target string that is longer than the target string's length causes an error.

I'd like to discover the target string's length in advance to I can move a substring of the original string and avoid the error. i.e.


integer i = /** code here to discover length of targetString__c **/; myCustomObj__c.targetString__c = Left('Some really long string value for targetString__c', i );


Best Answer chosen by Admin (Salesforce Developers) 

Took a bit of digging but I answered my own question. Substitute your own values for CustObj__c and CustField__c.



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