You need to sign in to do that
Don't have an account?
Matthew Harris 40
How can you call the results of a method within another method?
I'm making a contact search page. The search criteria are Name, Phone Number and Email. I'm trying to attempt the following logic.
Here are the validation functions:
/* Name Input Validation Regex*/
public static Boolean ValidationName (String name)
{
Boolean NameIsValid = false;
String nameRegex = '/^[a-zA-Z][a-zA-Z0-9]*(_[a-zA-Z0-9]+)*(__[cC])?$/';
Pattern PatternName = Pattern.compile(nameRegex);
Matcher nameMatcher = PatternName.matcher(name);
if (!nameMatcher.matches())
NameIsValid = true;
return NameIsValid;
}
/* Phone Input Validation Regex*/
public static Boolean ValidationPhone (String phone)
{
Boolean PhoneIsValid = false;
String phoneRegex = '//^\\(?([0-9]{3})\\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$//';
Pattern PatternPhone = Pattern.compile(phoneRegex);
Matcher phoneMatcher = PatternPhone.matcher(phone);
if (!phoneMatcher.matches())
PhoneIsValid = true;
return PhoneIsValid;
}
/* Email Input Validation Regex*/
public static Boolean ValidationEmail (String email)
{
Boolean EmailIsValid = false;
String emailRegex = '/^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+ (\\.\\w{2,3})+$//';
Pattern PatternEmail = Pattern.compile(emailRegex);
Matcher emailMatcher = PatternEmail.matcher(email);
if (!emailMatcher.matches())
EmailIsValid = true;
return EmailIsValid;
}
And here is the method I want to call those results into:
public PageReference searchContacts()
{
/* Checks if input fields are empty*/
if (name == '' || phone == '' || email == '')
{
Error_FieldsEmpty = true;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'One or more of your fields are blank. Please enter your information in the remainding fields to proceed'));
}
else
{
/* Check Validations*/
}
- SearchContacts is pressed
- Checks for Blank Fields
- Validate input(Name,Phone,Email)
- Search Contacts for matches
- Generate Contact table with results
Here are the validation functions:
/* Name Input Validation Regex*/
public static Boolean ValidationName (String name)
{
Boolean NameIsValid = false;
String nameRegex = '/^[a-zA-Z][a-zA-Z0-9]*(_[a-zA-Z0-9]+)*(__[cC])?$/';
Pattern PatternName = Pattern.compile(nameRegex);
Matcher nameMatcher = PatternName.matcher(name);
if (!nameMatcher.matches())
NameIsValid = true;
return NameIsValid;
}
/* Phone Input Validation Regex*/
public static Boolean ValidationPhone (String phone)
{
Boolean PhoneIsValid = false;
String phoneRegex = '//^\\(?([0-9]{3})\\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$//';
Pattern PatternPhone = Pattern.compile(phoneRegex);
Matcher phoneMatcher = PatternPhone.matcher(phone);
if (!phoneMatcher.matches())
PhoneIsValid = true;
return PhoneIsValid;
}
/* Email Input Validation Regex*/
public static Boolean ValidationEmail (String email)
{
Boolean EmailIsValid = false;
String emailRegex = '/^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+ (\\.\\w{2,3})+$//';
Pattern PatternEmail = Pattern.compile(emailRegex);
Matcher emailMatcher = PatternEmail.matcher(email);
if (!emailMatcher.matches())
EmailIsValid = true;
return EmailIsValid;
}
And here is the method I want to call those results into:
public PageReference searchContacts()
{
/* Checks if input fields are empty*/
if (name == '' || phone == '' || email == '')
{
Error_FieldsEmpty = true;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'One or more of your fields are blank. Please enter your information in the remainding fields to proceed'));
}
else
{
/* Check Validations*/
}
public PageReference searchContacts()
{
/* Checks if input fields are empty*/
if (name == '' || phone == '' || email == '')
{
Error_FieldsEmpty = true;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'One or more of your fields are blank. Please enter your information in the remainding fields to proceed'));
return null;
}
else
{
/* Check Validations*/
Boolean isValid = true;
if (ValidationName(name))
{
isValid = false;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Name is invalid. Please put a valid name'));
}
if (ValidationPhone(Phone))
{
isValid = false;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Phone is invalid. Please put a valid phone'));
}
if (ValidationPhone(email))
{
isValid = false;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Name is email. Please put a valid email'));
}
if (!isValid)
{
return null;
}
// other processes
}
All Answers
public PageReference searchContacts()
{
/* Checks if input fields are empty*/
if (name == '' || phone == '' || email == '')
{
Error_FieldsEmpty = true;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'One or more of your fields are blank. Please enter your information in the remainding fields to proceed'));
return null;
}
else
{
/* Check Validations*/
Boolean isValid = true;
if (ValidationName(name))
{
isValid = false;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Name is invalid. Please put a valid name'));
}
if (ValidationPhone(Phone))
{
isValid = false;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Phone is invalid. Please put a valid phone'));
}
if (ValidationPhone(email))
{
isValid = false;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Name is email. Please put a valid email'));
}
if (!isValid)
{
return null;
}
// other processes
}