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
sriram anilsriram anil 

How to handle Compile Error: Invalid field Doctor__c for SObject Patient__c

This my apexclass:
------------------------------
Public class CreateMultiplePatients{
ID DoctorID;

public Doctor__c docObj{get;set;}
public List<Patient__c> multiplePatients{get;set;}

public CreateMultiplePatients(ApexPages.StandardController varName){
multiplePatients = New List<Patient__c>();
DoctorID = apexpages.currentpage().getparameters().get('id');
 docObj = [SELECT id,name,Address__c,daysworking__c,Salary__c,Joining_Year__c,specialization__c FROM Doctor__c where id=:DoctorID];
       
        Patient__c newpatient = New Patient__c();
        multiplePatients.add(newpatient);


}
public void addRow(){
         Patient__c newpatient = New Patient__c();
         multiplePatients.add(newpatient);
    }
 public void saveMultiplepatients(){
        for(integer i=0;i<multiplePatients.size();i++){
           / multiplePatients[i].Doctor__c =DoctorID;
        }
        insert multiplePatients;
        
        
}
}
Best Answer chosen by sriram anil
Krishna SambarajuKrishna Sambaraju
Check the Api name of the Doctor field on Patient object. This may be different than what you are using in this class.

All Answers

Vinay Chaturvedi_SFDCVinay Chaturvedi_SFDC

Hi Anil,
This error is due to below code:
multiplePatients[i].Doctor__c =DoctorID;

It seems that you are uopdating field Doctor__c which is not available 

Krishna SambarajuKrishna Sambaraju
Check the Api name of the Doctor field on Patient object. This may be different than what you are using in this class.
This was selected as the best answer
sriram anilsriram anil
API name is carrect 

this program used to
i am creating button in doctor obj---Vf page button link
doctor is parent
patient is child
the doctor obj by using button create multiple patients 


 
sriram anilsriram anil
i got result , thank u for the information
Krishna SambarajuKrishna Sambaraju
Can you share the VF page and the field names on patient object?