-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
5Questions
-
11Replies
How do I add fieldinput values to an object in Lightning?
m working on a component where a table is generated by data entered into 3 input fields (Year, Make and Model). I have a function where the user's inputs are assigned to their corresponding variable which are then to be added to an object type attribute, GarageItems. This would then be used to populate the datatable in my component. How could I do this?
Here is my Component
Here is my Controller
Here is my Component
<aura:component> <aura:handler name="init" value="{! this }" action="{! c.init }"/> <aura:attribute name="YearInput" type="Integer"/> <lightning:input aura:id="IdYear" name="CarYear" placeholder="Please type the Car's Year" value="{! v.YearInput }" /> <aura:attribute name="MakeInput" type="String"/> <lightning:input aura:id="IdMake" name="CarMake" placeholder="Please type the Car's Make" value="{! v.MakeInput }" /> <aura:attribute name="ModelInput" type="String"/> <lightning:input aura:id="IdModel" name="CarModel" placeholder="Please type the Car's Model" value="{! v.ModelInput }" /> <aura:attribute name="GarageItems" type="Object"/> <aura:attribute name="Columns" type="List"/> <div style = "height: 300px"> <lightning:datatable key-field="id" data="{!v.GarageItems}" columns="{!v.Columns}"> </lightning:datatable> </div> <lightning:button variant="brand" label="Submit" title="Submit action" onclick="{! c.SubmitData }" /> <lightning:button variant="brand" label="Clear Fields" title="Clear action" onclick="{! c.ClearFields }" /> </aura:component>
Here is my Controller
({ init: function (cmp, event, helper) { cmp.set('v.Columns', [ {label: 'Year', fieldName: 'CarYear', type: 'integer'}, {label: 'Make', fieldName: 'CarMake', type: 'text'}, {label: 'Model', fieldName: 'CarModel', type: 'text'} ]); }, SubmitData : function(component, event, helper) { var Year = component.get("v.YearInput"); var Make = component.get("v.MakeInput"); var Model = component.get("v.ModelInput"); if ((Year != "")&&(Make != "")&&(Model != "")) {
//take year.make.model and add to GarageItems; **This is where I'm having the issue**
} else { return null; } }, ClearFields : function(component, event, helper) { component.set("v.YearInput", ""); component.set("v.MakeInput", ""); component.set("v.ModelInput", ""); } })
- Matthew Harris 40
- September 22, 2020
- Like
- 0
Lightning Component Table with Input Fields
I'm attempting to create a lightning component that displays a table that takes the input of 3 values (All of which are text fields) and adds them to said table.
I've seen examples online of components featuring tables populated with pre-existing data (such as https://sfdcmonkey.com/2017/02/20/custom-sorting-lightning-component/ or https://developer.salesforce.com/docs/component-library/bundle/lightning:datatable/example) but none with blank tables that are then populated with user-inputted data.
Are there any resources that someone could recommend? I'm very new and this is my first time interacting with aura components.
I've seen examples online of components featuring tables populated with pre-existing data (such as https://sfdcmonkey.com/2017/02/20/custom-sorting-lightning-component/ or https://developer.salesforce.com/docs/component-library/bundle/lightning:datatable/example) but none with blank tables that are then populated with user-inputted data.
Are there any resources that someone could recommend? I'm very new and this is my first time interacting with aura components.
- Matthew Harris 40
- September 19, 2020
- Like
- 0
Uknown Property Errors
Hello!
I am making contact search page where the Results and Errors pageblocks render based on the value of their corresponding booleans:
<apex:pageBlock title="Results" rendered="{!ResultsPresent}">
or this
<apex:pageBlock title="Errors" id="ErrorSection" rendered="{!ErrorsPresent}">
I keep getting "Unknown Property" errors.
Here are the pageblocks in question:
Here is my Controller
In a similar vein, I'm trying to also make an outputtext box that displays the number of results based the value of MatchingContacts but when I do that, I ALSO get an unknown property error.
What am I missing here?
I am making contact search page where the Results and Errors pageblocks render based on the value of their corresponding booleans:
- public boolean ResultsPresent
- public boolean ErrorsPresent
<apex:pageBlock title="Results" rendered="{!ResultsPresent}">
or this
<apex:pageBlock title="Errors" id="ErrorSection" rendered="{!ErrorsPresent}">
I keep getting "Unknown Property" errors.
Here are the pageblocks in question:
<!-- Results Display --> <apex:pageBlock title="Results" rendered="{!ResultsPresent}"> <apex:outputText value="There are currently '' results found." /> <apex:pageBlockSection > <apex:pageBlockTable value="{!contacts}" var="c" id="contact-table"> <apex:column > <apex:facet name="header">Name</apex:facet> {!c.Name} </apex:column> <apex:column > <apex:facet name="header">Phone Number</apex:facet> {!c.Phone} </apex:column> <apex:column > <apex:facet name="header">Email</apex:facet> {!c.Email} </apex:column> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> <!-- Error Display --> <apex:pageBlock title="Errors" id="ErrorSection" rendered="{!ErrorsPresent}"> <apex:pageMessages id="ErrorsListing"> </apex:pageMessages> </apex:pageBlock>
Here is my Controller
public with sharing class Ctrl_ContactSearch { public List<Contact> contacts { get; set; } public String name { get; set; } public String phone { get; set; } public String email { get; set; } public integer MatchingContacts = 0; public boolean ResultsPresent = false; public boolean ErrorsPresent = false; public boolean Error_NoResults = false; public boolean Error_FieldsEmpty = false; public boolean Error_NameSyntax = false; public boolean Error_PhoneSyntax = false; public boolean Error_EmailSyntax = false; /* Name Input Validation Regex*/ public static Boolean ValidationName (String name) { Boolean NameIsValid = false; String nameRegex = '[a-zA-Z]*[\\s]{1}[a-zA-Z].*'; 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\\(\\)\\/\\+ \\-]*)$'; 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 = '^[a-zA-Z0-9._|\\\\%#~`=?&/$^*!}{+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$'; Pattern PatternEmail = Pattern.compile(emailRegex); Matcher emailMatcher = PatternEmail.matcher(email); if (emailMatcher.matches()) { EmailIsValid = true; } return EmailIsValid; } /* Runs when "Clear Fields" button is pressed*/ public void ClearFields() { name = ''; phone = ''; email = ''; } /* Runs when "Search Contacts" button is pressed*/ public PageReference searchContacts() { /* Checks if input fields are empty*/ if (name == '' && phone == '' && email == '') { Error_FieldsEmpty = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Your fields are blank. Please enter your information in the remaining fields to proceed')); } else { /* Checks Input Validation Results*/ if (ValidationName(name) == false) { Error_NameSyntax = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Inproper name format. Please enter name in following format : Firstname Lastname.')); } if (ValidationPhone(phone) == false) { Error_PhoneSyntax = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Inproper phone number format. Please enter number in following format : XXX-XXX-XXXX.')); } if (ValidationEmail(email) == false) { Error_EmailSyntax = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Inproper email format. Please enter email in following format : XXX@emailprovider.com')); } /* Runs if all Validation results are 'true'*/ if (ValidationName(name) == true && ValidationPhone(phone) == true && ValidationEmail(email) == true) { ResultsPresent = true; contacts = [select Name, Phone, Email from Contact where Name = :name or Phone = :phone or email = :email]; MatchingContacts = contacts.size(); /* Checks if/how many matches were found from the search*/ if(MatchingContacts != 0) { return null; } else { Error_NoResults = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'No matching Contacts were found.')); } } } /* Displays "Error" field if any errors are found*/ if (Error_NoResults == true || Error_FieldsEmpty == true || Error_NameSyntax == true || Error_PhoneSyntax == true || Error_EmailSyntax == true) { ErrorsPresent = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'There are errors present. Please read and follow instructions accordingly.')); } return null; } }
In a similar vein, I'm trying to also make an outputtext box that displays the number of results based the value of MatchingContacts but when I do that, I ALSO get an unknown property error.
What am I missing here?
- Matthew Harris 40
- September 06, 2020
- Like
- 0
Why aren't my input validations working?
I'm working on a contact search page and I have a problem. My console has no errors but when I run a search, the results don't generate and all my input validation errors prompt.
For Example:
Here is my VisualForce Page:
What do I have wrong here?
For Example:
Here is my VisualForce Page:
<apex:page id="ContactPage" controller="Ctrl_ContactSearch"> <apex:tabPanel id="ContactPanel"> <apex:tab id="ContactTab" label="Contact Search"> <apex:form id="ContactForm"> <!-- Input Fields --> <apex:pageBlock title="Contact Search Page" id="ContactBlock"> <apex:pageBlockSection id="contact-table" columns="3"> <apex:pageBlockSectionItem id="NameInputBlock"> <apex:outputLabel value="Name" /> <apex:inputText id="NameInputField" value="{!name}" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem id="PhoneInputBlock"> <apex:outputLabel value="Phone" /> <apex:inputText id="PhoneInputField" value="{!phone}" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem id="EmailInputBlock"> <apex:outputLabel value="Email" /> <apex:inputText id="EmailInputField" value="{!email}" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> <!-- Buttons --> <apex:pageBlockButtons location="bottom"> <apex:commandButton value="Search Contacts" action="{!searchContacts}" /> <apex:commandButton value="Clear Fields" action="{!ClearFields}" /> </apex:pageBlockButtons> </apex:pageBlock> <!-- Results Display --> <apex:pageBlock title="Results" rendered="{!contacts.size!=0}" > <apex:pageBlockSection > <apex:pageBlockTable value="{!contacts}" var="c" id="contact-table"> <apex:column > <apex:facet name="header">Name</apex:facet> {!c.Name} </apex:column> <apex:column > <apex:facet name="header">Phone Number</apex:facet> {!c.Phone} </apex:column> <apex:column > <apex:facet name="header">Email</apex:facet> {!c.Email} </apex:column> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> <!-- Error Display --> <apex:pageBlock title="Errors" id="ErrorSection" > <apex:pageMessages id="ErrorsListing"> </apex:pageMessages> </apex:pageBlock> </apex:form> </apex:tab> </apex:tabPanel> <script type = "text/javascript"> var name = document.getElementByID("name"); var phone = document.getElementByID("phone"); var email = document.getElementByID("email"); </script> </apex:page>Here is my Controller
public with sharing class Ctrl_ContactSearch { public List<Contact> contacts { get; set; } public String name { get; set; } public String phone { get; set; } public String email { get; set; } public integer MatchingContacts { get; set; } public boolean ErrorsPresent = false; public boolean Error_NoResults = false; public boolean Error_FieldsEmpty = false; public boolean Error_NameSyntax = false; public boolean Error_PhoneSyntax = false; public boolean Error_EmailSyntax = false; /* 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; } /* Runs when "Clear Fields" button is pressed*/ public void ClearFields() { name = ''; phone = ''; email = ''; } /* Runs when "Search Contacts" button is pressed*/ public PageReference searchContacts() { /* Checks if input fields are empty*/ if (name == '' && phone == '' && email == '') { Error_FieldsEmpty = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Your fields are blank. Please enter your information in the remainding fields to proceed')); } else { /* Checks Input Validation Results*/ if (ValidationName(name) == false) { Error_NameSyntax = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Inproper name format. Please enter name in following format : Firstname Lastname.')); } if (ValidationPhone(phone) == false) { Error_PhoneSyntax = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Inproper phone number format. Please enter number in following format : XXX-XXX-XXXX.')); } if (ValidationPhone(email) == false) { Error_EmailSyntax = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Inproper email format. Please enter email in following format : XXX@emailprovider.com')); } /* Runs if all Validation results are 'true'*/ if (ValidationName(name) == true && ValidationPhone(phone) == true && ValidationPhone(email) == true) { contacts = [select Name, Phone, Email from Contact where Name = :name or Phone = :phone or email = :email]; MatchingContacts = contacts.size(); /* Checks if/how many matches were found from the search*/ if(MatchingContacts != 0) { system.debug('There are currently ' + MatchingContacts + 'results found.' ); } else { Error_NoResults = false; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'No matching Contacts were found.')); } } } /* Displays "Error" field if any errors are found*/ if (Error_NoResults == true || Error_FieldsEmpty == true || Error_NameSyntax == true || Error_PhoneSyntax == true || Error_EmailSyntax == true) { ErrorsPresent = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'There are errors present. Please read and follow instructions accordingly.')); } return null; } }
What do I have wrong here?
- Matthew Harris 40
- September 05, 2020
- Like
- 0
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*/
}
- Matthew Harris 40
- September 05, 2020
- Like
- 0
Uknown Property Errors
Hello!
I am making contact search page where the Results and Errors pageblocks render based on the value of their corresponding booleans:
<apex:pageBlock title="Results" rendered="{!ResultsPresent}">
or this
<apex:pageBlock title="Errors" id="ErrorSection" rendered="{!ErrorsPresent}">
I keep getting "Unknown Property" errors.
Here are the pageblocks in question:
Here is my Controller
In a similar vein, I'm trying to also make an outputtext box that displays the number of results based the value of MatchingContacts but when I do that, I ALSO get an unknown property error.
What am I missing here?
I am making contact search page where the Results and Errors pageblocks render based on the value of their corresponding booleans:
- public boolean ResultsPresent
- public boolean ErrorsPresent
<apex:pageBlock title="Results" rendered="{!ResultsPresent}">
or this
<apex:pageBlock title="Errors" id="ErrorSection" rendered="{!ErrorsPresent}">
I keep getting "Unknown Property" errors.
Here are the pageblocks in question:
<!-- Results Display --> <apex:pageBlock title="Results" rendered="{!ResultsPresent}"> <apex:outputText value="There are currently '' results found." /> <apex:pageBlockSection > <apex:pageBlockTable value="{!contacts}" var="c" id="contact-table"> <apex:column > <apex:facet name="header">Name</apex:facet> {!c.Name} </apex:column> <apex:column > <apex:facet name="header">Phone Number</apex:facet> {!c.Phone} </apex:column> <apex:column > <apex:facet name="header">Email</apex:facet> {!c.Email} </apex:column> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> <!-- Error Display --> <apex:pageBlock title="Errors" id="ErrorSection" rendered="{!ErrorsPresent}"> <apex:pageMessages id="ErrorsListing"> </apex:pageMessages> </apex:pageBlock>
Here is my Controller
public with sharing class Ctrl_ContactSearch { public List<Contact> contacts { get; set; } public String name { get; set; } public String phone { get; set; } public String email { get; set; } public integer MatchingContacts = 0; public boolean ResultsPresent = false; public boolean ErrorsPresent = false; public boolean Error_NoResults = false; public boolean Error_FieldsEmpty = false; public boolean Error_NameSyntax = false; public boolean Error_PhoneSyntax = false; public boolean Error_EmailSyntax = false; /* Name Input Validation Regex*/ public static Boolean ValidationName (String name) { Boolean NameIsValid = false; String nameRegex = '[a-zA-Z]*[\\s]{1}[a-zA-Z].*'; 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\\(\\)\\/\\+ \\-]*)$'; 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 = '^[a-zA-Z0-9._|\\\\%#~`=?&/$^*!}{+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$'; Pattern PatternEmail = Pattern.compile(emailRegex); Matcher emailMatcher = PatternEmail.matcher(email); if (emailMatcher.matches()) { EmailIsValid = true; } return EmailIsValid; } /* Runs when "Clear Fields" button is pressed*/ public void ClearFields() { name = ''; phone = ''; email = ''; } /* Runs when "Search Contacts" button is pressed*/ public PageReference searchContacts() { /* Checks if input fields are empty*/ if (name == '' && phone == '' && email == '') { Error_FieldsEmpty = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Your fields are blank. Please enter your information in the remaining fields to proceed')); } else { /* Checks Input Validation Results*/ if (ValidationName(name) == false) { Error_NameSyntax = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Inproper name format. Please enter name in following format : Firstname Lastname.')); } if (ValidationPhone(phone) == false) { Error_PhoneSyntax = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Inproper phone number format. Please enter number in following format : XXX-XXX-XXXX.')); } if (ValidationEmail(email) == false) { Error_EmailSyntax = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Inproper email format. Please enter email in following format : XXX@emailprovider.com')); } /* Runs if all Validation results are 'true'*/ if (ValidationName(name) == true && ValidationPhone(phone) == true && ValidationEmail(email) == true) { ResultsPresent = true; contacts = [select Name, Phone, Email from Contact where Name = :name or Phone = :phone or email = :email]; MatchingContacts = contacts.size(); /* Checks if/how many matches were found from the search*/ if(MatchingContacts != 0) { return null; } else { Error_NoResults = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'No matching Contacts were found.')); } } } /* Displays "Error" field if any errors are found*/ if (Error_NoResults == true || Error_FieldsEmpty == true || Error_NameSyntax == true || Error_PhoneSyntax == true || Error_EmailSyntax == true) { ErrorsPresent = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'There are errors present. Please read and follow instructions accordingly.')); } return null; } }
In a similar vein, I'm trying to also make an outputtext box that displays the number of results based the value of MatchingContacts but when I do that, I ALSO get an unknown property error.
What am I missing here?
- Matthew Harris 40
- September 06, 2020
- Like
- 0
Why aren't my input validations working?
I'm working on a contact search page and I have a problem. My console has no errors but when I run a search, the results don't generate and all my input validation errors prompt.
For Example:
Here is my VisualForce Page:
What do I have wrong here?
For Example:
Here is my VisualForce Page:
<apex:page id="ContactPage" controller="Ctrl_ContactSearch"> <apex:tabPanel id="ContactPanel"> <apex:tab id="ContactTab" label="Contact Search"> <apex:form id="ContactForm"> <!-- Input Fields --> <apex:pageBlock title="Contact Search Page" id="ContactBlock"> <apex:pageBlockSection id="contact-table" columns="3"> <apex:pageBlockSectionItem id="NameInputBlock"> <apex:outputLabel value="Name" /> <apex:inputText id="NameInputField" value="{!name}" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem id="PhoneInputBlock"> <apex:outputLabel value="Phone" /> <apex:inputText id="PhoneInputField" value="{!phone}" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem id="EmailInputBlock"> <apex:outputLabel value="Email" /> <apex:inputText id="EmailInputField" value="{!email}" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> <!-- Buttons --> <apex:pageBlockButtons location="bottom"> <apex:commandButton value="Search Contacts" action="{!searchContacts}" /> <apex:commandButton value="Clear Fields" action="{!ClearFields}" /> </apex:pageBlockButtons> </apex:pageBlock> <!-- Results Display --> <apex:pageBlock title="Results" rendered="{!contacts.size!=0}" > <apex:pageBlockSection > <apex:pageBlockTable value="{!contacts}" var="c" id="contact-table"> <apex:column > <apex:facet name="header">Name</apex:facet> {!c.Name} </apex:column> <apex:column > <apex:facet name="header">Phone Number</apex:facet> {!c.Phone} </apex:column> <apex:column > <apex:facet name="header">Email</apex:facet> {!c.Email} </apex:column> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> <!-- Error Display --> <apex:pageBlock title="Errors" id="ErrorSection" > <apex:pageMessages id="ErrorsListing"> </apex:pageMessages> </apex:pageBlock> </apex:form> </apex:tab> </apex:tabPanel> <script type = "text/javascript"> var name = document.getElementByID("name"); var phone = document.getElementByID("phone"); var email = document.getElementByID("email"); </script> </apex:page>Here is my Controller
public with sharing class Ctrl_ContactSearch { public List<Contact> contacts { get; set; } public String name { get; set; } public String phone { get; set; } public String email { get; set; } public integer MatchingContacts { get; set; } public boolean ErrorsPresent = false; public boolean Error_NoResults = false; public boolean Error_FieldsEmpty = false; public boolean Error_NameSyntax = false; public boolean Error_PhoneSyntax = false; public boolean Error_EmailSyntax = false; /* 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; } /* Runs when "Clear Fields" button is pressed*/ public void ClearFields() { name = ''; phone = ''; email = ''; } /* Runs when "Search Contacts" button is pressed*/ public PageReference searchContacts() { /* Checks if input fields are empty*/ if (name == '' && phone == '' && email == '') { Error_FieldsEmpty = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Your fields are blank. Please enter your information in the remainding fields to proceed')); } else { /* Checks Input Validation Results*/ if (ValidationName(name) == false) { Error_NameSyntax = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Inproper name format. Please enter name in following format : Firstname Lastname.')); } if (ValidationPhone(phone) == false) { Error_PhoneSyntax = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Inproper phone number format. Please enter number in following format : XXX-XXX-XXXX.')); } if (ValidationPhone(email) == false) { Error_EmailSyntax = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Inproper email format. Please enter email in following format : XXX@emailprovider.com')); } /* Runs if all Validation results are 'true'*/ if (ValidationName(name) == true && ValidationPhone(phone) == true && ValidationPhone(email) == true) { contacts = [select Name, Phone, Email from Contact where Name = :name or Phone = :phone or email = :email]; MatchingContacts = contacts.size(); /* Checks if/how many matches were found from the search*/ if(MatchingContacts != 0) { system.debug('There are currently ' + MatchingContacts + 'results found.' ); } else { Error_NoResults = false; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'No matching Contacts were found.')); } } } /* Displays "Error" field if any errors are found*/ if (Error_NoResults == true || Error_FieldsEmpty == true || Error_NameSyntax == true || Error_PhoneSyntax == true || Error_EmailSyntax == true) { ErrorsPresent = true; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'There are errors present. Please read and follow instructions accordingly.')); } return null; } }
What do I have wrong here?
- Matthew Harris 40
- September 05, 2020
- Like
- 0
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*/
}
- Matthew Harris 40
- September 05, 2020
- Like
- 0