2

This is driving me crazy!!

I have a very simple page with checkbox and textfield (start_date__c) if the checkbox is checked then the textfield is required so far so good no problem, the start_date__c is required field.

Screen shot 1 Without check:

enter image description here

Screen shot 2 Checked:

enter image description here

But when I submit the page without is Present checked then i'm getting this error:

Start Date required field is missing

I do not have validation rule that specific field but my question is why is it complaining when the required field is = false in the visualforce page

  <apex:inputField value="{!employee__c.Start_Date__c}" required="false"/>
  • Are you able to save blank value on standard layout? – Ilya Lepesh May 16 '16 at 22:39
  • Nick, it is entirely possible this field is marked as "Required" at the object level... Have you checked there? – Sebastian Kessel May 16 '16 at 22:44
  • @SebastianKessel: I did mentioned in my post but maybe not highlighted the field is "required" in the object level, so if that case then what do i need to ignore that required in visualforce page? – Nick Kahn May 16 '16 at 22:48
  • 1
    If the field is required at the object level you're out of luck. Salesforce will not let you save a record with that field blank under any circumstance. – Sebastian Kessel May 16 '16 at 22:51
  • 2
    @SebastianKessel: please post this as answer if this is the case then I really have to think my approach, I didn't know about this. – Nick Kahn May 16 '16 at 22:53
3

Nick,

The main problem (per your comments) is that the field is required at the object level. When you make a field required like that, you cannot save a blank value in there in any way (API, code, standard layout).

As Adrian mentioned, you can choose several workarounds.

1) You can make a smart Validation Rule

This will allow you to bypass the requirement in certain cases

2) You can make it required at a Page Layout level

This will let you save blank values via VF or API, but maintain the requirement of the field for people using the standard Page Layout.

3) You can write a trigger

Please don't do it, either of the two cases above should be enough in a simple case like this. :D

  • Adrian's answer will only work as I describe in #1 above. But for that you will have to remove the requirement at the object level first – Sebastian Kessel May 16 '16 at 22:57
  • Just fyi from the comments above, you can make comment text bold by wrapping it in double asterisks (e.g. **bold**). – Adrian Larson May 17 '16 at 15:27
  • In the comments, too? I did not know that. – Sebastian Kessel May 17 '16 at 15:28
4

You need to make a Validation Rule and modify the field so it is not required at the database level. It is the only way you can save a record without a value in that field, unless you want to give it a default value under those circumstances, but it does not sound like what you want. Your Validation Rule would then be simply:

AND(NOT(Is_Present__c), ISBLANK(Start_Date__c))
  • Do I have remove required requirement at the object level first in order to achieve? – Nick Kahn May 16 '16 at 22:55
  • Yes, I tried to make it clear in my first sentence. You have to remove that attribute or your only option is to fill the field in. – Adrian Larson May 16 '16 at 23:04
  • 1+Thanks Adrian I must have overlooked – Nick Kahn May 16 '16 at 23:07

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.