You need to sign in to do that
Don't have an account?
Hoysala
Put a button named “Search”, that will be used to search accounts, when accounts found display. If not found show messaging saying no accounts found. Put a Create button on page as well if no records found to create new account.
Put a button named “Search”, that will be used to search accounts, when accounts found display. If not found show messaging saying no
accounts found. Put a Create button on page as well if no records found to create new account.
accounts found. Put a Create button on page as well if no records found to create new account.
Greetings to you!
Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Visualforce:
Controller:
Visualforce Page to create Account: CreateAccount
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks and Regards,
Khan Anas
Below code can fulfill your requirements, Hope this will work for you.
Controller :
public with sharing class accsearchcontroller {
public list <account> acc {get;set;}
public string searchstring {get;set;}
public accsearchcontroller( ) {
}
public void search(){
string searchquery='select name,id from account where name like \'%'+searchstring+'%\' Limit 20';
acc= Database.query(searchquery);
}
public void clear(){
acc.clear();
}
}
Visualforce page:
<apex:page Controller="accsearchcontroller" >
<apex:form >
<apex:inputText value="{!searchstring}" label="Input"/>
<apex:commandButton value="Search records" action="{!search}"/>
<apex:commandButton value="Clear records" action="{!clear}"/>
<apex:pageBlock title="Search Result">
<apex:pageblockTable value="{!acc}" var="a">
<apex:column value="{!a.name}"/>
<apex:column value="{!a.id}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Please mark this as best answer if this solves your problem.
Thank you,
Ajay Dubedi