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
BDArnzBDArnz 

Wrong object referenced in VF page header

Does anyone know why this page references the wrong object?

 

I've created a VF page to replace the default Case Detail page so I can add an extension controller.  We have linked the Asset object to Cases and also the Service object (a custom object) to Cases.

 

When this new detail page loads I expected the header to show the Case icon typically used and the name of the case.  Instead it shows the Service Icon with the name of the service that is attached to the case.  If I remove the Service from the case the header shows the asset instead.  It's very confusing for the user.  (I can't figure out how to post a screen capture in here...)

 

Here's the code for the page which clearly references the Case standard controller AND uses the tabStyle Case.

 

<apex:page standardcontroller="Case" extensions="CaseExtension" tabStyle="Case">
<!-- https://na6.salesforce.com/apex/case_escalation?id=50080000006nANlAAM -->
	<style>
		.activeTab {background-color: #236FBD; color:white;
			background-image:none}
		.inactiveTab {background-color: lightgrey; color:black;
			background-image:none} 
	</style>
	<apex:form >
	<apex:pageblock Title="Hello {!$User.FirstName} {!$User.LastName}" id="TitleBlock">
	<table border="3">
		<tr>
			<td colspan="2"><h1>Version 1.0</h1><br />
			<font color="blue">1.0 Initial Release</font><br />
			This is a new Case Detail Screen showing details about the associated service and asset.<br />
			It will also be the launching point for escalating cases.<br />
			<br />
			Please provide feedback regarding this page to:
			<apex:outputLInk value="mailto:barnold@nordson.com">  Brett Arnold</apex:outputLInk><br /><br />
			</td>
			<td rowspan="3">Instructions:<br />
			To be added.<br />
			</td>
			<td rowspan="3"><apex:image url="{!$Resource.ServiceMAN}" height="150" width="150" /></td>
		</tr>
		<tr>
			<td>Message:</td>
			<td>
			<apex:outputtext value="{!strMessage}"/>
			</td>
		</tr>
		<tr>
			<td>
			NoSolution/thisCase.IsClosed
			</td>
			<td>
			<apex:outputtext value="{!NoSolution}/{!thisCase.IsClosed}"/>
			</td>
		</tr>
		
	</table>			
	</apex:pageblock>
	</apex:form>
	
	<apex:tabPanel switchType="client" selectedTab="TestStepsTab"
			id="CaseTabPanel" tabClass="activeTab"
			inactiveTabClass="inactiveTab">
		<apex:tab label="Case Details" name="CaseDetailTab" id="tabCaseDetails">
			<apex:detail subject="{!thisCase.Id}" relatedList="false" title="true" id="CaseDetail" inlineEdit="true"/>
			<h3><apex:outputText value="{!NoSolution}"/></h3>
			<apex:relatedList subject="{!thisCase}" list="CaseSolutions" />
		</apex:tab>	
		<apex:tab label="Test Steps" name="TestStepsTab" id="tabTestSteps">
			<apex:pageBlock >
				<apex:pageBlockTable value="{!TestSteps}" var="Steps" id="StepsTaken">
					<apex:column HeaderValue="Contributor" value="{!Steps.CreatedBy.Name}"/>
					<apex:column HeaderValue="Contributed When" Value="{!Steps.CreatedDate}"/>
					<apex:column HeaderValue="Suggested Step" value="{!Steps.Step__c}" />
					<apex:column HeaderValue="Suggested When" value="{!Steps.Presented_When__c}"/>
					<apex:column HeaderValue="Result Reported" value="{!Steps.Result__c}"/>
					<apex:column HeaderValue="Reported When" value="{!Steps.Result_Returned_When__c}"/>
				</apex:pageBlockTable>
			</apex:pageBlock> 
		</apex:tab>
		<apex:tab label="Asset" name="AssetDetailTab" id="tabAssetDetails">
			{!NoAssetAttached}
			<apex:detail subject="{!thisCase.AssetId}" relatedList="false" title="true" inlineEdit="true" />
		</apex:tab>		
		<apex:tab label="Service" name="ServiceDetailTab" id="tabServiceDetails">
			{!NoServiceAttached}
			<apex:detail subject="{!thisCase.Service__c}" relatedList="false" title="true" inlineEdit="true"/>
		</apex:tab>		
	</apex:tabPanel>
	
	
	

</apex:page>

 

Here's the case extension markup:

 

