function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Synthia B.Synthia B. 

Restrict Validation Rule from firing through Controller Class

When a new task is created on the Create Task VF page, Yes and No checkboxs does not exist but should remain blank upon new task creation.
How can I stop the Yes and No validation rule from firing on the Controller Class so that it does not affect the VF page?
The Yes and No checkboxes should remain blank until the task is revisited for editing. 
With the code below No is automatically checked when the task is created which allows the user to no complete the section properly.  


User-added image
User-added image

User-added image


 
public pagereference insertSTC2(){    
        try{
            scp_Of_srvc_tsk.No__c = True;
            scp_Of_srvc_tsk.Created_from_VF_page__c = true;
            upsert scp_Of_srvc_tsk;

Thanks in advance!
Abhishek BansalAbhishek Bansal
Hi Synthia,

As i can clearly see that you are setting up a field Created_from_VF_page__c in your method and by the name of this field it will be only true when record is created from VF page.
So just edit your Validation Rule and Exclude it when Created_from_VF_page__c  equal to true.

If you are unable to edit and modify your validation rule than please paste your Validation rule logic, I will do the rest

Please let me know if you need more help on this. 

Thanks,
Abhishek
Synthia B.Synthia B.
Hi Abhishek, 

This is my VR
 
AND(
No__c = False,
Yes__c = False
)

 
Synthia B.Synthia B.
No for the created task is still checked when I use the below. 
 
AND(
No__c = False,
Yes__c = False,
Created_from_VF_page__c = False
)

 
Abhishek BansalAbhishek Bansal
Hi Synthia,

Please change your validation rule as follows :
If(Created_from_VF_page__c = true,false,If(OR(Yes__c=true,No__c=true)),true,false)

The vaidation rule will work as folows :
  1. If Created_from_VF_page__c = true than this rule will not be fired.
  2. If Created_from_VF_page__c is false and any value from Yes or No is true than it will be fired.
I think this is what you are expecting.
Please let me know if i have misunderstood your requirement.

Thanks,
Abhishek.
Synthia B.Synthia B.
Hi Abhishek, 

I am getting an errors. 

If(Created_from_VF_page__c) = true,false,If(OR(Yes__c=true,No__c=true)),true,false)
Error: Syntax error. Extra ','


 
Abhishek BansalAbhishek Bansal
There was a syntax error.
Please update as follows :

If(Created_from_VF_page__c = true, false, If(OR(Yes__c=true,No__c=true),true,false))
Synthia B.Synthia B.
Thank you Abhishek, 

The VR had no errors but still checked No when the task was created from the VF. I will look at this at a different angle. Thank you for all your help. 

Thanks, 
Synthia 
Abhishek BansalAbhishek Bansal
The validation rule looks perfectly fine.
Maybe the error is coming form some of your trigger or Apex class.
If you dont mind than can you please share the error which you are facing.
Synthia B.Synthia B.
Hi Abhishek, 

There are no errors. I will have to modify the VF page to replicate Checks and Balances in the screenshot in the first post. The VR alone will not work. 

Thanks, 
Synthia