You need to sign in to do that
Don't have an account?
Error: Non-void method might not return a value or might have statement after a return statement.
Can please help me to resolve error.
VF code
<apex:page controller="AsFour" sidebar="false" tabStyle="Account">
<apex:form >
<apex:sectionHeader title="AssignmentFour"/>
<apex:pageBlock >
<apex:pageBlockSection title="Search">
<apex:inputText value="{!searchString}" label="Search"/>
<apex:commandButton value="Search" action="{!doSearch}" reRender="output"/>
</apex:pageBlockSection>
<apex:outputPanel id="output">
<apex:pageBlockSection title="Results">
<apex:pageBlockTable value="{!accounts}" var="a">
<apex:column value="{!a.name}"/>
<apex:column value="{!a.BillingState}"/>
<apex:column value="{!a.Phone}"/>
<apex:column value="{!a.Webiste}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller class
public class AsFour {
String Accountqurey;
public list<Account> listAccount{ get; set; }
public String searchString { get; set; }
public String errMsg;
public PageReference doSearch() {
listAccount = new list<Account>();
if(searchString !='' && searchString !=null){
for (List<Account> listAccount : [Select Id,Name,BillingState,Phone,Website FROM Account where name =:'searchString']) {
if(listAccount.size()>0 && listAccount.size()!= null){
}
else{
ApexPages.Message errMsg = new ApexPages.Message(ApexPages.Severity.Warning,'No Accounts Found');
ApexPages.addMessage(errMsg);
}
}
}
}
}
Hello,
You are using accountsin the table
<apex:pageBlockTable value="{!accounts}" var="a">
But in controller you are fetching in this listAccount list.
So you must iterate thsi list in the table to get the values.
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
All Answers
Do it like this
public class AsFour {
String Accountqurey;
public list<Account> listAccount{ get; set; }
public String searchString { get; set; }
public String errMsg;
public PageReference doSearch() {
listAccount = new list<Account>();
if(searchString !='' && searchString !=null){
for (List<Account> listAccount : [Select Id,Name,BillingState,Phone,Website FROM Account where name =:'searchString']) {
if(listAccount.size()>0 && listAccount.size()!= null){
}
else{
ApexPages.Message errMsg = new ApexPages.Message(ApexPages.Severity.Warning,'No Accounts Found');
ApexPages.addMessage(errMsg);
}
}
}
return NULL;
}
}
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Thanks for reply.But if tired to search<United Oil & Gas Corp> a account from VF page unable to retrieve account details in Output panel. Any help is highly appreciated
public class AsFour {
List<Account> accounts;
String Accountqurey;
public list<Account> listAccount{ get; set; }
public String searchString { get; set; }
public String errMsg;
public List<Account> getAccounts() {
return accounts;
}
public PageReference doSearch() {
listAccount = new list<Account>();
if(searchString !='' && searchString !=null){
for (List<Account> listAccount : [Select Id,Name,BillingState,Phone,Website FROM Account where name =:'searchString']) {
if(listAccount.size()>0 && listAccount.size()!= null){
}
else{
ApexPages.Message errMsg = new ApexPages.Message(ApexPages.Severity.Warning,'No Accounts Found');
ApexPages.addMessage(errMsg);
}
}
}
return NULL;
}
Hello,
You are using accountsin the table
<apex:pageBlockTable value="{!accounts}" var="a">
But in controller you are fetching in this listAccount list.
So you must iterate thsi list in the table to get the values.
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Hi Vishnu,
Actually the problem is your query. In your scenario, you have to use dynamic soql. Try this
public class AsFour {
List<Account> accounts;
String Accountqurey;
public list<Account> listAccount{ get; set; }
public String searchString { get; set; }
public String errMsg;
public List<Account> getAccounts() {
return accounts;
}
public PageReference doSearch() {
listAccount = new list<Account>();
if(searchString !='' && searchString !=null){
String searchQuery = 'Select Id,Name,BillingState,Phone,Website FROM Account where name = \'+searchString+\'';
for (List<Account> listAccount : Database.query(searchQuery)) {
if(listAccount.size()>0 && listAccount.size()!= null){
}
else{
ApexPages.Message errMsg = new ApexPages.Message(ApexPages.Severity.Warning,'No Accounts Found');
ApexPages.addMessage(errMsg);
}
}
}
return NULL;
}
}
Thanks,
Hi Souvik,
Thanks for solution..
Here is a qucik question like in my VF page there are two pageblock section 1 for Search Text and search button and second one is to show results.
Here in the first section i'm faceing a long gap between search Text and button
Please find VF code
<apex:page controller="AsFour" sidebar="false" tabStyle="Account">
<apex:form >
<apex:pageMessages ></apex:pageMessages>
<apex:sectionHeader title="AsFour"/>
<apex:pageBlock >
<apex:pageBlockSection title="Search">
<apex:pageBlockSectionItem >
<apex:outputText value="Search"></apex:outputText>
<apex:inputText label="Search" value="{!searchString}"/>
</apex:pageBlockSectionItem>
<apex:commandButton value="Search" action="{!doSearch}" reRender="output,msg"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock >
<apex:outputPanel id="output">
<apex:pageBlockSection title="Results">
<apex:pageBlockTable value="{!accounts}" var="a">
<apex:column value="{!a.name}"/>
<apex:column value="{!a.BillingState}"/>
<apex:column value="{!a.Phone}"/>
<apex:column value="{!a.Website}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
Try to keep
<apex:commandButton value="Search" action="{!doSearch}" reRender="output,msg"/>
within
<apex:pageBlockSectionItem>
and test what is coming.
If the post helps you, please throw KUDOS.
Thanks
Tried as u said but throws error that <apex:pageBlockSectionItem> component can have only 2 child components.
Here i blocked actually.Any idea pls.
Then you can do like this
<apex:pageBlockSection title="Search" column="2">
<apex:outputText value="Search"></apex:outputText>
<apex:inputText label="Search" value="{!searchString}"/>
<apex:commandButton value="Search" action="{!doSearch}" reRender="output,msg"/>
</apex:pageBlockSection>
If this post is helpful please throw Kudos.
Thanks