public with sharing class CaseExtension {
	Public Case thisCase {get;set;}
	Private String strMessage{get;set;}
	Public String NoAssetAttached{get;set;}
	Public String NoServiceAttached{get;set;}
	Public String NoSolution {get;set;}
	List<Testing_Steps__c> TestSteps {get;set;}
	
	Public CaseExtension(ApexPages.StandardController stdController) {
		thisCase = (Case)stdController.getRecord();
		thisCase = [Select 
			id,
			AssetId,
			Asset.Name,
			Asset.SerialNumber,
			Service__c,
			Service__r.Classification__c,
			Subject,
			IsClosed
			from Case
			Where Id = :thisCase.Id
			];
		
		if (thisCase.AssetId == Null){
			NoAssetAttached = 'No Asset has been attached to this case.';
		} else {
			NoAssetAttached = '';
		}
		
		if (thisCase.Service__c == null){
			NoServiceAttached = 'This case is not attached to a service record.';
		} else {
			NoServiceAttached = '';
		}
	
		if (thisCase.IsClosed == False){
			NoSolution = 'Case is still open.  No Solutions to display' ;
		} else {
			NoSolution = '';	
		}
	}
	
	Public String getstrMessage(){
		return 'No Messages';
	}
	
	Public List<Testing_Steps__c> getTestSteps(){
		TestSteps = [Select id,
			CreatedById,
			CreatedBy.Name,
			CreatedDate,
			Step__c,
			Presented_When__c,
			Result__c,
			Result_Returned_When__c
			from Testing_Steps__c
			where Case__c = :thisCase.Id
			];
			
		return TestSteps;
	}
	
	Static testMethod void testCaseExtensionController(){
	    //create test data
	    
	    Account testAccount = new Account();
        testAccount.Name = 'ACME Missles Inc.';
        testAccount.ShippingStreet = '1313 Mockingbird Lane';
        testAccount.ShippingCity = 'Somecity';
        testAccount.ShippingState = 'CA';
        testAccount.ShippingPostalCode = '94105';
        testAccount.ShippingCountry = 'USA';
        testAccount.Site = 'Somecity';
        insert testAccount; 
	    
	    Contact testContact = new Contact();
        testContact.FirstName = 'Joe';
        testContact.LastName = 'Smuckatelli';
        testContact.AccountId = testAccount.Id;
        insert testContact;
         
        Asset testAsset = new Asset();
        testAsset.AccountId=testAccount.Id;
        testAsset.ContactId = testContact.Id;
        testAsset.Name = 'S-910 Test Asset';
        testAsset.SerialNumber = 'S12345';
        testAsset.Quote__c = 'Quote # ABCDEF';
        testAsset.Sales_Order__c = '987654';
        testAsset.Status = 'Not Shipped';
        insert testAsset;
         
        Case testCase = new Case();
        testCase.AccountId = testAccount.Id;
        testCase.ContactId = testContact.Id;
        testCase.AssetId = testAsset.Id;
        insert testCase;
         
        Service__c testService = new Service__c();
        testService.Account__c = testAccount.Id;
        insert testService;
         
		//Solution testSolution = new Solution(SolutionName = 'Test Solution', Status = 'New');
		//insert testSolution;

		ApexPages.StandardController c = new ApexPages.StandardController(testCase);
		CaseExtension testCon = new CaseExtension(c);
		ApexPages.CurrentPage().getParameters().put('id',testCase.Id);
		System.AssertEquals('No Messages',testCon.getstrMessage());
		
		List<Testing_Steps__c> testTestSteps = testCon.getTestSteps();

		testCase.Service__c = testService.Id;
		testCase.Status = 'Closed';
		update testCase;
		
		
		CaseExtension testCon2 = new CaseExtension(c);
		
	
	}
}

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Yeah I tried the rendered trick but no joy.  However, if you don't mind a bit of page bloat you can add the following:

 

<div style="display:none">
  <apex:detail subject="{!thisCase.Id}" relatedList="false" title="true" id="CaseDetailDupe"/>
</div>

 This puts the detail into the page, which triggers the heading switch, but doesn't show it to the user.

All Answers

bob_buzzardbob_buzzard

I've had a bit of a play around with this, and it appears to be a side effect of using the apex:detail component.  I've dwindled this down to a page with a standard controller for contact, using the contact tabstyle and with the apex:detail of an account where the id comes from the URL.  The icon and title are for the account in question rather than contact.

 

If I add an apex:detail for the contact before the account, I see the same behaviour as above. If I add it after, the icon and title switches to contact.  

 

Adding the title="false" attribute to the apex:detail stopped this side effect for me - give that a shot and see how you get on,  i.e.

 

<apex:tab label="Asset" name="AssetDetailTab" id="tabAssetDetails">
			{!NoAssetAttached}
			<apex:detail subject="{!thisCase.AssetId}" relatedList="false" title="false" inlineEdit="true" />
		</apex:tab>		
		<apex:tab label="Service" name="ServiceDetailTab" id="tabServiceDetails">
			{!NoServiceAttached}
			<apex:detail subject="{!thisCase.Service__c}" relatedList="false" title="false" inlineEdit="true"/>
		</apex:tab>	

 

 

 

BDArnzBDArnz

Thanks for looking into this.  The title="false" attribute did not help in my case.  I added it to all the tabs.  It seems that whichever detail page is rendered last in the tab list is the one that drives the icon selection.  I moved the case detail to the end and the page rendered properly.  But since I want the case detail first I moved it back and duplicated it at the end.  For the last one I added the attribute rendered="false" in hopes of tricking it but alas, no joy.  It still used the icon from the last detail page rendered....

bob_buzzardbob_buzzard

Yeah I tried the rendered trick but no joy.  However, if you don't mind a bit of page bloat you can add the following:

 

<div style="display:none">
  <apex:detail subject="{!thisCase.Id}" relatedList="false" title="true" id="CaseDetailDupe"/>
</div>

 This puts the detail into the page, which triggers the heading switch, but doesn't show it to the user.

This was selected as the best answer
BDArnzBDArnz

That did the trick!  Thanks for your help.

 

That's a small amount of page bloat to get this going.  Sometimes a work around is necessary...