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
Jeannine2017Jeannine2017 

Issue with class and Visualforce page for custom object

I want to  get the id for a record in an object called patient__C and render the patient detail page in a VF page without having to specify each detail field.  I have created the standard controller Patient to get the record id and get the error This gives error: Illegal Assignment List to List:

public with sharing class Patient {
    
        public String patientId{get;set;}
         

         public Patient(){
             String pat = apexpages.currentPage().getParameters().get('Id');
            List<patient> patID  = [Select id from Patient__c where id = :pat Limit 10];
 }
}

Here is the visualforce page code:
<apex:page standardController="Patient">
    
    <apex:detail />
    
</apex:page>

Can anyone tell me what I am doing wrong?
 
Best Answer chosen by Jeannine2017
Shashikant SharmaShashikant Sharma
Hi Jaennine,

Please try to change your code like this i have developed it for Contact :
public with sharing class ContactDetailController {
    
    
    public String contactId{get;set;}
    public ContactDetailController(ApexPages.StandardController controller) {
        String pat = apexpages.currentPage().getParameters().get('Id');
        List<Contact> patID  = [Select id from Contact where id = :pat Limit 10];
        contactId = patID.get(0).Id;
    }
}
<apex:page standardController="Contact" extensions="ContactDetailController">
    
    <apex:detail subject="{!contactId}"/>
    
</apex:page>

Mistakes in your code:

1. You are not using API name of the object in ​standardController="Patient" it should be Patient__c
2. You did not provide Subject on visualforce page
3. You did not use extensions="Name of your class"  so it should be extensions="Patient"


So your code should be like:
public with sharing class Patient {
    
        public String patientId{get;set;}
      

         public Patient(ApexPages.StandardController controller){
             String pat = apexpages.currentPage().getParameters().get('Id');
            List<patient> patID  = [Select id from Patient__c where id = :pat Limit 10];
            patientId = patID.get(0).Id; 
 }
}
<apex:page standardController="Patient__" extensions="Patient">
    
    <apex:detail subject="{!contactId}"/>
    
</apex:page>
In order to test you could open the page with any record id.

Let me know if you still face issue.

Thanks
Shashikant


 

All Answers

Shashikant SharmaShashikant Sharma
Hi Jaennine,

Please try to change your code like this i have developed it for Contact :
public with sharing class ContactDetailController {
    
    
    public String contactId{get;set;}
    public ContactDetailController(ApexPages.StandardController controller) {
        String pat = apexpages.currentPage().getParameters().get('Id');
        List<Contact> patID  = [Select id from Contact where id = :pat Limit 10];
        contactId = patID.get(0).Id;
    }
}
<apex:page standardController="Contact" extensions="ContactDetailController">
    
    <apex:detail subject="{!contactId}"/>
    
</apex:page>

Mistakes in your code:

1. You are not using API name of the object in ​standardController="Patient" it should be Patient__c
2. You did not provide Subject on visualforce page
3. You did not use extensions="Name of your class"  so it should be extensions="Patient"


So your code should be like:
public with sharing class Patient {
    
        public String patientId{get;set;}
      

         public Patient(ApexPages.StandardController controller){
             String pat = apexpages.currentPage().getParameters().get('Id');
            List<patient> patID  = [Select id from Patient__c where id = :pat Limit 10];
            patientId = patID.get(0).Id; 
 }
}
<apex:page standardController="Patient__" extensions="Patient">
    
    <apex:detail subject="{!contactId}"/>
    
</apex:page>
In order to test you could open the page with any record id.

Let me know if you still face issue.

Thanks
Shashikant


 
This was selected as the best answer
Shashikant SharmaShashikant Sharma
Update your page like this variable name got wrong in last post as it was copied from contact page.
 
<apex:page standardController="Patient__c" extensions="Patient">
    
    <apex:detail subject="{!patientID}"/>
    
</apex:page>

 
Jeannine2017Jeannine2017
Hi Shashikant

I updated my code to the following and am still receiving errors:

User-added image

Any ideas?

Thank you so much for your help!
Shashikant SharmaShashikant Sharma
Change List<Patient>  to  List<Patient__c> at line no 8.

Thanks
Jeannine2017Jeannine2017
That did it!  Thank you ever so much!
Shashikant SharmaShashikant Sharma
Glad that it helped you. Please mark the ticket as solved so it helps others.

Thanks
Shashikant