+ Start a Discussion
KeithlarsKeithlars 

Landing on correct Tab when using custom list button to add multiple contacts to a custom object

I the post for adding multiple contacts to a custom object from a list button:

 

http://forums.sforce.com/sforce/board/message?board.id=Visualforce&thread.id=8881

 

I am brought to the detail Tab in my custom object after the records are added.  

Since I'm using Tabs for my related list I would like to bring the user to the Tab where we just

added the records.

 

Here is the page for displaying the related list tabs:

 

<apex:page standardController="Account_Plan__c" showHeader="true" tabStyle="Account_Plan__c" >
<apex:tabPanel switchType="client" selectedTab="name2" id="theTabPanel">
<apex:tab label="Details" name="AcctPlanDetails" id="tabdetails">
<apex:detail relatedList="false" relatedListHover="false" title="true"/>
</apex:tab>
<apex:tab label="Account Team" name="accountTeam" id="tabAT">
<apex:relatedList subject="{!Account_Plan__c}" list="R00NR0000000QDpzMAG" />
</apex:tab>
<apex:tab label="Org Contacts" name="orgContacts" id="tabOC">
<apex:relatedList subject="{!Account_Plan__c}" list="R00NR0000000QDpaMAG" />
</apex:tab>
<apex:tab label="Competitive Business" name="competitiveBusiness" id="tabCB">
<apex:relatedList subject="{!Account_Plan__c}" list="R00NR0000000QDp2MAG" />
</apex:tab>
<apex:tab label="New Demand" name="newDemand" id="tabND">
<apex:relatedList subject="{!Account_Plan__c}" list="R00NR0000000QDpGMAW" />
</apex:tab>
<apex:tab label="Strategic Messaging" name="strategicMessaging" id="tabSM">
<apex:relatedList subject="{!Account_Plan__c}" list="R00NR0000000QFn8MAG" />
</apex:tab>
<apex:tab label="Substantiation Plans" name="substantiationPlans" id="tabSP">
<apex:relatedList subject="{!Account_Plan__c}" list="R00NR0000000QFmaMAG" />
</apex:tab>
<apex:tab label="Strategic Goals" name="strategicGoals" id="tabSG">
<apex:relatedList subject="{!Account_Plan__c}" list="R00NR0000000QDxPMAW" />
</apex:tab>
<apex:tab label="Objectives Tactics" name="objectivesTactics" id="tabOT">
<apex:relatedList subject="{!Account_Plan__c}" list="R00NR0000000QFjQMAW" />
</apex:tab>
<apex:tab label="Competitive Analysis" name="competitiveAnalysis" id="tabCA">
<apex:relatedList subject="{!Account_Plan__c}" list="R00NR0000000QDzBMAW" />
</apex:tab>
<apex:tab label="Opp Plans" name="oppPlans" id="tabOP">
<apex:relatedList subject="{!Account_Plan__c}" list="R00NR0000000QS3cMAG" />
</apex:tab>
<apex:tab label="Open Activities" name="openActivities" id="tabOA">
<apex:relatedList subject="{!Account_Plan__c}" list="OpenActivities" />
</apex:tab>
<apex:tab label="Activity History" name="activityHistory" id="tabAH">
<apex:relatedList subject="{!Account_Plan__c}" list="ActivityHistories" />
</apex:tab>
<apex:tab label="Notest and Attachments" name="notesAttachments" id="tabNotes">
<apex:relatedList subject="{!Account_Plan__c}" list="NotesAndAttachments" />
</apex:tab>

</apex:tabPanel>
</apex:page>

 Here is the code that adds the records to the related list on my custom object and then brings me to the detail tab in the try catch block:

 

public class contactSetExt {

List<Contact> contacts;
public contactSetExt(ApexPages.StandardSetController controller) {
contacts = (List<Contact>) controller.getSelected();
}

public Id planId { get; set; }

public List<ApexPages.SelectOption> getPlanOptions() {
List<ApexPages.SelectOption> options = new List<ApexPages.SelectOption>();
options.add(new ApexPages.SelectOption('','--SELECT--'));

for(Account_Plan__c p:[select name from account_plan__c order by name asc]) {
options.add(new ApexPages.SelectOption(p.id, p.name));
}

return options;
}

public PageReference createMembers() {
/* see if there are existing members for this plan */
Set<Id> existingMemberContactIds = new Set<Id>{};

for(Account_Team_Members__c m:[select id, contactid__c from account_team_members__c where account_plan_id__c = :planId and contactid__c in :contacts]) {
existingMemberContactIds.add(m.contactid__c);
}

List<Account_Team_Members__c> newMembers = new List<Account_Team_Members__c>();

for(Contact c:contacts) {
if(!existingMemberContactIds.contains(c.id)) {
newMembers.add(new Account_Team_Members__c(account_plan_id__c = planId, contactid__c = c.id));
}
}

PageReference p;

if(newMembers.size() > 0) {

try {
Database.insert(newMembers);
p = new ApexPages.StandardController(new Account_Plan__c(id = planId)).view();
} catch (System.DMLException e) {
ApexPages.addMessages(e);
}

}


return p;
}

}

 So how would I bring the user to the tab id "tabAT" instead of the detail tab?

 

 

 

 

JeremyKraybillJeremyKraybill

You almost certainly can use the logic described in this thread to cause a click on that tab after the page is loaded.

 

HTH

 

Jeremy Kraybill

Austin, TX

KeithlarsKeithlars
How exactly do I do that is my question?
JeremyKraybillJeremyKraybill

If you take the js code I provided in the thread above, and then replace the test method with something like

 

function test() { document.getElementById('{!$Component.tabAT}').click(); }

You should hopefully get the desired effect. You may need to play with the component reference to get VF to give you the right ID, see this VF guide page for more info.

 

Jeremy Kraybill

Austin, TX