You need to sign in to do that
Don't have an account?
Venkatesh L
public class SearchGlobal {
public List <Account> acc {set;get;}
public List <Contact> con {set;get;}
public List <Opportunity> opp {set;get;}
public List <Lead> ld {set;get;}
public boolean noMatchesFound {set;get;}
public boolean isNull {set;get;}
public boolean isLess {set;get;}
public boolean isMagic {set;get;}
public boolean isCon {set;get;}
public boolean isOpp {set;get;}
public boolean isLd {set;get;}
public Integer m {set;get;}
public Integer n {set;get;}
public Integer o {set;get;}
public Integer p {set;get;}
public String name {set;get;}
public String orderType {set;get;}
public String searchVal {set;get;}
public void accOrder()
{
if(orderType == Null || orderType =='DESC')
{
acc = Database.query('Select id, Name, Phone from Account where id IN :acc order by ' + Name + ' DESC');
orderType = 'ASC';
}
else
{
acc = Database.query('Select id, Name, Phone from Account where id IN :acc order by ' + Name + ' '+orderType);
orderType = 'DESC';
}
}
public void conOrder()
{
if(orderType == Null || orderType =='DESC')
{
con = Database.query('Select LastName, Phone from Contact where id IN :con order by ' + Name + ' DESC');
orderType = 'ASC';
}
else
{
con = Database.query('Select LastName, Phone from Contact where id IN :con order by ' + Name + ' '+orderType);
orderType = 'DESC';
}
}
public void oppOrder()
{
if(orderType == Null || orderType =='DESC')
{
opp = Database.query('Select Name, Amount from Opportunity where id IN :opp order by ' + Name + ' DESC');
orderType = 'ASC';
}
else
{
opp = Database.query('Select Name, Amount from Opportunity where id IN :opp order by ' + Name + ' '+orderType);
orderType = 'DESC';
}
}
public void ldOrder()
{
if(orderType == Null || orderType =='DESC')
{
ld = Database.query('Select Name, Company from Lead where id IN :ld order by ' + Name + ' DESC');
orderType = 'ASC';
}
else
{
ld = Database.query('Select Name, Company from Lead where id IN :ld order by ' + Name + ' '+orderType);
orderType = 'DESC';
}
}
public pageReference doSearch()
{
if(searchVal==null || searchVal=='')
{
isNull = true;
isLess = false;
noMatchesFound = false;
isMagic = false;
isCon = false;
isOpp = false;
isLd = false;
return null;
}
else if (searchVal.length()<=2)
{
isLess = true;
isNull = false;
noMatchesFound = false;
isMagic = false;
isCon = false;
isOpp = false;
isLd = false;
return null;
}
else
{
String s='FIND '+'\''+searchVal+'\' IN ALL FIELDS RETURNING Account(name,phone),Contact(lastname,phone),Opportunity(Name,Amount),Lead(Name,Company)';
List<List<sObject>> searchList = search.query(s);
sObject[] asl = (List <Account>) searchList[0];
sObject[] csl = (List <Contact>)searchList[1];
sObject[] osl = (List <Opportunity>) searchList[2];
sObject[] lsl = (List <Lead>) searchList[3];
acc = asl;
con = csl;
opp = osl;
ld = lsl;
m=searchList[0].size();
n=searchList[1].size();
o=searchList[2].size();
p=searchList[3].size();
if(!acc.isEmpty())
{
isMagic=true;
isLess = false;
isNull = false;
noMatchesFound = false;
}
else
{
isMagic=false;
}
if(!con.isEmpty() )
{
isCon=true;
isLess = false;
isNull = false;
noMatchesFound = false;
}
else
{
isCon=false;
}
if(!opp.isEmpty())
{
isOpp=true;
isLess = false;
isNull = false;
noMatchesFound = false;
}
else
{
isOpp=false;
}
if(!ld.isEmpty())
{
isLd=true;
isLess = false;
isNull = false;
noMatchesFound = false;
}
else
{
isLd=false;
}
if(acc.isEmpty() && con.isEmpty() && opp.isEmpty() && ld.isEmpty())
{
noMatchesFound = true;
isLess = false;
isNull = false;
}
else
{
noMatchesFound = false;
}
return null;
}
}
public PageReference moreAccounts()
{
PageReference refAcc=new PageReference('/apex/Accounts');
return refAcc;
}
public PageReference moreContacts()
{
PageReference refCon=new PageReference('/apex/Contacts');
return refCon;
}
public PageReference moreOpportunities()
{
PageReference refOpp=new PageReference('/apex/Opportunities');
return refOpp;
}
public PageReference moreLeads()
{
PageReference refLds=new PageReference('/apex/Leads');
return refLds;
}
}
how to test my apex class
public class SearchGlobal {
public List <Account> acc {set;get;}
public List <Contact> con {set;get;}
public List <Opportunity> opp {set;get;}
public List <Lead> ld {set;get;}
public boolean noMatchesFound {set;get;}
public boolean isNull {set;get;}
public boolean isLess {set;get;}
public boolean isMagic {set;get;}
public boolean isCon {set;get;}
public boolean isOpp {set;get;}
public boolean isLd {set;get;}
public Integer m {set;get;}
public Integer n {set;get;}
public Integer o {set;get;}
public Integer p {set;get;}
public String name {set;get;}
public String orderType {set;get;}
public String searchVal {set;get;}
public void accOrder()
{
if(orderType == Null || orderType =='DESC')
{
acc = Database.query('Select id, Name, Phone from Account where id IN :acc order by ' + Name + ' DESC');
orderType = 'ASC';
}
else
{
acc = Database.query('Select id, Name, Phone from Account where id IN :acc order by ' + Name + ' '+orderType);
orderType = 'DESC';
}
}
public void conOrder()
{
if(orderType == Null || orderType =='DESC')
{
con = Database.query('Select LastName, Phone from Contact where id IN :con order by ' + Name + ' DESC');
orderType = 'ASC';
}
else
{
con = Database.query('Select LastName, Phone from Contact where id IN :con order by ' + Name + ' '+orderType);
orderType = 'DESC';
}
}
public void oppOrder()
{
if(orderType == Null || orderType =='DESC')
{
opp = Database.query('Select Name, Amount from Opportunity where id IN :opp order by ' + Name + ' DESC');
orderType = 'ASC';
}
else
{
opp = Database.query('Select Name, Amount from Opportunity where id IN :opp order by ' + Name + ' '+orderType);
orderType = 'DESC';
}
}
public void ldOrder()
{
if(orderType == Null || orderType =='DESC')
{
ld = Database.query('Select Name, Company from Lead where id IN :ld order by ' + Name + ' DESC');
orderType = 'ASC';
}
else
{
ld = Database.query('Select Name, Company from Lead where id IN :ld order by ' + Name + ' '+orderType);
orderType = 'DESC';
}
}
public pageReference doSearch()
{
if(searchVal==null || searchVal=='')
{
isNull = true;
isLess = false;
noMatchesFound = false;
isMagic = false;
isCon = false;
isOpp = false;
isLd = false;
return null;
}
else if (searchVal.length()<=2)
{
isLess = true;
isNull = false;
noMatchesFound = false;
isMagic = false;
isCon = false;
isOpp = false;
isLd = false;
return null;
}
else
{
String s='FIND '+'\''+searchVal+'\' IN ALL FIELDS RETURNING Account(name,phone),Contact(lastname,phone),Opportunity(Name,Amount),Lead(Name,Company)';
List<List<sObject>> searchList = search.query(s);
sObject[] asl = (List <Account>) searchList[0];
sObject[] csl = (List <Contact>)searchList[1];
sObject[] osl = (List <Opportunity>) searchList[2];
sObject[] lsl = (List <Lead>) searchList[3];
acc = asl;
con = csl;
opp = osl;
ld = lsl;
m=searchList[0].size();
n=searchList[1].size();
o=searchList[2].size();
p=searchList[3].size();
if(!acc.isEmpty())
{
isMagic=true;
isLess = false;
isNull = false;
noMatchesFound = false;
}
else
{
isMagic=false;
}
if(!con.isEmpty() )
{
isCon=true;
isLess = false;
isNull = false;
noMatchesFound = false;
}
else
{
isCon=false;
}
if(!opp.isEmpty())
{
isOpp=true;
isLess = false;
isNull = false;
noMatchesFound = false;
}
else
{
isOpp=false;
}
if(!ld.isEmpty())
{
isLd=true;
isLess = false;
isNull = false;
noMatchesFound = false;
}
else
{
isLd=false;
}
if(acc.isEmpty() && con.isEmpty() && opp.isEmpty() && ld.isEmpty())
{
noMatchesFound = true;
isLess = false;
isNull = false;
}
else
{
noMatchesFound = false;
}
return null;
}
}
public PageReference moreAccounts()
{
PageReference refAcc=new PageReference('/apex/Accounts');
return refAcc;
}
public PageReference moreContacts()
{
PageReference refCon=new PageReference('/apex/Contacts');
return refCon;
}
public PageReference moreOpportunities()
{
PageReference refOpp=new PageReference('/apex/Opportunities');
return refOpp;
}
public PageReference moreLeads()
{
PageReference refLds=new PageReference('/apex/Leads');
return refLds;
}
}
You need to create dummy data first and call your methods in test class. If you are not fimiliar with test classes then you should refer trailhead for apex testing.