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
Joanne ButterfieldJoanne Butterfield 

Inline Visualforce Page with Standard Case Page Layouts

Hi All,
I'm trying to create an Inline Visualforce Page on my standard case page layout.
I'm not very familiar with VF. I have a button in an opportunity which creates a case related to the opportunity. I would like to view the opportunity products in the case.
I'm needing some assistant with the VF page, I tried the below however wasn’t successful. Any help would be much appreciated.
Thank you in advance!

<apex:page standardController="Case" >
    <apex:relatedList ="OpportunityLineItems"/>
</apex:page>
KevinPKevinP
In order to inline a vf page on std object layout you must not only have it use the standardController for the object you wish the inline vf page to be on, but you must create a controller extension controller and provide your logic for gathering the data you wish to display there. 

In this case your controller will need to look something like this: 

Public With Sharing Class crossObjectOpportunityInfo {
	Public Opportunity o 				{get; private set;}
	Public Case 			 c				{get; private set;}

	Public List<Schema.FieldSetMember> getFields() {
		// create a fieldset on Opportunity LIne items for the data you want to display called: Display_On_Case
		return SObjectType.OpportunityLineItem.FieldSets.Display_On_Case.getFields();
	}

	Public crossObjectContactInfo(ApexPages.StandardController sc) {
		// I don't know your data well enough to understand how opportunity and case are linked but you need a query
		// that will return the opportunity line items for the opportunity referenced by this case.
		this.o = [SELECT Id, AccountId FROM Opportunity WHERE Some_ID_Reference_To_Opportunity = :sc.getId() LIMIT 1];

		String queryString = 'SELECT Id';
		List<Schema.FieldSetMember> querySet = SObjectType.OpportunityLineItem.FieldSets.Display_On_Case.getFields();
		for(Schema.FieldSetMember f : querySet) {
			queryString += ', '+ f.getFieldPath();
		}

		if(o.Npe01__Contact_Id_for_Role__c == null) {
			Id cid = [SELECT Id FROM Contact WHERE AccountId = :o.AccountId LIMIT 1].Id;
			queryString += ' FROM Opportunity WHERE id = \''+ cid +'\' LIMIT 1';
		}	
		
		
		this.contact = database.Query(queryString);
	}

}


Joanne ButterfieldJoanne Butterfield
Kevin, This amazing thank you!
The opportunity and case are linked by a look up field to the opportunity - "Related Opportunity"
Is the opportunity contact and case contact are diffrent will this still work?
Sorry I'm new with apex code and alittle lost.
Thank you again for your help!
Joanne ButterfieldJoanne Butterfield
Hi Kevin,
I'm getting the following error

Error Error: Compile Error: Invalid constructor name: CrossObjectContactInfo at line 10 column 8


Public With Sharing Class crossObjectOpportunityInfo {
Public Opportunity o                {get; private set;}
Public Case              c              {get; private set;}
  
Public List<Schema.FieldSetMember> getFields() {

return SObjectType.OpportunityLineitems.FieldSets.Display_On_Case.getFields();
}
 
Public crossObjectContactInfo(ApexPages.StandardController sc) {

this.o = [SELECT Id, AccountId FROM Opportunity WHERE RELATED_OPPORTUNITY__C = :sc.getId() LIMIT 1];

String queryString = 'SELECT Id';
List<Schema.FieldSetMember> querySet = SObjectType.OpportunityLineItem.FieldSets.Display_On_Case.getFields();
for(Schema.FieldSetMember f : querySet) {
queryString += ', '+ f.getFieldPath();
}
 
if(o.Npe01__Contact_Id_for_Role__c == null) {
Id cid = [SELECT Id FROM Contact WHERE AccountId = :o.AccountId LIMIT 1].Id;
queryString += ' FROM Opportunity WHERE id = \''+ cid +'\' LIMIT 1';

          
          
this.contact = database.Query(queryString);
    }
  
  }