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
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student 

Record creation re-render tabbed VF page

Hey there,

 

I am not even sure this is possible, but I need some advice. Basically, I have a tabbed VF page for my account and all of its related lists and child objects have their own tab. These tabs are lists of all the records associated with that account and should the user click on one of the links, the bottom half of that tab will re-render with the information. Essentially, it is all the information on one page.

 

This all works perfectly, except what i need to do is to make it so that should the user wish to create a new record, upon saving they will be re-directed to the tab of the object they had jsut created the record in. I have searched and searched and searched for a solution, many people have theories on how to do this...maybe some people have even done this (by searching for a reference for each tab or naming each tab in the code), however it is a bit beyond my coding skill.

 

My question is...Would it be possible to have a link which will re-render the bottom half of the tab..into a create new record VF page...which upon saving will once again re-render to the record... What are your thoughts people?

 

Mikie 

Best Answer chosen by Admin (Salesforce Developers) 
Paul.FoxPaul.Fox

1. If you just put FactFinder in the selectedTab parameter of the tabPanel does it start on the FactFinder tab? If not, there's something wrong with that page and you'll need to figure out what is not working. 

2. If that works, then double check that the formula I gave you is working. Just paste it somewhere on the page that's not inside of a paramter and test it. It should display AccountDetail unless you come from your FactFinder submission page.

{!BLANKVALUE($CurrentPage.parameters.tab,'AccountDetail')}

All Answers

Paul.FoxPaul.Fox

First off, be careful because a page with this many forms and DML statements may have issues with limits in the future.

 

However, I don't see why you couldn't do this. You could probably use rerender and rendered values to show and hide the sections without causing a page referesh. However, if you want to figure out how to go to different tabs, just use the selectedtab parameter in the tabpanel.

 

<apex:tabPanel switchType="client" selectedTab="{!selectedTab}" id="theTabPanel">

 Then in your controller, get the selectedtab from the URL

public string getSelectedTab(){
    if(ApexPages.CurrentPage().getParameters().containsKey('tab')){
       return ApexPages.CurrentPage().getParameters().get('tab');
    }else return 'detail';
}

 So when you're saving the records from your form for creating records, you just need to append the tab name to the URL parameters of the pagereference that is returned.

Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student

Hey Paul,

 

Thank you for the quick reply. I have begun writing a record creation page for my custom object 'Fact Finder' and an extension (with alot of help from people on the forums) to add to my Tabbed Accounts VF page. I was wondering if you would be able to give me a little hand on how I may implement the code that you have just posted? This is my Fact Finder, record creation page:

 

<apex:page standardController="Fact_Finder__c" extensions="extSaveButton">
    <apex:form >
        <apex:pageBlock >
            <apex:commandButton value="Save" action="{!SaveFactFinder}"/>
            <apex:pageBlockSection >
                <apex:inputField value="{!Fact_Finder__c.Name}"/>
    
                <apex:inputField value="{!Fact_Finder__c.Account__c}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
    
    </apex:page>

This is my extension, it currently redirects to the TestAccount VF page: 

 

public class extSaveButton {
 
    public Fact_Finder__c fac {get;set;}
    public extSaveButton(ApexPages.StandardController controller) {
        this.fac = (Fact_Finder__C)controller.getRecord();

    }
    
    Public PageReference saveFactFinder(){
    
        insert fac;
        // Send the user to the detail page for the new account.
       PageReference pageRef= new PageReference('/apex/DestinyAccountTest?id='+fac.account__c+'&Sfdc.override=1');
        
        return pageRef;
    
    }

}

 This is the main Accounts tabbed VF page with the Fact Finder section highlighted

<apex:page standardController="Account" extensions="myFactFinderExtension2" showHeader="true" 
tabStyle="account"  >

 <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"/>
    <apex:stylesheet value="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/ui-lightness/jquery-ui.css"/>
    <script>
        $j = jQuery.noConflict();

        function highlightElem(elem){
            $j('tr').removeClass('ui-state-highlight');
            $j(elem).addClass('ui-state-highlight');
        }
</script>




