I have the following Apex method:
public static void createJourney(Id accountId) {
// Step 1: get account record type
Account accRecTypeName = [SELECT Id, RecordType.DeveloperName FROM Account WHERE Id = :accountId];
if(accRecTypeName.RecordType?.DeveloperName == 'Patient_Account') {
// Step 2: Create a new Patient Journey record
List<Patient_Journey__c> patientJourney = new List<Patient_Journey__c>();
patientJourney.add(
new Patient_Journey__c(
Name = 'Test Patient Journey',
Patient__c = accRecTypeName.Id,
Status__c = 'Active'
)
);
insert patientJourney;
// Get ID of the newly inserted Patient Journey record
for(Patient_Journey__c getPJID : patientJourney) {
patientJourneyID = getPJID.Id; // Line 25
}
// Step 3: Read records from custom metadata type 'Journey Step'
Map<String, Journey_Step__mdt> journeyStepMD = Journey_Step__mdt.getAll();
List<Patient_Journey_Step__c> patientJourneySteps = new List<Patient_Journey_Step__c>();
for (String getJSteps : journeyStepMD.keySet()) {
// Step 4: Create a new Patient Journey Step records based on 'Journey Step'
patientJourneySteps.add(
new Patient_Journey_Step__c(
Step_Name__c = journeyStepMD.get(getJSteps).Step_Name__c,
Order__c = journeyStepMD.get(getJSteps).Order__c,
Journey__c = patientJourneyID // Line 39
)
);
}
}
}
I want to get the Id of the newly created 'Patient_Journey__c' record. I get the following errors when saving the file:
- Line 25: Variable does not exist: patientJourneyID
- Line 39: Variable does not exist: patientJourneyID