if you want know the how the sosl work dynamically :
1.create visualforce page
with flowing code:
<apex:page controller="soslexampleclass">
<apex:form >
<apex:pageBlock >
<apex:inputText value="{!str}"/>
<apex:commandButton value="Show Records" action="{!showRecordsMethod}"/>
</apex:pageBlock>
</apex:form>
<apex:pageBlock title="accounts">
<apex:pageBlockTable value="{!acclist}" var="acc">
<apex:column value="{!acc.name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock title="conatcs">
<apex:pageBlockTable value="{!conlist}" var="acc">
<apex:column value="{!acc.name}"/>
<apex:column value="{!acc.email}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock title="opportunities">
<apex:pageBlockTable value="{!opplist}" var="acc">
<apex:column value="{!acc.name}"/>
<apex:column value="{!acc.stagename}"/>
</apex:pageBlockTable>
<apex:pageBlock title="leads">
<apex:pageBlockTable value="{!leadlist}" var="acc">
<apex:column value="{!acc.name}"/>
<apex:column value="{!acc.company}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:pageBlock>
</apex:page>
=============================
controller::::::::::::::
public class soslexampleclass {
public String str { get; set; }
public List<lead> leadlist{set;get;}
public List<Account> acclist{set;get;}
public List<Contact> conlist{set;get;}
public List<opportunity> opplist{set;get;}
public void showRecordsMethod() {
system.debug('444444444444444444444'+str);
leadlist= new List<lead>();
acclist=new list<account>();
conlist=new list<contact>();
opplist=new list<opportunity>();
List<List<SObject>> searchlist=[find :str IN ALL FIELDS RETURNING ACCOUNT(ID,NAME),CONTACT(NAME,EMAIL),OPPORTUNITY(NAME,STAGENAME),LEAD(COMPANY,NAME,STATUS)];
acclist=((List<account>)searchlist[0]);
conlist=((List<contact>)searchlist[1]);
opplist=((List<opportunity>)searchlist[2]);
leadlist=((List<lead>)searchlist[3]);
}
}
Enjoy.....
1.create visualforce page
with flowing code:
<apex:page controller="soslexampleclass">
<apex:form >
<apex:pageBlock >
<apex:inputText value="{!str}"/>
<apex:commandButton value="Show Records" action="{!showRecordsMethod}"/>
</apex:pageBlock>
</apex:form>
<apex:pageBlock title="accounts">
<apex:pageBlockTable value="{!acclist}" var="acc">
<apex:column value="{!acc.name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock title="conatcs">
<apex:pageBlockTable value="{!conlist}" var="acc">
<apex:column value="{!acc.name}"/>
<apex:column value="{!acc.email}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock title="opportunities">
<apex:pageBlockTable value="{!opplist}" var="acc">
<apex:column value="{!acc.name}"/>
<apex:column value="{!acc.stagename}"/>
</apex:pageBlockTable>
<apex:pageBlock title="leads">
<apex:pageBlockTable value="{!leadlist}" var="acc">
<apex:column value="{!acc.name}"/>
<apex:column value="{!acc.company}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:pageBlock>
</apex:page>
=============================
controller::::::::::::::
public class soslexampleclass {
public String str { get; set; }
public List<lead> leadlist{set;get;}
public List<Account> acclist{set;get;}
public List<Contact> conlist{set;get;}
public List<opportunity> opplist{set;get;}
public void showRecordsMethod() {
system.debug('444444444444444444444'+str);
leadlist= new List<lead>();
acclist=new list<account>();
conlist=new list<contact>();
opplist=new list<opportunity>();
List<List<SObject>> searchlist=[find :str IN ALL FIELDS RETURNING ACCOUNT(ID,NAME),CONTACT(NAME,EMAIL),OPPORTUNITY(NAME,STAGENAME),LEAD(COMPANY,NAME,STATUS)];
acclist=((List<account>)searchlist[0]);
conlist=((List<contact>)searchlist[1]);
opplist=((List<opportunity>)searchlist[2]);
leadlist=((List<lead>)searchlist[3]);
}
}
Enjoy.....
No comments:
Post a Comment