You need to sign in to do that
Don't have an account?
data.migration1.3948976100296348E12
Search functionality Performance Issue............
Hi All,
I am creating search functionality it's working fine..
but when i click search button i'ts time taken after records display..
i want quick response .....
please help on this.....
Thanks advance.............
Here my code
public without sharing class CustomerSearchController
{
public PageReference search()
{
try{
pbflag=true;
boolean errflag=false;
if(commonAppSettings__c.getInstance('global')!=null)
size=Integer.valueOf(commonAppSettings__c.getInstance('global').Pagination_Size__c);
String companycode=LoggedInUser.companyName;
accIdSet = new Set<Id>();
//Enters into the If loop if the search is of CustomerCode and the results are stored in StandardSetController for pagination.
if(selectedOption == CODE_SEARCH)
{
// addToDVLFlag=true;
if(accnt != null && (accnt.Customer_Code__c == null || accnt.Customer_Code__c == ''))
{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, Label.Mandatory_Customer_Code);
ApexPages.addMessage(myMsg);
pbflag = false;
errflag = true;
return null;
}
//Gets the customer record based on the customercode entered and the organization of the user.
AllSearchCustomers = [select a.Id, a.Name, a.Speciality__c, a.Qualification1__c, a.PersonMobilePhone, a.LastName, a.Hospital_Type__c, a.RecordType.Name, a.searchable__c,a.IsPersonAccount,
a.FirstName, a.Customer_Code__c, (Select Id, Primary__c,Address__r.State__r.Name, Address__r.City__r.Name,Address__r.Area_Locality_Taluka__r.Name,Address__r.Address_Line1__c From Address_junctions__r),
(select Id,Target__r.User__r.name,Target__r.User__r.Division,Target__r.User__r.EmployeeNumber from Assignments__r)
From Account a
where a.Customer_Code__c=:accnt.Customer_Code__c and RecordType.Name=:selectedCustomerType and Organization__c=:companycode AND Searchable__c=true limit 1];
system.debug('-----AllSearchCustomers -------'+AllSearchCustomers.size());
List<Address_Junction__c> addList = new List<Address_Junction__c>();
List<Assignment__c> assgnList = new List<Assignment__c>();
if(AllSearchCustomers != null && !AllSearchCustomers.isEmpty()) {
for(Account a : AllSearchCustomers)
{
addList = a.Address_junctions__r;
assgnList = a.Assignments__r;
}
}
if(assgnList != null) {
System.debug('Total Assignments:'+assgnList.size());
}
if(addList !=null && !addList.isEmpty())
primaryAddress = true;
else
primaryAddress = false;
Set<Id> userIds = new Set<Id>();
assignTBMValues(AllSearchCustomers);
}
//Enters into the If loop if the search is of FilterCriteria and the results are stored in StandardSetController for pagination.
else if(selectedOption == FILTER_SEARCH && personAccount==true)
{
// addToDVLFlag=true;
primaryAddress = true;
/* if(accnt != null && (accnt.Last_Name__c==null || accnt.Last_Name__c==''))
{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, Label.Mandatory_Last_Name);
ApexPages.addMessage(myMsg);
errflag=true;
pbflag = false;
}
if(accnt != null && (accnt.First_Name__c == null || accnt.First_Name__c == ''))
{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, Label.Mandatory_First_Name);
ApexPages.addMessage(myMsg);
errflag=true;
pbflag = false;
}
Addjunduplist =[Select Id, Primary__c,Account__C,Account__r.name,Account__r.RecordType.Name,Account__r.Customer_Code__c,Account__r.lastname,Account__r.firstname,Account__r.Speciality__c ,Account__r.Qualification1__c,
Address__r.State__r.Name, Address__r.City__r.Name,Address__r.Area_Locality_Taluka__r.Name,Address__r.Address_Line1__c From Address_junction__c
WHERE
Account__r.name LIKE:accnt.first_name__c +'%'+accnt.Last_Name__c+'%' and Account__r.RecordType.Name=:selectedCustomerType and Account__r.Organization__c=:companycode
and Account__r.searchable__c = true];
system.debug('--------------Addjunduplist-----------'+Addjunduplist);
assignTBMDetails(Addjunduplist);*/
string FName='%'+accnt.first_name__c +'%';
String MName='%'+accnt.Middle_Name__c+'%';
string LName='%'+accnt.last_name__c+'%';
system.debug('--------------------FName--------------------'+Fname);
String Acclist='Select Id, Primary__c,Account__C,Account__r.name,Account__r.RecordType.Name,Account__r.Customer_Code__c,Account__r.lastname,Account__r.firstname,Account__r.Middle_Name__c ,'+
'Account__r.Speciality__c ,Account__r.Qualification1__c,Address__r.State__r.Name, Address__r.City__r.Name,Address__r.Area_Locality_Taluka__r.Name,'+
'Address__r.Address_Line1__c,Address__r.Address_Line2__c From Address_junction__c '+
'WHERE Account__r.RecordType.Name=:selectedCustomerType '+
' AND Account__r.firstname LIKE: FName '+
' AND Account__r.lastname LIKE: LName ';
if(selectedState!=Null)
Acclist+=' AND Address__r.State__r.Name=:selectedState';
if(selectedCity!=Null)
Acclist+=' AND Address__r.City__r.Name=:selectedCity' ;
if(accnt.Middle_Name__c!=Null && accnt.Middle_Name__c!='')
Acclist+=' AND Account__r.Middle_Name__c LIKE : MName';
system.debug('--------------sobjects ----LName------'+Database.query(Acclist));
addjunlistfinal = Database.query(Acclist);
assignTBMDetails(addjunlistfinal);
// addjunlistfinal.clear();
} // End FILTER_SEARCH && personAccount==true
I am creating search functionality it's working fine..
but when i click search button i'ts time taken after records display..
i want quick response .....
please help on this.....
Thanks advance.............
Here my code
public without sharing class CustomerSearchController
{
public PageReference search()
{
try{
pbflag=true;
boolean errflag=false;
if(commonAppSettings__c.getInstance('global')!=null)
size=Integer.valueOf(commonAppSettings__c.getInstance('global').Pagination_Size__c);
String companycode=LoggedInUser.companyName;
accIdSet = new Set<Id>();
//Enters into the If loop if the search is of CustomerCode and the results are stored in StandardSetController for pagination.
if(selectedOption == CODE_SEARCH)
{
// addToDVLFlag=true;
if(accnt != null && (accnt.Customer_Code__c == null || accnt.Customer_Code__c == ''))
{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, Label.Mandatory_Customer_Code);
ApexPages.addMessage(myMsg);
pbflag = false;
errflag = true;
return null;
}
//Gets the customer record based on the customercode entered and the organization of the user.
AllSearchCustomers = [select a.Id, a.Name, a.Speciality__c, a.Qualification1__c, a.PersonMobilePhone, a.LastName, a.Hospital_Type__c, a.RecordType.Name, a.searchable__c,a.IsPersonAccount,
a.FirstName, a.Customer_Code__c, (Select Id, Primary__c,Address__r.State__r.Name, Address__r.City__r.Name,Address__r.Area_Locality_Taluka__r.Name,Address__r.Address_Line1__c From Address_junctions__r),
(select Id,Target__r.User__r.name,Target__r.User__r.Division,Target__r.User__r.EmployeeNumber from Assignments__r)
From Account a
where a.Customer_Code__c=:accnt.Customer_Code__c and RecordType.Name=:selectedCustomerType and Organization__c=:companycode AND Searchable__c=true limit 1];
system.debug('-----AllSearchCustomers -------'+AllSearchCustomers.size());
List<Address_Junction__c> addList = new List<Address_Junction__c>();
List<Assignment__c> assgnList = new List<Assignment__c>();
if(AllSearchCustomers != null && !AllSearchCustomers.isEmpty()) {
for(Account a : AllSearchCustomers)
{
addList = a.Address_junctions__r;
assgnList = a.Assignments__r;
}
}
if(assgnList != null) {
System.debug('Total Assignments:'+assgnList.size());
}
if(addList !=null && !addList.isEmpty())
primaryAddress = true;
else
primaryAddress = false;
Set<Id> userIds = new Set<Id>();
assignTBMValues(AllSearchCustomers);
}
//Enters into the If loop if the search is of FilterCriteria and the results are stored in StandardSetController for pagination.
else if(selectedOption == FILTER_SEARCH && personAccount==true)
{
// addToDVLFlag=true;
primaryAddress = true;
/* if(accnt != null && (accnt.Last_Name__c==null || accnt.Last_Name__c==''))
{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, Label.Mandatory_Last_Name);
ApexPages.addMessage(myMsg);
errflag=true;
pbflag = false;
}
if(accnt != null && (accnt.First_Name__c == null || accnt.First_Name__c == ''))
{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, Label.Mandatory_First_Name);
ApexPages.addMessage(myMsg);
errflag=true;
pbflag = false;
}
Addjunduplist =[Select Id, Primary__c,Account__C,Account__r.name,Account__r.RecordType.Name,Account__r.Customer_Code__c,Account__r.lastname,Account__r.firstname,Account__r.Speciality__c ,Account__r.Qualification1__c,
Address__r.State__r.Name, Address__r.City__r.Name,Address__r.Area_Locality_Taluka__r.Name,Address__r.Address_Line1__c From Address_junction__c
WHERE
Account__r.name LIKE:accnt.first_name__c +'%'+accnt.Last_Name__c+'%' and Account__r.RecordType.Name=:selectedCustomerType and Account__r.Organization__c=:companycode
and Account__r.searchable__c = true];
system.debug('--------------Addjunduplist-----------'+Addjunduplist);
assignTBMDetails(Addjunduplist);*/
string FName='%'+accnt.first_name__c +'%';
String MName='%'+accnt.Middle_Name__c+'%';
string LName='%'+accnt.last_name__c+'%';
system.debug('--------------------FName--------------------'+Fname);
String Acclist='Select Id, Primary__c,Account__C,Account__r.name,Account__r.RecordType.Name,Account__r.Customer_Code__c,Account__r.lastname,Account__r.firstname,Account__r.Middle_Name__c ,'+
'Account__r.Speciality__c ,Account__r.Qualification1__c,Address__r.State__r.Name, Address__r.City__r.Name,Address__r.Area_Locality_Taluka__r.Name,'+
'Address__r.Address_Line1__c,Address__r.Address_Line2__c From Address_junction__c '+
'WHERE Account__r.RecordType.Name=:selectedCustomerType '+
' AND Account__r.firstname LIKE: FName '+
' AND Account__r.lastname LIKE: LName ';
if(selectedState!=Null)
Acclist+=' AND Address__r.State__r.Name=:selectedState';
if(selectedCity!=Null)
Acclist+=' AND Address__r.City__r.Name=:selectedCity' ;
if(accnt.Middle_Name__c!=Null && accnt.Middle_Name__c!='')
Acclist+=' AND Account__r.Middle_Name__c LIKE : MName';
system.debug('--------------sobjects ----LName------'+Database.query(Acclist));
addjunlistfinal = Database.query(Acclist);
assignTBMDetails(addjunlistfinal);
// addjunlistfinal.clear();
} // End FILTER_SEARCH && personAccount==true
1.Go to Setup | Customize | Home | Home Page Components
2.Click New
3.Name it: Search
4.Select Type as: HTML Area
5.Follow the screenshot [Source Code: http://goo.gl/8pAQ14]:
6.Save it.
Now, you have to add it to the Home Page Layout. Here you go:
1.Setup | Customize | Home | Home Page Layouts
2.Click Edit
3.From Select Narrow Components to Show, check the option: Search
4.Click Next
5.Sort it to the top
6.Save
You can also turn the Show Custom Sidebar Components on All Pages [ Setup | Customize | User Interface ] to make this visible on All Pages.
thanks,
Ramesh
I am creating here all custamization ...
so how can overcome search performence issue.........
Thanks,
Venu
for best practices for SOQL.
thanks,
RAmesh