You need to sign in to do that
Don't have an account?
d.tejdeep@nicomatic.in
Result of sosl query convert to list and show in visualforce page
public List<sObject> sobjlst {get; set;} public void find() { if(searchText != null && searchText.length() > 1){ List<List<SObject>> results = [FIND :('*' + searchText + '*') IN ALL FIELDS RETURNING Contact (Id, Name, Email, Account.Name,MailingStreet, MailingCity, MailingPostalCode, MailingState, MailingCountry,Location__Latitude__s, Location__Longitude__s) , Account (Id, Name, Billingstreet, Billingcity, BillingPostalcode, Billingstate, Billingcountry, Location__Latitude__s, Location__Longitude__s) , Lead (Id, Name, Email, street,city,postalcode,state,country, Location__Latitude__s, Location__Longitude__s) ]; contacts = (List<Contact>)results[0]; acc=(List<account>)results[1]; lea=(List<lead>)results[2]; if(results!=null && results.isempty()){ for(list<sObject> objectList :results ){ sobjlst .addall(objectList); } } if(sobjlst.isEmpty()){ ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'No matches for "' + searchText + '"')); } else { serverSideGeocode(); } } else { if(sobjlst != null) { contacts.clear(); } ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Please provide at least 2 characters for the search.')); } }
<apex:form id="form"> <apex:pageBlock id="searchBlock"> <apex:inputText value="{!searchText}" /> <apex:commandButton value="Search" action="{!find}"/> <p>Examples: <a href="/apex/{!$CurrentPage.Name}?q=USA">"USA"</a>, "Singapore", "Uni", "(336) 222-7000". If it works in the global search box, it will work here.</p> </apex:pageBlock> <apex:pageBlock title="Found {!sobjlst.size} Contact(s)..." rendered="{!NOT(ISNULL(sobjlst)) && sobjlst.size > 0}" id="resultsBlock"> <apex:pageBlockButtons location="top"> <apex:commandButton value="Clear cached locations" title="Click if you want to set 'null' as geolocation info for all these contacts" action="{!clearGeocodedData}" /> </apex:pageBlockButtons> <apex:pageBlockTable value="{!sobjlst}" var="c" id="contacts"> <apex:column headerValue="{!$ObjectType.Contact.fields.Name.label}"> <apex:outputLink value="../{!c['Id']}">{!c['Name']}</apex:outputLink> </apex:column> </apex:pageBlockTable> <pre id="log"></pre> </apex:pageBlock> </apex:form>
System.NullPointerException: Attempt to de-reference a null object Error is in expression '{!find}' in component in page findnearby1: Class.mapController.find: line 31, column 1
Class.mapController.find: line 31, column 1
if( sobjlst == NULL || sobjlst.isEmpty())
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'No matches for "' + searchText + '"'));
} else
{
serverSideGeocode();
}
Thx
Use this code to initialize sobjlst
sobjlst = new List<sObject>();