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
Daniel KDaniel K 

hyperlink for vfpage

Hi All,
            I have created a formula field with hyperlink and when clicked on that it opens vfpage in same tab.
          
            Now, when I select something from vfpage I want to return to the main page(not custom vfpage).

            If anyone know pls suggest.

Thanks.
Banwari kevat1Banwari kevat1
Hi Daniel,
  You can put  record id in hyper link parameter and recieve it into vfpage and create a custom link  as following: 
<apex:outputlink value="/{!$CurrentPage.parameters.yourRecordId}"}">Go Back</apex:outputlink>
yourRecordId is a parameter you set in heperlink as folows:
HYPERLINK("/apex/vfpage?yourRecordId ="+ Id , 'my hyperlink')

Let me know it its help you.

Thanks
Banwari
 
Daniel KDaniel K
Hi Banwari,
                      Thanks for quick response.

                      My formula field is as below:

HYPERLINK("/apex/vfpage1?Id="&Id, "linktovfpage","_self")

May be I can create a custom link as suggested, but how can I get the value which I select from vfpage to main page.

Thank you.
Banwari kevat1Banwari kevat1
What is the purpose of value you selected on vfpage. Can you give me a exact requirement you need to complete?

Thanks 
Baanwari
Daniel KDaniel K
After clicking on the link, vf page opens, then on the vfpage i will search on a product and after getting results of search I want to select one of the results. Once I select a product I should come back to main page and be able to display the name of the product in a different field of the main page. I have already done with formula field hyperlink, vfpage search.
But, I'm struck at navigating back to main page with the selected product name.

It will be helpful if you can share any links which work similar to my requirement.

Thank You.
Banwari kevat1Banwari kevat1
You can add product into url parameter:
 
ApexPages.currentPage().setParameters().put('ProductName', productName);
<apex:outputlink value="/{!$CurrentPage.parameters.yourRecordId}&{!$CurrentPage.parameters.productName}"}">Go Back</apex:outputlink>

 
Daniel KDaniel K

public class AccountSearch 
{
    public Account account {get;set;}
    public List<Account> results{get;set;}
    public string searchString{get;set;}
    public boolean showmsg{get;set;}
    public Map<string,boolean> MaptoId{get;set;}
    public string AccName{get;set;}
    public string Id{get;set;}
    
    public AccountSearch()
    {
        account = new Account();
        results=new List<Account>();
        showmsg = false;
    }
    
    public PageReference search() 
    {
        
        results=performSearch(searchString);
        return null;
    }
    
    private List<Account> performSearch(string searchString)
    {
        List<Account> SearchResult=new List<Account>();
        system.debug('SearchString ' +searchString);
        {
            String soql = 'select id,name,site,industry,type,phone from account';
            if(searchString != '' && searchString != null)
                soql = soql +  ' where name LIKE \'%' + searchString +'%\'';
            list<account> tempacclist = database.query(soql+' limit 100');
            system.debug(soql);
            if(tempacclist.size()>100)
            {
                ApexPages.Message myMsg = new ApexPages.Message(ApexPages.severity.WARNING, 'Please narrow down your search');
                ApexPages.addMessage(myMsg);
                showmsg=true;
                
            }
            else if(tempacclist.size() == 0)
            {
                
                ApexPages.Message myMsg = new ApexPages.Message(ApexPages.severity.WARNING,'No Data Found');
                ApexPages.addMessage(myMsg);
                showmsg=true;
            }
            else
            {
                showmsg=false; 
                SearchResult = tempacclist ;
            }
                ApexPages.currentPage().getParameters().put('Id', Id);
                ApexPages.currentPage().getParameters().put('Acc_Name__c', AccName);
        }    
        return SearchResult;
    }


}
Here, I'm trying with Account object.
I know that I'm missing something to redirect to main account page in below highlighted outputlink
<apex:page controller="AccountSearch" title="Search"
           showHeader="false" 
           sideBar="false" 
           tabStyle="Account" 
           id="pg"
           docType="html-5.0">  
    <apex:form >
        <apex:outputPanel >     
            <apex:actionstatus id="status">
                <apex:facet name="start">
                    <div class="waitingSearchDiv" id="el_loading"> 
                        <div class="waitingHolder">
                            <img class="waitingImage" src="/img/loading.gif" title="Please Wait..." />                  
                            <span class="waitingDescription">Searching...</span>
                        </div>
                    </div>
                </apex:facet>
            </apex:actionstatus>
        </apex:outputPanel>
        
        <apex:outputPanel id="page" layout="block">
            <apex:actionRegion >  
                <apex:outputPanel id="top" layout="block">
                    <apex:outputLabel value="Search Name" for="txtSearch"/>
                    <apex:inputText id="txtSearch" value="{!searchString}" />
                    <span style="padding-left:5px"><apex:commandButton id="btnGo" value="Search" action="{!Search}" rerender="searchResults,msg" status="status"></apex:commandButton></span>                     
                </apex:outputPanel>
                <apex:outputPanel id="msg">
                    <apex:Pagemessages rendered="{!showmsg}"/>
                </apex:outputPanel>
                <apex:outputPanel id="pnlSearchResults" layout="block">
                    <apex:pageBlock id="searchResults">
                        <apex:pageBlockTable value="{!results}" var="a" id="tblResults">
                            <apex:column >
                                <apex:facet name="header">
                                    <apex:outputPanel >Selectone</apex:outputPanel>
                                </apex:facet>
                                <apex:outputlink value="/{!$CurrentPage.parameters.Id}&{!$CurrentPage.parameters.AccName}">Select and Go Back</apex:outputlink>
                            </apex:column>
                            <apex:column >
                                <apex:facet name="header">
                                    <apex:outputPanel >Name</apex:outputPanel>
                                </apex:facet>
                                <apex:outputText >{!a.Name}</apex:outputText>  
                            </apex:column>
                            <apex:column >
                                <apex:facet name="header">
                                    <apex:outputPanel >Industry</apex:outputPanel>
                                </apex:facet>
                                <apex:outputText >{!a.Industry}</apex:outputText>     
                            </apex:column>
                            <apex:column >
                                <apex:facet name="header">
                                    <apex:outputPanel >Type</apex:outputPanel>
                                </apex:facet>
                                <apex:outputText >{!a.Type}</apex:outputText>     
                            </apex:column>
                            <apex:column >
                                <apex:facet name="header">
                                    <apex:outputPanel >Phone</apex:outputPanel>
                                </apex:facet>
                                <apex:outputText >{!a.phone}</apex:outputText>     
                            </apex:column>                            
                        </apex:pageBlockTable>
                    </apex:pageBlock>                            
                </apex:outputPanel>
            </apex:actionRegion>
        </apex:outputPanel>
    </apex:form>
</apex:page>

CustomLink is formula field :
HYPERLINK("apex/vfpage4?Id="&Id,"search","_self")
Account Page

When I click on above search of Customlink field, I'll have a vfpage in same tab as below screen shotsearch

So, in search page when I click on "Search and Go Back", I should be redirected to Account page and "Acc Name" field should be populated with the name of account I had selected in search screen. Acc Name is custom field created just to hold account name for testing purpose.

In the above highlighted vfpage outputlink I have to include something to navigate back , please direct that point.

Thanks for your valuable time.