+ Start a Discussion
MATTYBMEMATTYBME 

Searching Solutions search method

Having trouble determining the right controller method for a search page for searching Solutions. I want to do a similar search function to the Find Solutions box that can be displayed in a homepage.

Code:
<apex:page controller="Solutions">
<apex:form>
<apex:pageBlock mode="edit" id="block">
<apex:pageBlockSection>
<apex:pageBlockSectionItem>
<apex:outputLabel for="searchSolutionText">Search Solutions</apex:outputLabel>
<apex:panelGroup>
<apex:inputText id="searchSolutionText" value="{!searchSolutionText}"/>
<apex:commandButton value="Go!" action="{!doSearch}"
rerender="block" status="status"/>
</apex:panelGroup>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:actionStatus id="status" startText="requesting..."/>
<apex:pageBlockSection title="Results" id="results" columns="1">
<apex:pageBlockTable value="{!results}" var="l"
rendered="{!NOT(ISNULL(results))}">
66
Controller Methods
<apex:column value="{!l.solutionname}"/>
<apex:column value="{!l.solutionnote}"/>
<apex:column value="{!l.createddate}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 
Code:
public class Solution {
String searchSolutionText;
List<Solution> results;
public String getSearchSolutionText() {
return searchSolutionText;
}
public void setSearchSolutionText(String s) {
searchSolutionText = s;
}
public List<Solution> getResults() {
return results;
}
public PageReference doSearch() {
results = (List<Solution>)[FIND :searchSolutionText RETURNING Solution(SolutionName, SolutionNote, CreatedDate)][0];
return null;
}
}

 I get a "Error: Compile Error: Incompatible types since an instance of LIST:SObject is never an instance of LIST:Solution at line 14 column 11" on the Apex Class.

Not sure how to proceed.




Message Edited by MATTYBME on 01-12-2009 06:05 AM
aalbertaalbert
I was able to get this snippet of SOSL With Solutions to compile (you will need to replace it with your 'searchSolutionText' variable since I removed that for simple test)

Code:
List<List<SObject>> searchList = [FIND 'name' RETURNING Solution(SolutionName, SolutionNote, CreatedDate)];
Solution [] sols = ((List<Solution>)searchList[0]);
  

 

MATTYBMEMATTYBME
So replace (Code portion stirke through):
Code:
public class Solution {
String searchSolutionText;
List<Solution> results;
public String getSearchSolutionText() {
return searchSolutionText;
}
public void setSearchSolutionText(String s) {
searchSolutionText = s;
}
public List<Solution> getResults() {
return results;
}
public PageReference doSearch() {
results = (List<Solution>)[FIND :searchSolutionText RETURNING Solution(SolutionName, SolutionNote, CreatedDate)][0];
return null;
}
}

 with:

Code:
results = List<List<Solutions>> searchSolutionList = [FIND 'searchSolutionList' RETURNING Solution(SolutionName, SolutionNote, CreatedDate)];
Solution [] sols = ((List<Solution>)searchSolutionList[0]);

 Correct?



MATTYBMEMATTYBME
I actually figured it out.

Code:
<apex:page controller="SolutionSearch" tabstyle="Solutions__tab">
<apex:sectionHeader title="Solutions" subtitle="Finding Answers to Common Questions"/>
<apex:form >
<apex:pageBlock mode="edit" id="block">
<apex:pageBlockSection columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel for="searchSolutionText">Find Answers</apex:outputLabel>
<apex:panelGroup >
<apex:inputText id="searchSolutionText" value="{!searchSolutionText}" style="width: 400px"/>
<apex:commandButton value="Find!" action="{!doSearch}"
rerender="block" status="status"/>
</apex:panelGroup>
</apex:pageBlockSectionItem>
<br>
Type in a keyword or phrase to your question to find any relevant published answers or type in the error message you are seeing.</br>
</apex:pageBlockSection><br>
<apex:actionStatus id="status" startText="Finding..."/></br>
<apex:pageBlockSection title="Relevant Solutions" id="results" columns="1">
<apex:pageBlockTable value="{!results}" var="l" rendered="{!NOT(ISNULL(results))}">
<apex:column headervalue="Solution Title">
<apex:outputLink value="/{!l.Id}" target="_self">{!l.solutionname}</apex:outputLink>
</apex:column>
<apex:column headervalue="Solution Details">
<apex:outputText value="{!l.solutionnote}"/></apex:column>
<apex:column value="{!l.createddate}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Code:
public class SolutionSearch {
String searchSolutionText;
List<Solution> results;
public String getSearchSolutionText() {
return searchSolutionText;
}
public void setSearchSolutionText(String s) {
searchSolutionText = s;
}
public List<Solution> getResults() {
return results;
}
public PageReference doSearch() {
results = (List<Solution>)[FIND :searchSolutionText RETURNING Solution(SolutionName, SolutionNote, CreatedDate)][0];
return null;
}
}

 
 Thanks for the help.

RGK.ax912RGK.ax912

Is there any way to limit the search result to solutions that are Visible To the Public rather than returning all solutions.

 

Thanks