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;
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
add a comment |
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
add a comment |
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
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
apex required-field describefieldresult
edited Apr 27 at 14:56
gvgramazio
asked Apr 27 at 14:39
gvgramaziogvgramazio
738
738
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
First Approach -
For the field to be required it has to meet 3 conditions:
- is Creatable
- is NOT Nillable
- 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.
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
|
show 5 more comments
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
First Approach -
For the field to be required it has to meet 3 conditions:
- is Creatable
- is NOT Nillable
- 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.
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
|
show 5 more comments
First Approach -
For the field to be required it has to meet 3 conditions:
- is Creatable
- is NOT Nillable
- 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.
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
|
show 5 more comments
First Approach -
For the field to be required it has to meet 3 conditions:
- is Creatable
- is NOT Nillable
- 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.
First Approach -
For the field to be required it has to meet 3 conditions:
- is Creatable
- is NOT Nillable
- 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.
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
|
show 5 more comments
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
|
show 5 more comments
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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