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
JCoppedgeJCoppedge 

search button that pulls up first found record

I'm looking to make my search function pull up the first found result.  I've gotten it to work except that the link that is delivered has a bunch of extra characters I can't seem to get rid of:  https://na6.salesforce.com/(Account:%7BId=0018000000NbMUIAA3%7D).  I know I am missing something very simple here.  Can anyone point me in the right direction?
 
I can't figure out how to get just the ID from the getResult() function...
 
Page:
Code:
<apex:page id="salesPartner" controller="AccountController" tabStyle="Account" > 
 <apex:pageBlock title="Search Accounts">  
  <apex:form >   
   <apex:inputText id="searchBox" value="{!searchText}"/>   
   <apex:commandButton action="{!search2}" value="Search" id="searchBtn"/>   
   <apex:dataTable value="{!result}" var="acc" id="data" >    
    <apex:column >     
     <apex:facet name="header"><b>Name</b></apex:facet>      {!acc.id}    
    </apex:column>   
   </apex:dataTable> 
  </apex:form> 
 </apex:pageBlock>
</apex:page>

 
Controller
Code:
public class AccountController{

public String getSearchText() {

return null;

}

private List<Account> result = new List<Account>();

private String searchText;

public AccountController(){

}

public List<Account> getResult() {return result;}

public void setSearchText(String searchText)

{ this.searchText = searchText; }



public void search()
{
result = [select id from Account Where Name like :searchText LIMIT 1];}


public PageReference search2() {


    PageReference next = new PageReference('/'+getResult());
    next.setRedirect(true);
    return next;


  }




}

 
Sam.arjSam.arj

do not use getResult method for your page reference object.


Code:
Account acc = getResult[0];

PageReference next = new PageReference('/'+ acc.id);
next.setRedirect(true);
return next;

 
Also note that when you are using "limit 1" option in your SOQL then you are allowed to use the follow statement:
Code:
Account a = [select id from Account Where Name like :searchText LIMIT 1];

Cheers,
 

JCoppedgeJCoppedge
Code:
Account acc = getResult[0];

PageReference next = new PageReference('/'+ acc.id);
next.setRedirect(true);
return next;

 Both methods worked flawlessly (just removed the get shown above), thanks.
ToddKruseToddKruse

Along these lines.  I need to create an "uber" page.  Its a mashup of a custom object with lots of the bells and gadgets all on one new page.  I know how to create a new VF page and override how its opened.  But I was looking to create a new page with a dropdown list of projects.  Then when one is selected, it just refreshes the page with the information that is tied to that project.  I have read that you can drop in sections from a page into a new page, but I have not seen this done.  Anyone do this?

 

Thanks

 

--Todd Kruse