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
HNT_NeoHNT_Neo 

Currency and Percentage fields Validation Rule

I have 4 fields ranging in percentage and currency types (as shown below) that all will be required to contain a value prior to being saved. 

Can someone assist in creating the VR for this one? Thanks!

User-added image
Best Answer chosen by HNT_Neo
Manish BhatiManish Bhati
I have considered that you don't want any of the field to be blank.
I have just given the example below:-

IF( OR(ISBLANK( SitRate),ISBLANK(CloseRate),ISBLANK(RevenueJob),ISBLANK(GrossMargin)) , true, false)

Please just replace the field name in above VR with actual field API name from the insertfield picklist . Also give some error message like Please input the values for..... (whatever you like).
This will work.

Mark it as answer if it solves your problem.

All Answers

Manish BhatiManish Bhati
I have considered that you don't want any of the field to be blank.
I have just given the example below:-

IF( OR(ISBLANK( SitRate),ISBLANK(CloseRate),ISBLANK(RevenueJob),ISBLANK(GrossMargin)) , true, false)

Please just replace the field name in above VR with actual field API name from the insertfield picklist . Also give some error message like Please input the values for..... (whatever you like).
This will work.

Mark it as answer if it solves your problem.
This was selected as the best answer
Dinesh Suggala 8Dinesh Suggala 8
Have this validation Rule .
AND(NOT(ISBLANK(SitRate)),NOT(ISBLANK(CloseRate)),NOT(ISBLANK(RevenueJob)),NOT(ISBLANK(GrossMargin))).                                  Replace Label Names with API Names .Keep the Error message in the Top.
Hope this Could be Helpful for you.
Mark tik if is helpful.

THanks
Dinesh
YogeshMoreYogeshMore
Hello,

In the salesforceforce there is a multiple way to make required field.
You can use following any way as per your requirement.

1. At the time of field creation, you can check the check box name as “Required”. If you check this then this field will be always required while saving the record.
User-added image
 2. Second way is you can make required field on page layout level. If you did this, then this field is required for this page layout only.
User-added image
  3. Third way is you can use standard salesforce validation rule for this. That will always validate the field while saving the record.
User-added image
  4. Fourth way is you can do this by Apex trigger and that is depending on you when you want to validate means at the time of insert, update             or delete. 
Trigger yourTriggerName on ObjectAPIName (before insert , before  update) {
               
        for(ObjectAPIName obj : trigger.new){
              
                if(obj.fieldAPIName == Null){
                         obj.addError(‘Please Enter Value’);
                }
         }
}


 5. Fifth way is, if you are using Visualforce page and Apex class then it is very easy to do by apex coding. Check following example.
Public void saveAll(){
	If(obj.fielAPIName == Null){		
               ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.error,'Please Enter Value');
               apexpages.addmessage(myMsg);
     }
}

 
HNT_NeoHNT_Neo
Thank  you all for your help on this!
HNT_NeoHNT_Neo
@YogRaj, I may be using example 5 for the Apex class if I pull this out into a VF page; which may happen. I'll post a new question and notifiy you when the time comes. Thanks!
YogeshMoreYogeshMore
@ JH_Neo, Welcome.