<style>
.activeTab {background-color: #892034; color:White;
background-image:none}
.inactiveTab { background-color: #00204E; color:white;
background-image:none}
</style>
<apex:tabPanel switchType="client" selectedTab="tabdetails"
id="AccountTabPanel" tabClass="activeTab"
inactiveTabClass="inactiveTab">
<apex:tab label="Details" name="AccDetails" id="tabdetails">
<apex:detail inlineEdit="True" relatedList="True" title="true"/>
</apex:tab>
<apex:tab label="Contacts" name="Contacts" id="tabContact">
<apex:pageBlock title="Hello {!$User.FirstName}!">
You are displaying contacts from the {!account.name} account.
Click a contact's name to view his or her details.
</apex:pageBlock>
<apex:pageBlock title="Contacts">
<apex:form >
<apex:dataTable value="{!account.Contacts}" var="contact" cellPadding="4"
border="1">
<apex:column >
<apex:commandLink rerender="detail">
{!contact.Name}
<apex:param name="cid" value="{!contact.id}"/>
</apex:commandLink>
</apex:column>
</apex:dataTable>
</apex:form>
</apex:pageBlock>
<apex:outputPanel id="detail">
<apex:detail subject="{!$CurrentPage.parameters.cid}" relatedList="True" inlineEdit="True"
title="false"/>
</apex:outputPanel>
</apex:tab>


<apex:tab label="Fact Finder" rendered="{!$ObjectType.Fact_Finder__c.Accessible}" name="FactFinder" id="tabFactFinder" >

<apex:pageBlock title="Hello {!$User.FirstName}!">
You are displaying Fact Finders from the {!account.name} account.Click a Fact Finder to view its details.
</apex:pageBlock>
<apex:pageBlock title="Fact Finder" >
<apex:form >
<apex:outputlink value="/c0T/e?CF00N80000007AqBp={!Account.name}&CF00N80000007AqBp_lkid=                                                                                                                           {!Account.id}">Create New Fact Finder</apex:outputlink> 
<apex:pageBlockTable value="{!account.Fact_Finder__r}" var="Fac" cellPadding="4"  border="4"  onRowClick="highlightElem(this)" >
<apex:column headerValue="Fact Finder" >
<apex:commandLink rerender="details"> {!Fac.Name}
<apex:param name="Fid" value="{!Fac.id}"/>
</apex:commandLink>
</apex:column>
<apex:column value="{!Fac.Employed_Since__c}"/>
</apex:pageBlockTable>
</apex:form>
</apex:pageBlock>
<apex:outputPanel id="details">
<apex:detail subject="{!$CurrentPage.parameters.Fid}" relatedList="True" inlineEdit="True" title="false"/>
</apex:outputPanel>
</apex:tab>

 

Any help would be much appreciated. I was also wondering what you mean by issues with limits in the future? Is it possible to avoid these issues if the code is written solidly enough... Basically, the goal is to have people redirected to the open tab after creating a record and the rendered record creation on the page is the dream that I only found out was possible after reading your post just now...But is way in the future. 

 

Please let me know your thoughts.

 

Thankyou for your time

 

Mikie

Paul.FoxPaul.Fox

Update saveFactFinder method

Public PageReference saveFactFinder(){
    
        insert fac;
        // Send the user to the detail page for the new account.
       PageReference pageRef= new PageReference('/apex/DestinyAccountTest?id='+fac.account__c+'&Sfdc.override=1');
        pageRef.getParameters().put('tab','tabFactFinder');
        return pageRef;
    
    }

Then in myfactfinderextension2 which you didn't post, add the method I posted earlier for getting the tab from the parameters. 

 

Then in the visualforce page, use the selectedtab merge field that I also mentioned before.

 

Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student

That is an old extension for something different, it should not still be there..Do I have to just create another extension? I am not too good on this, apart from the method, what else will the extension need? Or is the method you posted earlier enough?

Paul.FoxPaul.Fox

You can try doing this in the selectedtab parameter for your tabpanel component in the visualforce page then:

selectedTab="{!BLANKVALUE($CurrentPage.parameters.tab,'AccountDetail')}"

 I think that's the right formula but I haven't tested it.

Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student

It all saves fine when editing the code, but then it still just redirects to the detail page upon saving the record. I added the method to the old extension and I tried the formula as well. Both of them just redirect to the detail page of the VF tabbed page after saving.

 

If it helps, something weird happened to the URl, normally it would be (VF page name)+accountID+"overide mumbo jumbo".

 

Now it is all that, then "=1&tab=tabFactFinder'.

 

What do you think has gone wrong?

 

Thank you for your help with this Paul, you are a life saver!

 

Mikie

Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student

Could I have maybe put it in wrong?

 

 

Paul.FoxPaul.Fox

Paste your latest controller and tabbed VF code here if you want anyone to check.

Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student

Trying to get it to redirect to the Fact Finder tab. Can anyone see what I have done wrong?

 

This is my extension:

 

public class extSaveButton {
 
    public Fact_Finder__c fac {get;set;}
    public extSaveButton(ApexPages.StandardController controller) {
        this.fac = (Fact_Finder__C)controller.getRecord();

    }
    
