You need to sign in to do that
Don't have an account?
Neeraj Sharma 103
How to validate Standard Phone Field of Account Object with Apex Class with validation is Only 10Digit is input by user
Hi
I am new in Salesforce Begineer
My Question is:
How to validate Phone field of Account Object with Use of Apex Class and the validation is ONly 10 Digit is input by user no sepcial character no characters Only digits and digit will be 10
and if user input digit according the condition then the record will be save and user not input 10digit then error will be show on the Phone field "Please Provide Valid Number" on Custom Visual force Page
Please help me ASAP
Thanks
Neeraj Sharma
I am new in Salesforce Begineer
My Question is:
How to validate Phone field of Account Object with Use of Apex Class and the validation is ONly 10 Digit is input by user no sepcial character no characters Only digits and digit will be 10
and if user input digit according the condition then the record will be save and user not input 10digit then error will be show on the Phone field "Please Provide Valid Number" on Custom Visual force Page
Please help me ASAP
Thanks
Neeraj Sharma
Greetings to you!
Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Visualforce:
Controller:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
All Answers
Try this validation rule :
Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Salesforce Freelance Consultant/Developer/Administrator/Trainer
@For Salesforce Project Support: varaprasad4sfdc@gmail.com
Salesforce latest interview questions and training videos :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1
Thanks,
V Varaprasad
Email: varaprasad4sfdc@gmail.com
Greetings to you!
Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Visualforce:
Controller:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
I have made the code simple. Hope this helps.
This is your VisualForce Page
This Will be your Controller
Have A Nice Day
You can try this code
// here is your VF Page code
<apex:page controller="ValidatePhone">
<apex:form>
<apex:pageblock>
<apex:messages/>
<apex:commandButton value="validate" action="{!validate}" />
<br/><br/>
Phone No: <apex:inputText value="{!phoneno }" />
</apex:pageblock>
</apex:form>
</apex:page>
// here is your Controller
public class ValidatePhone{
public string phoneno {get;set;}
public list<Account> acc{get;set;}
public ValidatePhone()
{
acc = [select id, name,phone from Account limit 1];
}
public PageReference validate()
{
if(phoneno .length()==10){
acc[0].phone=phoneno ;
update acc[0];
} else{
ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Enter Valid Phone Number');
ApexPages.addMessage(msg);
return null;
}
return null;
}
}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha