0

I look at the question here:

Is there a way to find required fields on an objects?

which offers this advice:

I think you can infer it, if a field is Createable and not Nillable and not DefaultedOnCreate.

SObjectType.Account.Fields.Name.Createable &&
!SObjectType.Account.Fields.Name.Nillable &&
!SObjectType.Account.Fields.Name.DefaultedOnCreate

Why do I need to be so indirect? Why is there no direct indication of required?

I called "describe" on an object and output like this:

  {:createable true,
   :mask nil,
   :nameField false,
   :deprecatedAndHidden false,
   :unique false,
   :dependentPicklist false,
   :soapType "xsd:double",
   :cascadeDelete false,
   :htmlFormatted false,
   :restrictedDelete false,
   :scale 0,
   :calculated false,
   :name "Probability",
   :byteLength 0,
   :highScaleNumber false,
   :precision 3,
   :filterable true,
   :digits 0,
   :type "percent",
   :custom false,
   :restrictedPicklist false,
   :idLookup false,
   :picklistValues [],
   :referenceTargetField nil,
   :defaultedOnCreate true,
   :externalId false,
   :controllerName nil,
   :inlineHelpText nil,
   :label "Probability (%)",
   :defaultValueFormula nil,
   :sortable true,
   :namePointing false,
   :updateable true,
   :length 0,
   :caseSensitive false,
   :nillable true,
   :referenceTo [],
   :displayLocationInDecimal false,
   :writeRequiresMasterRead false,
   :calculatedFormula nil,
   :defaultValue nil,
   :permissionable true,
   :extraTypeInfo nil,
   :relationshipOrder nil,
   :encrypted false,
   :filteredLookupInfo nil,
   :autoNumber false,
   :relationshipName nil,
   :queryByDistance false,
   :maskType nil,
   :groupable false}
  {:createable false,
   :mask nil,
   :nameField false,
   :deprecatedAndHidden false,
   :unique false,
   :dependentPicklist false,
   :soapType "xsd:double",
   :cascadeDelete false,
   :htmlFormatted false,
   :restrictedDelete false,
   :scale 2,
   :calculated false,
   :name "ExpectedRevenue",
   :byteLength 0,
   :highScaleNumber false,
   :precision 18,
   :filterable true,
   :digits 0,
   :type "currency",
   :custom false,
   :restrictedPicklist false,
   :idLookup false,
   :picklistValues [],
   :referenceTargetField nil,
   :defaultedOnCreate false,
   :externalId false,
   :controllerName nil,
   :inlineHelpText nil,
   :label "Expected Amount",
   :defaultValueFormula nil,
   :sortable true,
   :namePointing false,
   :updateable false,
   :length 0,
   :caseSensitive false,
   :nillable true,
   :referenceTo [],
   :displayLocationInDecimal false,
   :writeRequiresMasterRead false,
   :calculatedFormula nil,
   :defaultValue nil,
   :permissionable true,
   :extraTypeInfo nil,
   :relationshipOrder nil,
   :encrypted false,
   :filteredLookupInfo nil,
   :autoNumber false,
   :relationshipName nil,
   :queryByDistance false,
   :maskType nil,
   :groupable false}

Is this the only place I can look for information? Is there any other call I can make to the API that would tell me which fields are required?

  • May I ask in what context you are needing this information? Is it in a test context? If so, (and I sound like a broken record), this package may be what you are looking for prebuilt test factory that handles all of that for you required fields, validation rules (saved me a ton of time both in writing test methods and in deployments (no more failures due to these types of changes appexchange.salesforce.com/…: – Eric Sep 25 '15 at 7:01
  • It also provides a UI that you can connect to any org you have access to, select the object, and find out what is required by object, and layout – Eric Sep 25 '15 at 7:03
0

The above article takes into consideration the field that are required by Field Level Security.

However in large enterprise organisations, since multiple teams are working on same records, organisation's IT Team writes business rules/Validations to make fields required for certain team and non-required for certain teams.

Since validations are entirely different configuration than the field information, this information is not stored in Field Describe.

Salesforce does a server side at run-time from these validation rules. I believe it will too costly in terms of system resources to calculate/parse all Validations and mark them as required.

Also note that this has to be done on profile/user to user basis and a field describe cannot contain that much information.

About Checking different Values

These three are required because the System fields are also Not Nillable but they are not creatable as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.