+ Start a Discussion
sales@myvarmasales@myvarma 

i m trying to code vf page which search for opportunities when we enter name in search box

after searching if we get re ords with that name it should have options beside to every record to edit or delete the record
Akshay_DhimanAkshay_Dhiman
Hi pradeep ,

Try the below code it will help you.

VisualForce page :-
 
<apex:page controller="DisplayRecordController" >
    <script>
    function getAccount()
        {
         	Xyz();
        }
    
    </script>
    <apex:form id="form">
       <apex:pageBlock >
        <apex:actionFunction name="Xyz" action="{!Show}" />
    	<apex:inputText value="{!OppName}" />
        <input type="button" value="Gocheck" onclick ="getAccount()" />  
        <apex:outputPanel Id="dis">
            
          <apex:pageBlockTable columns="5" var="opp" value="{!opplist}" >
            	<apex:column value="{!opp.Id}" />
              	<apex:column value="{!opp.Name}" />
              	<apex:column value="{!opp.AccountId}" />
              	<apex:column value="{!opp.CloseDate}" />
              <apex:column value="{!opp.StageName}"/>
              <apex:column >
                    <apex:outputLink title="" value="/{!opp.id}/e?
  retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>
                	&nbsp;|&nbsp;
               
                  <apex:commandLink action="{!deleteDeal}" onclick="if(!confirm('Are you sure?')) return false;">Del
                      <apex:param value="{!opp.Id}" name="idToDel" assignTo="{!SelectedOpportunityId}"/>
                  </apex:commandLink>
                        
              </apex:column>
              
              </apex:pageBlockTable>
        </apex:outputPanel>
           </apex:pageBlock>
    </apex:form>
</apex:page>



Controller (Apex class) :
 
public class DisplayRecordController
{
    public String OppName{get ; set;}
    public string SelectedOpportunityId { get; set; }
    public list<Opportunity> opplist{get;set;}
    public DisplayRecordController()
    {
       	opplist = new list<Opportunity>();
        OppName = '';
        SelectedOpportunityId = '' ;
    }
    
    public void Show()
    {	
        if(OppName != NULL)
    	{
        opplist = [ SELECT ID , Name , CloseDate , StageName , AccountId from Opportunity WHERE Name =: OppName ];
           
        }
    }
    
    public void deleteDeal()
    {
         opplist = [ SELECT ID , Name , CloseDate , StageName , AccountId from Opportunity WHERE Id =: SelectedOpportunityId ];
       
        if(opplist.size() > 0 || opplist[0].Id != '')
        {
            delete opplist;
     }
        Show();
        
   }
}
 
Regards ,
Akshay
Please mark my answer as a solution if it was helpful.