Skip to main content
For e.g.

 

I have a custom object named CustomObj__c and that has a custom field named CustomField__c which is a Long Text Area(32768)

 

The size is 32768.

 

Can I retrieve this value in Apex and store it in an Integer variable?
4 answers
Loading
  1. May 27, 2020, 11:14 AM

    Hi Hari,

    • To get the field length for Text,LongText,Picklist,TextArea and ID Data Type, we can use

    Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();

    Map <String, Schema.SObjectField> fieldMap = schemaMap.get('ObjectName').getDescribe().fields.getMap();

    for(Schema.SObjectField sfield : fieldMap.Values())

    {

    schema.describefieldresult dfield = sfield.getDescribe();

    // For Text,LongText,Picklist,TextArea and ID Data Type

    system.debug(dfield.getType()+':'+dfield.getLength());

    }

    }

    • To get the field lenght for Decimal or Currency Data Type, we can use

    Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();

    Map <String, Schema.SObjectField> fieldMap = schemaMap.get('ObjectName').getDescribe().fields.getMap();

    for(Schema.SObjectField sfield : fieldMap.Values())

    {

    schema.describefieldresult dfield = sfield.getDescribe();

    // For Decimal and Currency Data Type

    system.debug(dfield.getType()+':'+dfield.getPrecision());

    }

    }

     

     
0/9000