In order to check if a field is required or not, is the result of isNillable method sufficient?I need a String method in a Trigger to validate if a Rich Text Area is blank“Required fields are missing” on non-null fieldLead conversion unit tests throw errors for validation rules that use custom settingsApex Describe Field pulling unavailable field for SOQLApex Class to Handle Flow/Process Errors from Validation Rules (Invocable Method/Variables)Bypass validation rule on parent object while updating parent object from Child object triggerValidation rule or lookup filter - Incoming Case (On-Demand-Email-to-Case)Set<> Check values in set for character insensativeDynamically set apex:inputField required attribute while using CSS to hide/show fieldApex Testing HttpCalloutMock failing

How long did it take Captain Marvel to travel to Earth?

Huffman Code in C++

Can I combine SELECT TOP() with the IN operator?

Efficient deletion of specific list entries

How is Pauli's exclusion principle still valid in these cases?

Guess the number game (Python)

How did the Apollo guidance computer handle parity bit errors?

Changing stroke width vertically but not horizontally in Inkscape

How can I finally understand the confusing modal verb "мочь"?

How to preserve a rare version of a book?

Picking a theme as a discovery writer

Can an earth elemental drag a tiny creature underground with Earth Glide?

What happens if I accidentally leave an app running and click "Install Now" in Software Updater?

My large rocket is still flipping over

Gerrymandering Puzzle - Rig the Election

Was there a dinosaur-counter in the original Jurassic Park movie?

How to deal with employer who keeps me at work after working hours

Is there any other simpler way to draw the following cross section?

Class Not Passing SObject By Reference

What does the copyright in a dissertation protect exactly?

Reverse ColorFunction or ColorData

Can you figure out this language?

How would you join two twin beds?

While drilling into kitchen wall, hit a wire - any advice?



In order to check if a field is required or not, is the result of isNillable method sufficient?


I need a String method in a Trigger to validate if a Rich Text Area is blank“Required fields are missing” on non-null fieldLead conversion unit tests throw errors for validation rules that use custom settingsApex Describe Field pulling unavailable field for SOQLApex Class to Handle Flow/Process Errors from Validation Rules (Invocable Method/Variables)Bypass validation rule on parent object while updating parent object from Child object triggerValidation rule or lookup filter - Incoming Case (On-Demand-Email-to-Case)Set<> Check values in set for character insensativeDynamically set apex:inputField required attribute while using CSS to hide/show fieldApex Testing HttpCalloutMock failing






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















Accordingly to the documentation of isNillable method of Schema.DescribeFieldResult class:




isNillable()



Returns true if the field is nillable, false otherwise. A
nillable field can have empty content. A non-nillable field must have
a value for the object to be created or saved.




Is it correct to state that a necessary and sufficient condition for a field to be required is that isNillable method returns false?
I'm pretty sure that it is a necessary condition but not so sure that it is also a sufficient condition if we take into account also validation rules and triggers.










