I have two custom objects, service_case__c and part__c. I am trying to display parts on the page layout of service_case__c through a visual force page. Though I have no errors in developer console, when hitting preview, I receive the error:
Invalid conversion from runtime type Service_Case__c to Part__c
An unexpected error has occurred. Your development organization has been notified.
Also, another way this question could be asked is: "How do I display another object's data onto a different object?" Here is the code for my controller, PartListCon:
public class PartListCon {
// ApexPages.StandardSetController must be instantiated
// for standard list controllers
private final part__c part;
public PartListCon(ApexPages.StandardSetController controller) {
this.part = (part__c)controller.getRecord();
}
public ApexPages.StandardSetController setCon {
get {
if(setCon == null) {
setCon = new ApexPages.StandardSetController(
Database.getQueryLocator(
[SELECT Name, id from Part__c limit 1]));
}
return setCon;
}
set;
}
// Initialize setCon and return a list of records
public List<part__c> getParts() {
return (List<part__c>) setCon.getRecords();
}
}
And here is my simple VF page:
<apex:page Standardcontroller="Service_Case__c" recordSetVar="Service_case__c" extensions="PartListCon">
<apex:pageBlock >
<apex:pageBlockTable value="{!parts}" var="p">
<apex:column value="{!p.Name}"/>
<apex:column value="{!p.id}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>