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
Deepika Gupta 26Deepika Gupta 26 

Not able to go back to the current account id by creating a link

Hi All,
I have a requirement that i am navigating from a link on VF page to another VF page now i want to create a link to go that partcular account from where i drilldown means on that particular account.Could any one suggest please how to do that?
sslodhi87sslodhi87
Hi Deepika,

You need to sent the return url from first page link and you can use this return url to come back to perviuos record or from  where you drilldown

Please let me know if this works or paste you code here so that I can suggest how you can achieve

Thanks,
Deepika Gupta 26Deepika Gupta 26
This is my first page from where i am navigating to a diffrenr page :
<apex:page standardController="Account" sidebar="true" tabStyle="Account" showHeader="true" extensions="WithContactButtonController">
<apex:form >

<apex:commandLink action="{!doSomething}" target="_top" value="Show_Hierarchy" id="theButton"/>

<c:HierarchyTree currId="{!Account.id}" />
<apex:messages layout="table" styleClass="exceptionText"/>


</apex:form>

</apex:page>

This is a second page where i want a back link and navigating to a third page link :
 
<apex:page standardController="Account" sidebar="true" tabStyle="Account" showHeader="true" extensions="WithContactButtonController">
<apex:form >



<c:HierarchyTree currId="{!Account.id}" />
<input type="button" value="Back to Account" onclick="window.history.back()" /> <b><apex:commandLink action="{!doSomething1}" target="_top" value="IncludeContact" id="theButton"/></b>


</apex:form>

</apex:page>

As you can see i have given a back button that is working for one level but now i have a third page too from where i also want to go on first page means on same account from where i have drill down
<apex:page standardController="Account" showHeader="true" sideBar="true" extensions="WithContactButtonController">
<apex:form >
<c:HierarchyTree_Clone currId="{!Account.id}" />
<b><apex:commandLink action="{!doSomething}" target="_top" value="ExcludeContact" id="theButton"/></b>
</apex:form>
</apex:page>

I want Back to account link on second and third page that should navigate me on my first page on same account id.please suggest.
sslodhi87sslodhi87
URL for opening the second page will be '/apex/demo1?id={!childAccountId}&retURL=/apex/demo?id={!parentAccountId}'

Now in second page controller you need to get the retURL and this return url you can use to go back to the first page or home page and append return url in third page as well and you can do same in thrid page controller

Please let me know if this works for you.

thanks
Deepika Gupta 26Deepika Gupta 26
Could you please suggest how to do that i mean i am not sure how can i apply this in my code.
sslodhi87sslodhi87
Please share your contoller code in same pattern.
Deepika Gupta 26Deepika Gupta 26
This is a controller code from where i am rendering this pages :
 
public with sharing class WithContactButtonController
{
    private ApexPages.StandardController standardController;

    public WithContactButtonController(ApexPages.StandardController standardController)
    {
        this.standardController = standardController;
         System.debug('HelloDeepika');
    }
     public PageReference doSomething()
     {
        // Apex code for handling record from a Detail page goes here
        //Id recordId = standardController.getId();
        PageReference pageRef = new PageReference('/apex/HierarchyPage1');

         System.debug('HelloDeepika1');
        return pageRef ;
       
    }
     public PageReference doSomething1()
     {
        // Apex code for handling record from a Detail page goes here
        //Id recordId = standardController.getId();
        PageReference pageRef1 = new PageReference('/apex/Hierarchy_Clone');

         System.debug('HelloDeepika1');
        return pageRef1 ;
       
    }


   }

 
sslodhi87sslodhi87

Hi Deepika,

I have create one new method(backToAccount) that you need to call from you page to go back to first page by assuming HierarchyPage is your first page
Also, done some small changes in all methos.

 

public with sharing class WithContactButtonController
{
	private ApexPages.StandardController standardController;
	private String retURL;
	public WithContactButtonController(ApexPages.StandardController standardController)
	{
		this.standardController = standardController;
		retURL = apexpages.currentpage().getparameters().get('retURL');
	}
	public PageReference doSomething()
	{
		// Apex code for handling record from a Detail page goes here
		//Id recordId = standardController.getId();
		PageReference pageRef = new PageReference('/apex/HierarchyPage1?retURL=/apex/HierarchyPage?Id='+standardController.getId());
		System.debug('HelloDeepika1');
		return pageRef ;
	}
	public PageReference doSomething1()
	{
		// Apex code for handling record from a Detail page goes here
		//Id recordId = standardController.getId();
		PageReference pageRef1 = new PageReference('/apex/Hierarchy_Clone?retURL='+retURL);
		System.debug('HelloDeepika1');
		return pageRef1;

	}
	public PageReference backToAccount()
	{
		return new PageReference(retURL);;
	}
}
 

Please check if this works for you..

Thanks,

Deepika Gupta 26Deepika Gupta 26
Thanks sslodhi87 for the replay.but its not working i have converted my controller class with this one and added commandlink in my HierarchyPage1 like this
<apex:page standardController="Account" tabStyle="Account" extensions="WithContactButtonController">
<apex:form >



<c:HierarchyTree currId="{!Account.id}" />
 <b><apex:commandLink action="{!backToAccount}" target="_top" value="BacktoAccount" id="theButton1"/></b>

<b><apex:commandLink action="{!doSomething1}" target="_top" value="IncludeContact" id="theButton"/></b>


</apex:form>

</apex:page>

But its howing me the error on clicking on the BacktoAccount link is :
User-added image
sslodhi87sslodhi87
Can you please share the url of the page while you are getting this error
Deepika Gupta 26Deepika Gupta 26
EnviornmentName/visual.force.com/apex/HierarchyPage1
sslodhi87sslodhi87

In page url return url is not appending that is the reason it is throwing the exception.

However, please check why return url is not coming.. also please try with button instead of command link.

 

public with sharing class WithContactButtonController
{
	private ApexPages.StandardController standardController;
	private String retURL;
	public WithContactButtonController(ApexPages.StandardController standardController)
	{
		this.standardController = standardController;
		retURL = apexpages.currentpage().getparameters().get('retURL');
	}
	public PageReference doSomething()
	{
		// Apex code for handling record from a Detail page goes here
		//Id recordId = standardController.getId();
		PageReference pageRef = new PageReference('/apex/HierarchyPage1?retURL=/apex/HierarchyPage?Id='+standardController.getId());
		System.debug('HelloDeepika1');
		return pageRef ;
	}
	public PageReference doSomething1()
	{
		// Apex code for handling record from a Detail page goes here
		//Id recordId = standardController.getId();
		PageReference pageRef1 = new PageReference('/apex/Hierarchy_Clone?retURL='+retURL);
		System.debug('HelloDeepika1');
		return pageRef1;

	}
	public PageReference backToAccount()
	{
		return String.isEmpty(retURL) ? null : new PageReference(retURL);;
	}
}
Deepika Gupta 26Deepika Gupta 26
Is this because of component? should i need to change anything in my component too?