After searching i tried to rename instance variable but still getting error. Updating selmeter.name.getDescribe() to TER_Meter__c.name.getDescribe() does remove the error but that isnt helping me to get length of field of every record in list.
All i want is to get length of name field from the list of TER_Meter__c records to check if its length is less than 13. Where am i going wrong
List<TER_Meter__c> meterList = new List<TER_Meter__c>([SELECTName,Id,PAS_MSID_Effective_From__c,PAS_MSID_Effective_To__c FROM TER_Meter__c]);
for(TER_Meter__c selmeter : meterList)
{
Schema.DescribeFieldResult meterNameLength = selmeter.name.getDescribe();
if(meterNameLength.getLength()<13)
{
system.debug('looong');
}
}
Best Answer
Rather than
selemeter.name
that references the value of the field, use theSobjectField
reference:This is the way to find out general (metadata) information about the field such as its maximum length or its data type.
If you want the length of the data in that field in a record it would be:
or if the name can ever be null: