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
learn_sfdclearn_sfdc 

cehckbox field mandatory when the status changes

Hello,

How to make checkbox field mandatory when ever the status changes.

i have written sample validation rule

IF(AND( 
ISPICKVAL(Status,"Open"), ISPICKVAL(PRIORVALUE(Status),"Closed"),
(Flag__c = True)))

Thanks
Best Answer chosen by learn_sfdc
Banwari kevat1Banwari kevat1
Hi sj,
  Use Error Condition Formula as following
AND (  ISCHANGED( Status),  NOT(Flag__c) )
And give a apriprote error message like 'Flag should be set before changing status'.
Let me know if any problem you are facing after that. Otherwise mark it as answer so that other will get help from this.

Thanks
Banwari

All Answers

Banwari kevat1Banwari kevat1
Hi sj,
  Use Error Condition Formula as following
AND (  ISCHANGED( Status),  NOT(Flag__c) )
And give a apriprote error message like 'Flag should be set before changing status'.
Let me know if any problem you are facing after that. Otherwise mark it as answer so that other will get help from this.

Thanks
Banwari
This was selected as the best answer
learn_sfdclearn_sfdc
Hello Banwari,

im checking status changes only from closed to open then only the flag should be checked.

How can i achieve this.

Thanks
Banwari kevat1Banwari kevat1
hello sj,
  you can achieve your requirement by following error condition:
AND ( TEXT(Status) = 'Open' , TEXT(PRIORVALUE(Status)) = 'Closed' , NOT(Flag__c) 
)

Flease check the case of Status field values. wether Open or open and Closed or closed.

Thanks
Banwari
learn_sfdclearn_sfdc
Hi Banwari,

Its working but,

Once the flag is checked and saved, immediatley this flag should get unchecked(after saving record).
How to do this?

Thanks

 
Banwari kevat1Banwari kevat1
Hello sj,
   If you want to achive this you can use following trigger and delete validation rule which is made previously.
trigger triger_name On Your_Object (before update){
    for(Your_Object  objRec : Trigger.new){
        if(objRec.Flag__c == true && objRec.Status == 'Open' && Trigger.OldMap.get(objRec.id) == 'Closed' ){
            objRec.Flag__c = false;
        }
        if(objRec.Flag__c != true && objRec.Status == 'Open' && Trigger.OldMap.get(objRec.id) == 'Closed' ){     
            objRec.addError('Give your error message');
        }
    }
}
let me know if any problem you are facving after that.

Thanks
Banwari
 
learn_sfdclearn_sfdc
Hi Banwari,

Im getting below error

Error: Compile Error: Comparison arguments must be compatible types: 

 
Banwari kevat1Banwari kevat1
Hi sj,
Try following code..
trigger triger_name On Your_Object (before update){
    for(Your_Object  objRec : Trigger.new){
        if(objRec.Flag__c == true && objRec.Status == 'Open' && Trigger.OldMap.get(objRec.id).Status  == 'Closed' ){
            objRec.Flag__c = false;
        }
        if(objRec.Flag__c != true && objRec.Status == 'Open' && Trigger.OldMap.get(objRec.id).Status == 'Closed' ){     
            objRec.addError('Give your error message');
        }
    }
}
let me know if any problem you are facing after that otherwise mark it as answer.

Thanks
Banwari
 
learn_sfdclearn_sfdc
Hello Banwari,

there should be small correction 

objRec.Flag__c = true; should be true // in the line number 4 

but the problem is once the record is saved the Flag check box should automatically uncheck but its not happening.
Banwari kevat1Banwari kevat1
Hi sj,
You would rather not modify len no 4. It must be objRec.Flag__c = false to automatically uncheck. Please revert your change at line no. 4.

Thanks 
Banwari
learn_sfdclearn_sfdc
Hello Banwari,

If i change that then it not allowing me to save the changes, it keeps on throwing an error.

Thanks
Banwari kevat1Banwari kevat1
Hi sj,
  use following code:
trigger triger_name On Your_Object (before update){
    for(Your_Object  objRec : Trigger.new){
      if(objRec.Flag__c != true && objRec.Status == 'Open' && Trigger.OldMap.get(objRec.id).Status == 'Closed' ){     
            objRec.addError('Give your error message');
        }
        if(objRec.Flag__c == true && objRec.Status == 'Open' && Trigger.OldMap.get(objRec.id).Status  == 'Closed' )    
        {
            objRec.Flag__c = false;
        }
    }
}

Now it will not through error.

Thanks
Banwari
learn_sfdclearn_sfdc
Hello Banwari,

Still no luck, even if i check the flag its not allowing me to proceed.

Thanks
Banwari kevat1Banwari kevat1
Hi sj,
Try following:
trigger triger_name On Your_Object (before update){
    for(Your_Object  objRec : Trigger.new){
      if(objRec.Status == 'Open' && Trigger.OldMap.get(objRec.id).Status == 'Closed' && objRec.Flag__c != true){     
            objRec.addError('Give your error message');
        }
        if(objRec.Status == 'Open' && Trigger.OldMap.get(objRec.id).Status  == 'Closed' && objRec.Flag__c == true )    
        {
            objRec.Flag__c = false;
        }
    }
}

It will work.

Thanks
Banwari
learn_sfdclearn_sfdc
Hi Banwari,

it seems not working,

i was thinking to use workflow 

AND(  ISPICKVAL(Case_Category__c,'Defect'),  ISPICKVAL(Case_Re_opened_By__c,'CS'),TEXT(Status) = 'New' ,TEXT(PRIORVALUE(Status)) = 'Closed', NOT(Flag__c =False))


and field update 

clear checkbox field

New Field Value = False

but the formula is throwing an error
Banwari kevat1Banwari kevat1
Hi sj,
  Why are you using workflow. please inactive it.

Thanks
Banwari