Activity Forums Salesforce® Discussions How to know the mandatory fields in standard or custom objects?

  • Abhinav

    Member
    July 5, 2016 at 8:15 am

    Hi Mark,

    Yes there is a simple solution to use https://workbench.developerforce.com to insert a single record of the Object type in question. After the insert operation click the following screen displays the object-level required field(s) in red.

  • Ravi

    Member
    July 5, 2016 at 8:40 am

    In Apex you can check this by global describe :

    Schema.DescribeSObjectResult r = User.sObjectType.getDescribe();
    Map<String,Schema.SObjectField> M = r.fields.getMap();
    for(String fieldName : M.keySet())
    { 
     Schema.SObjectField field = M.get(fieldName);
     Schema.DescribeFieldResult F = field.getDescribe();
     //A nillable field can have empty content. A isNillable Boolean non-nillable field must have a value for the object to be //created or saved. 
     // if F.isNillable() is false then field is mandatory
     Boolean isFieldreq = F.isNillable() ;
     System.debug ('F = ' + fieldName + ' isnul= ' + isFieldreq);
    }
    • This reply was modified 7 years, 10 months ago by  Ravi.
  • Mark

    Member
    July 5, 2016 at 1:04 pm

    Thanks @ravikant and @abhinav-bhatia. It makes sense.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos