You need to sign in to do that
Don't have an account?
Mohan Raj 33
I have received the DATE type input on the controller in astring manner then how it converted to date field if any one can know?
I have the controller here I tried to the multiple field filterization but in the birthdatefield only not work it's give an error can any one help me to remove this error:Compile Error: Method does not exist or incorrect signature: YEAR(String) at line 124 column 46
My controller:
public class SortOfContactListController {
public List<Contact> ContactListTable {get; set;}
public String ExpressionOfSort = 'name';
public String DirectionOfSort = 'ASC';
public List<Contact> ContactResults {get; set;}
public SortOfContactListController() {
ContactListTable = new List<Contact>();
ContactResults = new List<Contact>();
}
/* public string searchtext {
get;
set;
}*/
public string ContactName {
get;
set;
}
public string Phone {
get;
set;
}
public string AccountName {
get;
set;
}
// String AccountName = Apexpages.currentPage().getParameters().get('AccountName');
public String BirthDate {
get;
set;
}
/*public string BirthdateMIN {
get;
set;
}
public string BirthdateMAX {
get;
set;
}*/
public string Email {
get;
set;
}
public string MailingCity {
get;
set;
}
public string MailingCountry {
get;
set;
}
public string MailingPostalCode {
get;
set;
}
public String ExpressionSort {
get {
return ExpressionOfSort;
}
set {
If(value == ExpressionOfSort) {
DirectionOfSort = (DirectionOfSort == 'ASC')? 'DESC' : 'ASC';
}
else {
DirectionOfSort = 'ASC';
ExpressionOfSort = value;
}
}
}
public String getDirectionOfSort() {
If(ExpressionOfSort == Null || ExpressionOfSort == '') {
return 'DESC';
}
else {
return DirectionOfSort;
}
}
public void setDirectionOfSort(String value) {
DirectionOfSort = value;
}
public List<Contact>getContacts() {
return ContactListTable;
}
public PageReference ViewData() {
String FullSortExpression = ExpressionOfSort + ' ' + DirectionOfSort;
system.debug('ExpressionOfSort:::::'+ExpressionOfSort);
system.debug(DirectionOfSort);
//String Queryitem = new String();
String Queryitem = ' SELECT Id, Name, Account.Name, Birthdate, Phone, Email, MailingCity, MailingCountry, MailingPostalCode FROM Contact WHERE Account.Name != Null ORDER BY ' + FullSortExpression +' Limit 1000';
system.debug(Queryitem);
ContactListTable = DataBase.query(Queryitem);
system.debug(ContactListTable);
return Null;
}
public PageReference Search(){
String searchquery = ' SELECT Id, Name, Account.Name, Birthdate, Phone, Email, MailingCity, MailingCountry, MailingPostalCode FROM Contact WHERE Account.Name != Null ';
system.debug(searchquery);
String condition = '';
if (ContactName != null && ContactName != '')
condition += ' and Name LIKE \'' + ContactName + '%\'';
if (AccountName != null && AccountName != '')
condition += ' and Account.Name LIKE \'' + AccountName + '%\'';
if (BirthDate != null && BirthDate != '')
condition += ' and Birthdate = \'' + YEAR(Birthdate) + '%\'' ;
if (Phone != null && Phone != '')
condition += ' and Phone LIKE \'' + Phone + '%\'';
if (Email != null && Email != '')
condition += ' and Email LIKE \'' + Email + '%\'';
if (MailingCountry != null && MailingCountry != '')
condition += ' and MailingCountry LIKE \'' + MailingCountry + '%\'';
if (MailingCity != null && MailingCity != '')
condition += ' and MailingCity LIKE \'' + MailingCity + '%\'';
if (MailingPostalCode != null && MailingPostalCode != '')
condition += ' and MailingPostalCode LIKE \'' + MailingPostalCode + '%\'';
if(condition != ''){
searchquery += condition;
System.debug(' searchquery:::::::: '+searchquery);
ContactResults = DataBase.query(searchquery);
system.debug(' ContactResults::::::::::: '+ContactResults);
}
return Null;
}
}
My controller:
public class SortOfContactListController {
public List<Contact> ContactListTable {get; set;}
public String ExpressionOfSort = 'name';
public String DirectionOfSort = 'ASC';
public List<Contact> ContactResults {get; set;}
public SortOfContactListController() {
ContactListTable = new List<Contact>();
ContactResults = new List<Contact>();
}
/* public string searchtext {
get;
set;
}*/
public string ContactName {
get;
set;
}
public string Phone {
get;
set;
}
public string AccountName {
get;
set;
}
// String AccountName = Apexpages.currentPage().getParameters().get('AccountName');
public String BirthDate {
get;
set;
}
/*public string BirthdateMIN {
get;
set;
}
public string BirthdateMAX {
get;
set;
}*/
public string Email {
get;
set;
}
public string MailingCity {
get;
set;
}
public string MailingCountry {
get;
set;
}
public string MailingPostalCode {
get;
set;
}
public String ExpressionSort {
get {
return ExpressionOfSort;
}
set {
If(value == ExpressionOfSort) {
DirectionOfSort = (DirectionOfSort == 'ASC')? 'DESC' : 'ASC';
}
else {
DirectionOfSort = 'ASC';
ExpressionOfSort = value;
}
}
}
public String getDirectionOfSort() {
If(ExpressionOfSort == Null || ExpressionOfSort == '') {
return 'DESC';
}
else {
return DirectionOfSort;
}
}
public void setDirectionOfSort(String value) {
DirectionOfSort = value;
}
public List<Contact>getContacts() {
return ContactListTable;
}
public PageReference ViewData() {
String FullSortExpression = ExpressionOfSort + ' ' + DirectionOfSort;
system.debug('ExpressionOfSort:::::'+ExpressionOfSort);
system.debug(DirectionOfSort);
//String Queryitem = new String();
String Queryitem = ' SELECT Id, Name, Account.Name, Birthdate, Phone, Email, MailingCity, MailingCountry, MailingPostalCode FROM Contact WHERE Account.Name != Null ORDER BY ' + FullSortExpression +' Limit 1000';
system.debug(Queryitem);
ContactListTable = DataBase.query(Queryitem);
system.debug(ContactListTable);
return Null;
}
public PageReference Search(){
String searchquery = ' SELECT Id, Name, Account.Name, Birthdate, Phone, Email, MailingCity, MailingCountry, MailingPostalCode FROM Contact WHERE Account.Name != Null ';
system.debug(searchquery);
String condition = '';
if (ContactName != null && ContactName != '')
condition += ' and Name LIKE \'' + ContactName + '%\'';
if (AccountName != null && AccountName != '')
condition += ' and Account.Name LIKE \'' + AccountName + '%\'';
if (BirthDate != null && BirthDate != '')
condition += ' and Birthdate = \'' + YEAR(Birthdate) + '%\'' ;
if (Phone != null && Phone != '')
condition += ' and Phone LIKE \'' + Phone + '%\'';
if (Email != null && Email != '')
condition += ' and Email LIKE \'' + Email + '%\'';
if (MailingCountry != null && MailingCountry != '')
condition += ' and MailingCountry LIKE \'' + MailingCountry + '%\'';
if (MailingCity != null && MailingCity != '')
condition += ' and MailingCity LIKE \'' + MailingCity + '%\'';
if (MailingPostalCode != null && MailingPostalCode != '')
condition += ' and MailingPostalCode LIKE \'' + MailingPostalCode + '%\'';
if(condition != ''){
searchquery += condition;
System.debug(' searchquery:::::::: '+searchquery);
ContactResults = DataBase.query(searchquery);
system.debug(' ContactResults::::::::::: '+ContactResults);
}
return Null;
}
}
Please use this your modified code: Please mark this as best answer if your query is resolved, so it will help others in future.
Thanks,
Gaurav Jain
All Answers
1.First convert birthdate to date.
2.Then get year using date.year() method.
Try like this.
Let me know if it helps.
Make it as best answer if it helps.
THanks.
Please use this your modified code: Please mark this as best answer if your query is resolved, so it will help others in future.
Thanks,
Gaurav Jain