+ Start a Discussion
Suvimal KunduSuvimal Kundu 

Validation Rule : When field "X" is changed, I want "Y" field equal to "Z".

I want to create a validation rule in the account object.
I have two text data type fields. I have tried with workflow it is working fine but need a validation rule for this.

When field "Location" is changed, I want "Status" field equal to "Moved".

Please guide me on this. Thanks for help.
Best Answer chosen by Suvimal Kundu
mukesh guptamukesh gupta
Hi Sunimal,

Actually, Validation rule use to prevent the user if criteria does matched as mentioned in Validation rule and Display Error message.

So here Validation rule will not work. Please use Workflow as well.


if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 

All Answers

mukesh guptamukesh gupta
Hi Sunimal,

Actually, Validation rule use to prevent the user if criteria does matched as mentioned in Validation rule and Display Error message.

So here Validation rule will not work. Please use Workflow as well.


if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 
This was selected as the best answer
Suvimal KunduSuvimal Kundu
Is there any other solution other than workflow. 
ravi soniravi soni
hi  Suvimal,
validation rule is used for restrict user to update,delete and insert record based on criteria matches . if you don't want to use workflow then you can use formula field if status datatype is text but if status is picklist then you can use process builder or flow builder.
but I think workflow is good approach.

let me know if you are satisfie with my answer.
don't forget to mark it as best answer.

Thank you
Suvimal KunduSuvimal Kundu
Can anyone help me in writing test class for the beloe apex class. I tried but failed.




    public class printpdf {
        public List<QuoteLineItem> prd{get;set;}
        private final ApexPages.StandardController theController;
        
        public printpdf(ApexPages.StandardController controller) {
            theController = controller;
            
        prd = [Select Id , QuoteId, Product2Id, Product2.Name, Product2.Description, Product2.ProductCode, Product2.Cross_Distr_Channel_Status__c, Product2.GB_Enterprise_Prod_Hier_Level_5__c from QuoteLineItem where QuoteId=:thecontroller.getId()];
        }
    }



    @isTest
    public class printpdfTests {
        @testsetup static void data_setup(){
            QuoteLineItem prd= new QuoteLineItem();
            prd.Id = '0Q01N000001FMNfSAO';
            prd.Product2.Name = '(20-0950)CORTRAK* 2 ENTERAL ACCESS SYSTEM';
            prd.Product2.Cross_Distr_Channel_Status__c = 'S -Saleable';
        }
        @istest static void printpdf(){
            List<QuoteLineItem> prd = [Select Id , QuoteId, Product2Id, Product2.Name, Product2.Description, Product2.ProductCode, Product2.Cross_Distr_Channel_Status__c, Product2.GB_Enterprise_Prod_Hier_Level_5__c from QuoteLineItem where QuoteId= '0Q01N000001FMNfSAO'];
            printpdf.printpdf(prd);
        }
    }