In order to check if a field is required or not, is the result of isNillable method sufficient?I need a...
How can Republicans who favour free markets, consistently express anger when they don't like the outcome of that choice?
TIKZ - changing one block into parallel multiple blocks
How to pronounce 'C++' in Spanish
Map of water taps to fill bottles
What was the first Intel x86 processor with "Base + Index * Scale + Displacement" addressing mode?
what is the sudo password for a --disabled-password user
Could moose/elk survive in the Amazon forest?
Symbolic Multivariate Distribution
As an international instructor, should I openly talk about my accent?
Refer to page numbers where table is referenced
How come there are so many candidates for the 2020 Democratic party presidential nomination?
Is the claim "Employers won't employ people with no 'social media presence'" realistic?
In order to check if a field is required or not, is the result of isNillable method sufficient?
How do I deal with a coworker that keeps asking to make small superficial changes to a report, and it is seriously triggering my anxiety?
Why does processed meat contain preservatives, while canned fish needs not?
What does a straight horizontal line above a few notes, after a changed tempo mean?
Pulling the rope with one hand is as heavy as with two hands?
Rivers without rain
Can SQL Server create collisions in system generated constraint names?
Apply MapThread to all but one variable
Copy a file to remote server using SSH
How did Captain America manage to do this?
How exactly does Hawking radiation decrease the mass of black holes?
Why was the Spitfire's elliptical wing almost uncopied by other aircraft of World War 2?
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 1 hour ago
gvgramazio
asked 1 hour ago
gvgramaziogvgramazio
638
638
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
1 hour ago
Also, could you please spend a word about validation rules? I think that it's not possible to check them from apex but I'm not sure.
– gvgramazio
1 hour ago
@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
1 hour ago
@gvgramazio About your second question. Validation rule is a problematic issue. Your valudation rule includes formula which avoids saving or creating a record once it meets the conditions. You can retrieve the formula using apex, but you can't really know what the formula means in run time. For covering this scenario, the workaround I suggest is the second approach I've mentioned in my answer.
– Derminal
1 hour ago
Or, instead of a try-catch, you can use allOrNone=false to make sure you get all the errors.
– sfdcfox
24 mins ago
add a comment |
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
1 hour ago
Also, could you please spend a word about validation rules? I think that it's not possible to check them from apex but I'm not sure.
– gvgramazio
1 hour ago
@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
1 hour ago
@gvgramazio About your second question. Validation rule is a problematic issue. Your valudation rule includes formula which avoids saving or creating a record once it meets the conditions. You can retrieve the formula using apex, but you can't really know what the formula means in run time. For covering this scenario, the workaround I suggest is the second approach I've mentioned in my answer.
– Derminal
1 hour ago
Or, instead of a try-catch, you can use allOrNone=false to make sure you get all the errors.
– sfdcfox
24 mins ago
add a comment |
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
1 hour ago
Also, could you please spend a word about validation rules? I think that it's not possible to check them from apex but I'm not sure.
– gvgramazio
1 hour ago
@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
1 hour ago
@gvgramazio About your second question. Validation rule is a problematic issue. Your valudation rule includes formula which avoids saving or creating a record once it meets the conditions. You can retrieve the formula using apex, but you can't really know what the formula means in run time. For covering this scenario, the workaround I suggest is the second approach I've mentioned in my answer.
– Derminal
1 hour ago
Or, instead of a try-catch, you can use allOrNone=false to make sure you get all the errors.
– sfdcfox
24 mins ago
add a comment |
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 1 hour ago
answered 1 hour ago
DerminalDerminal
1035
1035
Could you please expand your answer with some explanations on why the other two conditions should be checked?
– gvgramazio
1 hour ago
Also, could you please spend a word about validation rules? I think that it's not possible to check them from apex but I'm not sure.
– gvgramazio
1 hour ago
@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
1 hour ago
@gvgramazio About your second question. Validation rule is a problematic issue. Your valudation rule includes formula which avoids saving or creating a record once it meets the conditions. You can retrieve the formula using apex, but you can't really know what the formula means in run time. For covering this scenario, the workaround I suggest is the second approach I've mentioned in my answer.
– Derminal
1 hour ago
Or, instead of a try-catch, you can use allOrNone=false to make sure you get all the errors.
– sfdcfox
24 mins ago
add a comment |
Could you please expand your answer with some explanations on why the other two conditions should be checked?
– gvgramazio
1 hour ago
Also, could you please spend a word about validation rules? I think that it's not possible to check them from apex but I'm not sure.
– gvgramazio
1 hour ago
@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
1 hour ago
@gvgramazio About your second question. Validation rule is a problematic issue. Your valudation rule includes formula which avoids saving or creating a record once it meets the conditions. You can retrieve the formula using apex, but you can't really know what the formula means in run time. For covering this scenario, the workaround I suggest is the second approach I've mentioned in my answer.
– Derminal
1 hour ago
Or, instead of a try-catch, you can use allOrNone=false to make sure you get all the errors.
– sfdcfox
24 mins ago
Could you please expand your answer with some explanations on why the other two conditions should be checked?
– gvgramazio
1 hour ago
Could you please expand your answer with some explanations on why the other two conditions should be checked?
– gvgramazio
1 hour ago
Also, could you please spend a word about validation rules? I think that it's not possible to check them from apex but I'm not sure.
– gvgramazio
1 hour ago
Also, could you please spend a word about validation rules? I think that it's not possible to check them from apex but I'm not sure.
– gvgramazio
1 hour ago
@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
1 hour ago
@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
1 hour ago
@gvgramazio About your second question. Validation rule is a problematic issue. Your valudation rule includes formula which avoids saving or creating a record once it meets the conditions. You can retrieve the formula using apex, but you can't really know what the formula means in run time. For covering this scenario, the workaround I suggest is the second approach I've mentioned in my answer.
– Derminal
1 hour ago
@gvgramazio About your second question. Validation rule is a problematic issue. Your valudation rule includes formula which avoids saving or creating a record once it meets the conditions. You can retrieve the formula using apex, but you can't really know what the formula means in run time. For covering this scenario, the workaround I suggest is the second approach I've mentioned in my answer.
– Derminal
1 hour ago
Or, instead of a try-catch, you can use allOrNone=false to make sure you get all the errors.
– sfdcfox
24 mins ago
Or, instead of a try-catch, you can use allOrNone=false to make sure you get all the errors.
– sfdcfox
24 mins ago
add a comment |
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