function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Linda 98Linda 98 

Custom button with Vf page

Created a custom object on record detail page.VF page will search records by using query in controller.
It has a input field and holds search text.I want to have more flexibity with the search text.It is being filled with value from record field.Like name of record.But i would like to give user to change the search text if he wants and still fit in the query.Like dynamic text field.
It has to work two ways,value from standard field and also should work if user chnages the value and give new value.Please help.
 
Deepali KulshresthaDeepali Kulshrestha
Hi Linda,
I have done the same thing i.e searching an account based on user string.
Please refer to the following code as it may be helpful in solving your problem.
Controller:

public with sharing class accsearchcontroller {  
   public list <account> acc {get;set;}  
   public string searchstring {get;set;}  
   public accsearchcontroller(ApexPages.StandardController controller) {  
   }  
   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();  
   }  
 }  


Vf Page:
<apex:page standardController="account" extensions="accsearchcontroller">  
  <apex:form >  
 <apex:inputText value="{!searchstring}" label="Input"/>   
  <apex:commandButton value="Search records" action="{!search}"/>  
  <apex:commandButton value="Clear records" action="{!search}"/>  
   <apex:pageBlock title="Search Result">  
    <apex:pageblockTable value="{!acc}" var="a">  
     <apex:column >  
      <apex:outputlink value="https://ap1.salesforce.com/{!a.id}">{!a.Name}</apex:outputlink>  
     </apex:column>  
     <apex:column value="{!a.id}"/>  
    </apex:pageBlockTable>     
   </apex:pageBlock>   
  </apex:form>  
 </apex:page>  


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
Linda 98Linda 98
Yes.This is exactly what I have done now. bUt ,my requirement is when clicked on the button ,it should open My VF page and name from detail page,should be populated in the search text This should work.But if I want to change the text,I should be able to do that also and then search .

Hope it's clear.Thank you! 
Linda 98Linda 98
Oh...never mind!!

Was able to figure out my mistake. Thank you again for replying Deepali.