You need to sign in to do that
Don't have an account?
swamy PRN
Task
Hi,
This is swamy. i want details about this program(In visual force page iam creating one Textbox & besides that am creating one button named as display )
If i enter Record name in text box then click display button.
then it must show, in which object the record belongs to and the record details should be display.
If anyone knows reply me
Hi,
For you task you can make use of SOSL in Apex. SOSL statements evaluate to a list of lists of sObjects, where each list contains the search results for a particular sObject type. The result lists are always returned in the same order as they were specified in the SOSL query. SOSL queries are only supported in Apex classes and anonymous blocks. You cannot use a SOSL query in a trigger. If a SOSL query does not return any records for a specified sObject type, the search results include an empty list for that sObject.
For example, you can return a list of accounts, contacts, opportunities, and leads that begin with the phrase map:
List<List<SObject>> searchList = [FIND 'map*' IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, Lead];
For more detail refer to below link:
http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL.htm
Hi,
Try the below code snippet as reference:
<apex:page controller="cls_sosl" >
<apex:form >
<apex:outputLabel >enter the text</apex:outputLabel>
<apex:inputText value="{!element}" />
<apex:commandButton value="Search" action="{!getsearch}" />
</apex:form>
<apex:pageBlock id="sp" >
<apex:pageBlockSection title="Lead">
<apex:pageBlockTable value="{!leads}" var="l">
<apex:column headerValue="Name" ><apex:outputLink value="/{!l.id}">{!l.name}</apex:outputLink> </apex:column>
<apex:column value="{!l.email}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:pageBlockSection title="Contact">
<apex:pageBlockTable value="{!contacts}" var="c" title="Contact">
<apex:column headerValue="Name" ><apex:outputLink value="/{!c.id}">{!c.name}</apex:outputLink> </apex:column>
<apex:column value="{!c.Accountid}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
--- Apex Controller ----------------
public class cls_sosl {
public Account [] accounts{get;set;}
public Contact [] contacts{get;set;}
public Opportunity [] opportunities{get;set;}
public Lead [] leads{get;set;}
public string element{get;set;}
public void getsearch()
{
string h = element+'*';
List<List<SObject>> searchList = [FIND :h IN ALL FIELDS RETURNING Account (id, name,phone), Contact(id,name,Accountid,phone), Opportunity(id, name), Lead(id, name,phone,Email)limit 200 ];
System.debug('******************************'+searchList);
accounts = ((List<Account>)searchList[0]);
contacts = ((List<Contact>)searchList[1]);
opportunities = ((List<Opportunity>)searchList[2]);
leads = ((List<Lead>)searchList[3]);
System.debug('*************accounts *****************'+accounts.size());
System.debug('*************contacts *****************'+contacts .size());
System.debug('*************opportunities *****************'+opportunities .size());
System.debug('*************leads *****************'+leads .size());
// return searchList ;
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
Hi,
For you task you can make use of SOSL in Apex. SOSL statements evaluate to a list of lists of sObjects, where each list contains the search results for a particular sObject type. The result lists are always returned in the same order as they were specified in the SOSL query. SOSL queries are only supported in Apex classes and anonymous blocks. You cannot use a SOSL query in a trigger. If a SOSL query does not return any records for a specified sObject type, the search results include an empty list for that sObject.
For example, you can return a list of accounts, contacts, opportunities, and leads that begin with the phrase map:
List<List<SObject>> searchList = [FIND 'map*' IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, Lead];
For more detail refer to below link:
http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL.htm
Hi,
Try the below code snippet as reference:
<apex:page controller="cls_sosl" >
<apex:form >
<apex:outputLabel >enter the text</apex:outputLabel>
<apex:inputText value="{!element}" />
<apex:commandButton value="Search" action="{!getsearch}" />
</apex:form>
<apex:pageBlock id="sp" >
<apex:pageBlockSection title="Lead">
<apex:pageBlockTable value="{!leads}" var="l">
<apex:column headerValue="Name" ><apex:outputLink value="/{!l.id}">{!l.name}</apex:outputLink> </apex:column>
<apex:column value="{!l.email}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:pageBlockSection title="Contact">
<apex:pageBlockTable value="{!contacts}" var="c" title="Contact">
<apex:column headerValue="Name" ><apex:outputLink value="/{!c.id}">{!c.name}</apex:outputLink> </apex:column>
<apex:column value="{!c.Accountid}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
--- Apex Controller ----------------
public class cls_sosl {
public Account [] accounts{get;set;}
public Contact [] contacts{get;set;}
public Opportunity [] opportunities{get;set;}
public Lead [] leads{get;set;}
public string element{get;set;}
public void getsearch()
{
string h = element+'*';
List<List<SObject>> searchList = [FIND :h IN ALL FIELDS RETURNING Account (id, name,phone), Contact(id,name,Accountid,phone), Opportunity(id, name), Lead(id, name,phone,Email)limit 200 ];
System.debug('******************************'+searchList);
accounts = ((List<Account>)searchList[0]);
contacts = ((List<Contact>)searchList[1]);
opportunities = ((List<Opportunity>)searchList[2]);
leads = ((List<Lead>)searchList[3]);
System.debug('*************accounts *****************'+accounts.size());
System.debug('*************contacts *****************'+contacts .size());
System.debug('*************opportunities *****************'+opportunities .size());
System.debug('*************leads *****************'+leads .size());
// return searchList ;
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Thanks for giving the solution.....it's working...