share|improve this question






























    3















    Accordingly to the documentation of isNillable method of Schema.DescribeFieldResult class:




    isNillable()



    Returns true if the field is nillable, false otherwise. A
    nillable field can have empty content. A non-nillable field must have
    a value for the object to be created or saved.




    Is it correct to state that a necessary and sufficient condition for a field to be required is that isNillable method returns false?
    I'm pretty sure that it is a necessary condition but not so sure that it is also a sufficient condition if we take into account also validation rules and triggers.










    share|improve this question


























      3












      3








      3








      Accordingly to the documentation of isNillable method of Schema.DescribeFieldResult class:




      isNillable()



      Returns true if the field is nillable, false otherwise. A
      nillable field can have empty content. A non-nillable field must have
      a value for the object to be created or saved.




      Is it correct to state that a necessary and sufficient condition for a field to be required is that isNillable method returns false?
      I'm pretty sure that it is a necessary condition but not so sure that it is also a sufficient condition if we take into account also validation rules and triggers.










      share|improve this question
















      Accordingly to the documentation of isNillable method of Schema.DescribeFieldResult class:




      isNillable()



      Returns true if the field is nillable, false otherwise. A
      nillable field can have empty content. A non-nillable field must have
      a value for the object to be created or saved.




      Is it correct to state that a necessary and sufficient condition for a field to be required is that isNillable method returns false?
      I'm pretty sure that it is a necessary condition but not so sure that it is also a sufficient condition if we take into account also validation rules and triggers.







      apex required-field describefieldresult






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 27 at 14:56







      gvgramazio

















      asked Apr 27 at 14:39









      gvgramaziogvgramazio

      738




      738




















          1 Answer
          1






          active

          oldest

          votes


















          5














          First Approach -
          For the field to be required it has to meet 3 conditions:



          1. is Creatable

          2. is NOT Nillable

          3. is NOT Default on create

          So your if condition should be as following:



          if(field.isCreateable() && !field.isNillable() && !field.isDefaultedOnCreate())
          // your code



          Once ’field’ is an element while of DescribeFieldResult.



          Second Approach - to cover code in a try catch block. Into the ’try’ you can insert the Object without the field you want to check, if an exception is thrown, check which required fields are mentioned in the error message.
          In this approach, you have to delete the record once it succeeds to be inserted.






          share|improve this answer

























          • Could you please expand your answer with some explanations on why the other two conditions should be checked?

            – gvgramazio
            Apr 27 at 15:00






          • 1





            @gvgramazio About your first question. For example, CreatedDate is not a nillable field since it has value once record is created, but he is not a required field for the client. To avoid these fields, you should add the two conditions I’ve mentioned.

            – Derminal
            Apr 27 at 15:10






          • 1





            Or, instead of a try-catch, you can use allOrNone=false to make sure you get all the errors.

            – sfdcfox
            Apr 27 at 15:54






          • 1





            I wonder if this is how the FieldSetMember.getDBRequired value is calculated developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…

            – Phil W
            Apr 27 at 19:12






          • 1





            @gvgramazio sounds good..

            – Derminal
            yesterday











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "459"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f260294%2fin-order-to-check-if-a-field-is-required-or-not-is-the-result-of-isnillable-met%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          5














          First Approach -
          For the field to be required it has to meet 3 conditions:



          1. is Creatable

          2. is NOT Nillable

          3. is NOT Default on create

          So your if condition should be as following:



          if(field.isCreateable() && !field.isNillable() && !field.isDefaultedOnCreate())
          // your code



          Once ’field’ is an element while of DescribeFieldResult.



          Second Approach - to cover code in a try catch block. Into the ’try’ you can insert the Object without the field you want to check, if an exception is thrown, check which required fields are mentioned in the error message.
          In this approach, you have to delete the record once it succeeds to be inserted.






          share|improve this answer

























          • Could you please expand your answer with some explanations on why the other two conditions should be checked?

            – gvgramazio
            Apr 27 at 15:00






          • 1





            @gvgramazio About your first question. For example, CreatedDate is not a nillable field since it has value once record is created, but he is not a required field for the client. To avoid these fields, you should add the two conditions I’ve mentioned.

            – Derminal
            Apr 27 at 15:10






          • 1





            Or, instead of a try-catch, you can use allOrNone=false to make sure you get all the errors.

            – sfdcfox
            Apr 27 at 15:54






          • 1





            I wonder if this is how the FieldSetMember.getDBRequired value is calculated developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…

            – Phil W
            Apr 27 at 19:12






          • 1





            @gvgramazio sounds good..

            – Derminal
            yesterday















          5














          First Approach -
          For the field to be required it has to meet 3 conditions:



          1. is Creatable

          2. is NOT Nillable

          3. is NOT Default on create

          So your if condition should be as following:



          if(field.isCreateable() && !field.isNillable() && !field.isDefaultedOnCreate())
          // your code



          Once ’field’ is an element while of DescribeFieldResult.



          Second Approach - to cover code in a try catch block. Into the ’try’ you can insert the Object without the field you want to check, if an exception is thrown, check which required fields are mentioned in the error message.
          In this approach, you have to delete the record once it succeeds to be inserted.






          share|improve this answer

























          • Could you please expand your answer with some explanations on why the other two conditions should be checked?

            – gvgramazio
            Apr 27 at 15:00






          • 1





            @gvgramazio About your first question. For example, CreatedDate is not a nillable field since it has value once record is created, but he is not a required field for the client. To avoid these fields, you should add the two conditions I’ve mentioned.

            – Derminal
            Apr 27 at 15:10






          • 1





            Or, instead of a try-catch, you can use allOrNone=false to make sure you get all the errors.

            – sfdcfox
            Apr 27 at 15:54






          • 1





            I wonder if this is how the FieldSetMember.getDBRequired value is calculated developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…

            – Phil W
            Apr 27 at 19:12






          • 1





            @gvgramazio sounds good..

            – Derminal
            yesterday













          5












          5








          5







          First Approach -
          For the field to be required it has to meet 3 conditions:



          1. is Creatable

          2. is NOT Nillable

          3. is NOT Default on create

          So your if condition should be as following:



          if(field.isCreateable() && !field.isNillable() && !field.isDefaultedOnCreate())
          // your code



          Once ’field’ is an element while of DescribeFieldResult.



          Second Approach - to cover code in a try catch block. Into the ’try’ you can insert the Object without the field you want to check, if an exception is thrown, check which required fields are mentioned in the error message.
          In this approach, you have to delete the record once it succeeds to be inserted.






          share|improve this answer















          First Approach -
          For the field to be required it has to meet 3 conditions:



          1. is Creatable

          2. is NOT Nillable

          3. is NOT Default on create

          So your if condition should be as following:



          if(field.isCreateable() && !field.isNillable() && !field.isDefaultedOnCreate())
          // your code



          Once ’field’ is an element while of DescribeFieldResult.



          Second Approach - to cover code in a try catch block. Into the ’try’ you can insert the Object without the field you want to check, if an exception is thrown, check which required fields are mentioned in the error message.
          In this approach, you have to delete the record once it succeeds to be inserted.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 27 at 15:17

























          answered Apr 27 at 14:55









          DerminalDerminal

          1216




          1216












          • Could you please expand your answer with some explanations on why the other two conditions should be checked?

            – gvgramazio
            Apr 27 at 15:00






          • 1





            @gvgramazio About your first question. For example, CreatedDate is not a nillable field since it has value once record is created, but he is not a required field for the client. To avoid these fields, you should add the two conditions I’ve mentioned.

            – Derminal
            Apr 27 at 15:10






          • 1





            Or, instead of a try-catch, you can use allOrNone=false to make sure you get all the errors.

            – sfdcfox
            Apr 27 at 15:54






          • 1





            I wonder if this is how the FieldSetMember.getDBRequired value is calculated developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…

            – Phil W
            Apr 27 at 19:12






          • 1





            @gvgramazio sounds good..

            – Derminal
            yesterday

















          • Could you please expand your answer with some explanations on why the other two conditions should be checked?

            – gvgramazio
            Apr 27 at 15:00






          • 1





            @gvgramazio About your first question. For example, CreatedDate is not a nillable field since it has value once record is created, but he is not a required field for the client. To avoid these fields, you should add the two conditions I’ve mentioned.

            – Derminal
            Apr 27 at 15:10






          • 1





            Or, instead of a try-catch, you can use allOrNone=false to make sure you get all the errors.

            – sfdcfox
            Apr 27 at 15:54






          • 1





            I wonder if this is how the FieldSetMember.getDBRequired value is calculated developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…

            – Phil W
            Apr 27 at 19:12






          • 1





            @gvgramazio sounds good..

            – Derminal
            yesterday
















          Could you please expand your answer with some explanations on why the other two conditions should be checked?

          – gvgramazio
          Apr 27 at 15:00





          Could you please expand your answer with some explanations on why the other two conditions should be checked?

          – gvgramazio
          Apr 27 at 15:00




          1




          1





          @gvgramazio About your first question. For example, CreatedDate is not a nillable field since it has value once record is created, but he is not a required field for the client. To avoid these fields, you should add the two conditions I’ve mentioned.

          – Derminal
          Apr 27 at 15:10





          @gvgramazio About your first question. For example, CreatedDate is not a nillable field since it has value once record is created, but he is not a required field for the client. To avoid these fields, you should add the two conditions I’ve mentioned.

          – Derminal
          Apr 27 at 15:10




          1




          1





          Or, instead of a try-catch, you can use allOrNone=false to make sure you get all the errors.

          – sfdcfox
          Apr 27 at 15:54





          Or, instead of a try-catch, you can use allOrNone=false to make sure you get all the errors.

          – sfdcfox
          Apr 27 at 15:54




          1




          1





          I wonder if this is how the FieldSetMember.getDBRequired value is calculated developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…

          – Phil W
          Apr 27 at 19:12





          I wonder if this is how the FieldSetMember.getDBRequired value is calculated developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…

          – Phil W
          Apr 27 at 19:12




          1




          1





          @gvgramazio sounds good..

          – Derminal
          yesterday





          @gvgramazio sounds good..

          – Derminal
          yesterday

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Salesforce Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f260294%2fin-order-to-check-if-a-field-is-required-or-not-is-the-result-of-isnillable-met%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to write a 12-bar blues melodyI-IV-V blues progressionHow to play the bridges in a standard blues progressionHow does Gdim7 fit in C# minor?question on a certain chord progressionMusicology of Melody12 bar blues, spread rhythm: alternative to 6th chord to avoid finger stretchChord progressions/ Root key/ MelodiesHow to put chords (POP-EDM) under a given lead vocal melody (starting from a good knowledge in music theory)Are there “rules” for improvising with the minor pentatonic scale over 12-bar shuffle?Confusion about blues scale and chords

          What if the end-user didn't have the required library?What is setup.py?What is a clean, pythonic way to have multiple constructors in Python?What does Ruby have that Python doesn't, and vice versa?What is the reason for having '//' in Python?How do I create a namespace package in Python?How to package shared objects that python modules depend on?setuptools vs. distutils: why is distutils still a thing?Navigation in Windows 10 vs code not going to virtualenv library when the same library is installed at user levelPython create package for local usePackaging a project that uses multiple python versionsWhy is permission denied on pip install except for when “--user” is included at end of command?

          Esgonzo ibérico Índice Descrición Distribución Hábitat Ameazas Notas Véxase tamén "Acerca dos nomes dos anfibios e réptiles galegos""Chalcides bedriagai"Chalcides bedriagai en Carrascal, L. M. Salvador, A. (Eds). Enciclopedia virtual de los vertebrados españoles. Museo Nacional de Ciencias Naturales, Madrid. España.Fotos