    Public PageReference saveFactFinder(){
    
        insert fac;
        // Send the user to the detail page for the new account.
       PageReference pageRef= new PageReference('/apex/DestinyAccountTest?id='+fac.account__c+'&Sfdc.override=1');
        pageRef.getParameters().put('tab','tabFactFinder');
        return pageRef;
    
    }

}

 This is my Fact Finder record creation page:

 

<apex:page standardController="Fact_Finder__c" extensions="extSaveButton">
    <apex:form >
        <apex:pageBlock >
            <apex:commandButton value="Save" action="{!SaveFactFinder}"/>
            <apex:pageBlockSection >
                <apex:inputField value="{!Fact_Finder__c.Name}"/>
    
                <apex:inputField value="{!Fact_Finder__c.Account__c}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
    
    </apex:page>

 and this is my main VF tabbed account page:

 

<apex:page standardController="Account" extensions="myFactFinderExtension2" showHeader="true" 
tabStyle="account"  >
<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"/>
<apex:stylesheet value="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/ui-lightness/jquery-ui.css"/>
<script>
$j = jQuery.noConflict();
function highlightElem(elem){
$j(elem).parent().parent().parent().find('tr').removeClass('ui-state-highlight');
$j(elem).parent().parent().addClass('ui-state-highlight');
}
</script>

<style>
.activeTab {background-color: #892034; color:White;
background-image:none}
.inactiveTab { background-color: #00204E; color:white;
background-image:none}
</style>
<apex:tabPanel switchType="client" selectedTab="{!BLANKVALUE($CurrentPage.parameters.tab,'AccountDetail')}"
id="AccountTabPanel" tabClass="activeTab"
inactiveTabClass="inactiveTab">
<apex:tab label="Details" name="AccDetails" id="tabdetails" >
<apex:detail inlineEdit="True" relatedList="false" title="true"/>
</apex:tab>
<apex:tab label="Contacts" name="Contacts" id="tabContact">
<apex:pageBlock title="Hello {!$User.FirstName}!">
You are displaying contacts from the {!account.name} account.
Click a contact's name to view his or her details.
</apex:pageBlock>
<apex:pageBlock title="Contacts">
<apex:form >
<apex:dataTable value="{!account.Contacts}" var="contact" cellPadding="4"
border="1">
<apex:column >
<apex:commandLink rerender="detail" oncomplete="highlightElem(this);">
{!contact.Name}
<apex:param name="cid" value="{!contact.id}"/>
</apex:commandLink>
</apex:column>
</apex:dataTable>
</apex:form>
</apex:pageBlock>
<apex:outputPanel id="detail">
<apex:detail subject="{!$CurrentPage.parameters.cid}" relatedList="True" inlineEdit="True"
title="false"/>
</apex:outputPanel>
</apex:tab>

<apex:tab label="Fact Finder" rendered="{!$ObjectType.Fact_Finder__c.Accessible}" name="FactFinder" id="tabFactFinder" >
<apex:pageBlock title="Hello {!$User.FirstName}!">
You are displaying Fact Finders from the {!account.name} account.Click a Fact Finder to view its details.
</apex:pageBlock>
<apex:pageBlock title="Fact Finder" >
<apex:form >
<apex:outputlink value="/a7Q/e?CF00N90000006BaAp={!Account.name}&CF00N90000006BaAp_lkid= {!Account.id}">Create New Fact Finder</apex:outputlink>
<apex:pageBlockTable value="{!account.Fact_Finder__r}" var="Fac" cellPadding="4" border="4" >
<apex:column headerValue="Fact Finder" >
<apex:commandLink rerender="details" oncomplete="highlightElem(this);"> {!Fac.Name}
<apex:param name="Fid" value="{!Fac.id}"/>
</apex:commandLink>
</apex:column>
<apex:column value="{!Fac.Employed_Since__c}" />
</apex:pageBlockTable>
</apex:form>
</apex:pageBlock>
<apex:outputPanel id="details">
<apex:detail subject="{!$CurrentPage.parameters.Fid}" relatedList="False" inlineEdit="True" title="false"/>
</apex:outputPanel>
</apex:tab>

 This is my FactFinderExtension2 - Not sure if it is relevent, it is for attempting to upload an account attachment...it is not redirecting properly either..but it may be conflicting or something.

 

