Регистрация  |  Вход

Создание новой записи в таблице со связанными полями c помощью контроллера

Добрый день, столкнулся с проблемой, пытаюсь добавить новую запись в таблицу в которой есть связанные поля.

Appointment__c ac = new Appointment__c();
ac.Duration_in_minutes__c = newDuration;
ac.Appointment_Date__c = newDate;
ac.Doctor__r.Name = selectDoctor;

При попытке создать запись высвечивается ошибка Attempt to de-reference a null object.

Картинка с табами и их связями https://drive.google.com/file/d/1ei7_XuUM57M-z0b1Isn7PFjNHVetAJ8q/view?usp=sharing

Всё работает если убрать поле с добавлением имени доктора.

Добрый день, столкнулся с проблемой, пытаюсь добавить новую запись в таблицу в которой есть связанные поля.
[code] Appointment__c ac = new Appointment__c();
        ac.Duration_in_minutes__c = newDuration;
        ac.Appointment_Date__c = newDate;
        ac.Doctor__r.Name = selectDoctor;
[/code]
При попытке создать запись высвечивается ошибка  [b]Attempt to de-reference a null object[/b]. 

Картинка с  табами и их связями https://drive.google.com/file/d/1ei7_XuUM57M-z0b1Isn7PFjNHVetAJ8q/view?usp=sharing

Всё работает если убрать поле с добавлением имени доктора.

Appointment__c ac = new Appointment__c();
ac.Duration_in_minutes__c = newDuration;
ac.Appointment_Date__c = newDate;
ac.Doctor__r = new Doctor__c();
ac.Doctor__r.Name = selectDoctor;

[code]    Appointment__c ac = new Appointment__c();
            ac.Duration_in_minutes__c = newDuration;
            ac.Appointment_Date__c = newDate;
            ac.Doctor__r = new Doctor__c();
            ac.Doctor__r.Name = selectDoctor;[/code]

Всё было так просто.
Я конечно так пытался через insert , но тоже не получалось.

insert new Appointment__c(Duration_in_minutes__c = newDuration, Appointment_Date__c = newDate, Doctor__r = Doctor__c(Name = selectDoctor), Patient__r = new Patient__c(Name = selectPatient));

Спасибо огромное!

Всё было так просто.
Я конечно так пытался через insert , но тоже не получалось.
[code] insert new Appointment__c(Duration_in_minutes__c = newDuration, Appointment_Date__c = newDate, Doctor__r = Doctor__c(Name = selectDoctor), Patient__r = new Patient__c(Name = selectPatient));[/code]

Спасибо огромное!

insert new Appointment__c(
Duration_in_minutes__c = newDuration,
Appointment_Date__c = newDate,
Doctor__r = Doctor__c(Name = selectDoctor),
Patient__r = new Patient__c(Name = selectPatient)
);

должно быть

insert new Appointment__c(
Duration_in_minutes__c = newDuration,
Appointment_Date__c = newDate,
Doctor__r = new Doctor__c(Name = selectDoctor),
Patient__r = new Patient__c(Name = selectPatient)
);

[code]insert new Appointment__c(
  Duration_in_minutes__c = newDuration, 
  Appointment_Date__c = newDate, 
  Doctor__r = Doctor__c(Name = selectDoctor), 
  Patient__r = new Patient__c(Name = selectPatient)
);[/code]

должно быть 

[code]insert new Appointment__c(
  Duration_in_minutes__c = newDuration, 
  Appointment_Date__c = newDate, 
  Doctor__r = [b]new[/b] Doctor__c(Name = selectDoctor), 
  Patient__r = new Patient__c(Name = selectPatient)
);[/code]

и
selectedDoctorName, selectedPatientName
но блин, обычно используют Id. Почему имена?

и
selectedDoctorName, selectedPatientName
но блин, обычно используют Id. Почему имена?