public class myFactFinderExtension2
{
private final Account webAccount;
public myFactFinderExtension2(ApexPages.StandardController stdController)
{
webAccount = (Account)stdController.getRecord();
attach = new Attachment();
}


public myFactFinderExtension2(){}
public PageReference saveAccount()
{
PageReference p = Page.FactFinder_Attachment_Notes2;
p.setRedirect(true);
return null;
}
public PageReference save()
{
PageReference p = Page.FactFinder_Attachment_Notes2;
p.setRedirect(true);
update webAccount;
upload();
return null;
}
public String parentId {get;set;}
public Attachment attach {get;set;}
public ApexPages.Pagereference upload()
{
attach.ParentId = webAccount.Id;
insert attach;
return new ApexPages.Standardcontroller(attach).view();
}

}

 Any help or advice would be much appreciated.

Paul.FoxPaul.Fox

Sorry, selectedtab must be the name of the tab, not the id. 

 

So in your controller, change this line:

pageRef.getParameters().put('tab','tabFactFinder');

 To this:

pageRef.getParameters().put('tab','FactFinder');

 

Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
Still no luck....still re-directed to the detals tab. I have no idea what I am missing...
Paul.FoxPaul.Fox

1. If you just put FactFinder in the selectedTab parameter of the tabPanel does it start on the FactFinder tab? If not, there's something wrong with that page and you'll need to figure out what is not working. 

2. If that works, then double check that the formula I gave you is working. Just paste it somewhere on the page that's not inside of a paramter and test it. It should display AccountDetail unless you come from your FactFinder submission page.

{!BLANKVALUE($CurrentPage.parameters.tab,'AccountDetail')}
This was selected as the best answer
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student

Ok, so far so good. I changed the parameter of selectedtab to that of Factfinder and upon opening the account it was opened onto the FactFinder Tab...I am not 100% sure on step two though...paste it somewhere on the page thats not inside of a parameter and test it? Where about should I put the formula...and what should I keep the selectedtab as?

Paul.FoxPaul.Fox

Just put the formula before the tabpanel.

{!BLANKVALUE($CurrentPage.parameters.tab,'AccountDetail')}
<apex:tabPanel switchType="client" selectedTab="{!BLANKVALUE($CurrentPage.parameters.tab,'AccountDetail')}"
id="AccountTabPanel" tabClass="activeTab"
inactiveTabClass="inactiveTab">

 This way you'll see the formula result when you open the page (this is just a temporary debugging step).

 

Now, when you first open the page it should say AccountDetail.

After coming from your form, it should say FactFinder.

 

If it doesn't then there's something wrong with the formula.

Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student

Ok, after opening the accounts page...it says accountdetail....and after creating a fact finder it now says factfinder at the top...which means and correct me if I am wrong..that the formula works perfectly....yet it raises more questions as it is not clear on why it is not working?

Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
After the normal URl...it does say =1&tab=FactFinder....so I feel like it is close
Paul.FoxPaul.Fox
The FactFinder save method is adding it to the URL. Then the formula field is reading it from the URL. That's what $CurrentPage.parameters.tab does. Are there any differences in capitalization? Basically, if typing in FactFinder in the selectedTab works, and the formula works, then putting the formula in the selectedTab field should work. I'm not sure what I'm missing here either.
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
From Fact Finder: https://c.cs6.visual.force.com/apex/DestinyAccountTest?id=001N0000007MJcKIAW&Sfdc.override=1&tab=FactFinder Normal Account opening: https://c.cs6.visual.force.com/apex/DestinyAccountTest?id=001N0000007MJcK&sfdc.override=1 Soo yes.....the end of the account ID.....seeems to weird itself out....there also seems to be a change in capitals fr the sfdc...could this have anything to do with the fact that I am doing all of this in sandbox?
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student

Does the extension have to be on both VF pages or just the record creation page?

Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student

What might the difference in URL mean?

Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student

Hey there..

 

Just come across the solution.. Apparently the selectedTab tag is used only for the default tab....I put your formula in front of a value tag (where the selectedtab was) and it all works and re-directs perfectly. i know the thread went stale at the end but thankyou for all your help. You are a legend.

Paul.FoxPaul.Fox

Thank you, I'm glad you figured it out.

 

So what was the final tabpanel line?

Paul.FoxPaul.Fox
<apex:tabPanel switchType="client" value="{!BLANKVALUE($CurrentPage.parameters.tab,'AccountDetail')}"
selectedTab="AccountDetail" id="AccountTabPanel" tabClass="activeTab" inactiveTabClass="inactiveTab">

 like that?

Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student

Yes, exactly that and it works perfectly. Thankyou for your time and help

TrueOasisTrueOasis
Hi Mikie,

Despite this thread being old can you comment ont this question?  I have the same tabbed page you were working with.  For each related list did you have to override all of the view/edit pages to make the return to tab function work?  Was it not possible to use the native view/edit screens and then redirect back to a tab?  It appears that's the case.

Thanks!
Peter
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
Hi Peter,

I am happy to help. There are two ways you can do this, the method I have kept for about a year about going like this:

Examples:

Tab of a custom object, that is in a child (master -detail relationship with accounts):
<apex:tab label="Services" rendered="{!($ObjectType.Service__c.Accessible)&&(account.Business_Contact_Account__c == False)}" name="Destiny Services" id="tabDestinyServices" > //introduce tab
<apex:pageBlock title="Services" > //open pageblock
<apex:form > //declare start of form
<div align="Left"> //arrange buttons left
<apex:commandbutton value="New Service" rendered="{!$ObjectType.Service__c.createable}" onclick="window.location='/a0I/e?CF00N90000006DlGe_lkid={!Account.id}&CF00N90000009ICg6_lkid={!Account.Office__c}&retUrl={!$CurrentPage.Url}'; return false;"/> //Link to New service__c page, the CF00... = Account and Office__c fields (both parents of service)
</div>
<apex:pageBlockTable value="{!account.Services__r}" var="Ser" cellPadding="4"  border="4" > //start of pageblocktable, using the Account related list tag as the value - Account.Services__r (replace __c with __r)
<!-- Create a column for user to click on delete and delete the record -->

<apex:column headerValue="Service"  >
<apex:commandLink rerender="Serdetails" oncomplete="highlightElem(this);"> {!Ser.Name} //This commandlink will appear as the Name, but hold the vbalue of the ID, allowing you to re-render the ser details below
<apex:param name="Sid" value="{!Ser.id}"/> //Sending Id value
</apex:commandLink>
</apex:column>
<apex:column headervalue="Service Name" value="{!Ser.Service_Name__c}"/> //Other custom fields
<apex:column headervalue="Service Type" value="{!Ser.Service_Type__c}"/>
<apex:column headervalue="Start" value="{!Ser.Start_of_Service__c}"/>
<apex:column headervalue="Stage" value="{!Ser.Service_Stage__c}"/>
<apex:column headervalue="Service Fee" value="{!Ser.Amount_Owed__c}"/>
<apex:column headervalue="Fee Outstanding" value="{!Ser.Amount_remaining__c}"/>
<apex:column headervalue="Office" value="{!Ser.Office__c}"/>
<apex:column headervalue="Active" value="{!Ser.Service_Active__c}"/>

</apex:pageBlockTable>
</apex:form>
</apex:pageBlock>
<apex:outputPanel id="Serdetails"> //Output panel to rerender once you send ID
<apex:detail subject="{!$CurrentPage.parameters.Sid}" relatedList="True" inlineEdit="True" title="false"/> //This will render as the standard detail page of object
</apex:outputPanel>
</apex:tab>

and Class for new service page:
 
public class extSaveSerButton {
 
    public Service__c ser {get;set;}
  
    
    public extSaveSerButton(ApexPages.StandardController controller) {
   
        this.ser = (Service__c)controller.getRecord(); 
        
       

    }
    
    
    
    //Save function
    Public PageReference saveDestinyService(){
    


    if(System.currentPageReference().getParameters().get('clone') == '1'){

        //Set record id to null

        ser.Id = null; 

    }
 
    
    try {     
        upsert ser;
        // Send the user to the detail page for the new account.
       PageReference pageRef= new PageReference('/apex/DestinyAccount?id='+ser.account__c+'&Sfdc.override=1'); //redirect back to account page, using the ser.account__c to set the ACCOUNT ID INTO URL
        pageRef.getParameters().put('tab','Destiny Services'); //redirects and opens page, replace Destiny Services with Tab name
        return pageRef;
        
        } catch (Exception e) {     
      
             ApexPages.addMessages(e);         
        }
        return null;
    
    }
   //Save and new function 
    Public PageReference saveNewDestinyService(){
    
    try {     
        upsert ser;
  
        // Send the user to the detail page for the new account.
       PageReference pageRef= new PageReference('/a0I/e');
        
        return pageRef;
        
        } catch (Exception e) {     
      
             ApexPages.addMessages(e);         
        }
        return null;
    }
    
    
    
    
    Public PageReference cancelDestinyService(){
    PageReference pageRef = new PageReference('/apex/DestinyAccount?id='+ser.account__c+'&Sfdc.override=1');
    pageRef.getParameters().put('tab','Destiny Services');
    return pageRef;
    
    }
    
    

}

If i understood your question correctly, this should get you started. This is a section of my Account Tab page and the controller for the new service page, which will redirect back to the Account tab page.

Let me know if you  need anything
TrueOasisTrueOasis
Thanks for coming back to this old thread Mikie!  Exactly what I needed and it works great!!