You need to sign in to do that
Don't have an account?
Error: Initial term field expression must concrete SObject: LIST:SOBJECT:Prescription__c line 38
// WHEN NEW PATIENT IS ADDED OR UPDATED, TRIGGER CREATES A PATIENT__SHARE IF AN ASSOCIATED PORTAL
// USER EXISTS. IF NOT, PATIENT SHOULD BE ADDED WITHOUT SHARING OR ERROR.
trigger PhyPortalPatientApexSharing on Patient__c (after insert, after update)
{
// CREATE A NEW LIST OF SHARING OBJECTS FOR PATIENT.
List<Patient__Share> patientShrs = new List<Patient__Share>();
//Map<ID,Patient__c> posIdToPatientMap = new Map<ID,Patient__c>(); // Map of PositionId-->Patient__c record
// DECLARE VARIABLES FOR PATIENT SHARING.
Patient__Share physicianShr;
Patient__Share patientShr;
for(Patient__c p : Trigger.new)
{
// FOR ASSOCIATD REFERRALS FIND ASSOCIATED PORTAL USER.
for(List<Prescription__c> prescriptions : [Select id,Patient_MRN__c,r.Physician_Contact__r.Portal_User_ID__c,Patient_MRN__r.id From Prescription__c r where r.Physician_Contact__r.Portal_User_ID__c!=null])
{
if(prescriptions.Prescription__c != null)
{
for(List<Patient__c> Patients : [Select id, name From Patient__c Where name=:prescriptions.Patient_MRN__c])
{
// loop thru the list of interviewers and create sharing records
for(Patient__c p1 : Patients)
{
// INSTANTIATE THE SHARING OBJECTS.
physicianShr = new Patient__Share();
// SET THE ID OF THE RECORD BEING SHARED.
physicianShr.ParentId = p1.id;
// GET THE ID OF THE RELATED USER BEING GRANTED ACCESS. THERE MAY BE MORE THAN 1
// PHYSICIAN PORTAL USER TO SHARE TO.
//Prescription__c pe = [Select Physician_Contact__r.Portal_User_ID__c From Prescription__c Where Id=:prescriptions.Id];
// SET THE ID OF THE USER BEING GRANTED ACCESS.
physicianShr.UserOrGroupId = prescriptions.Physician_Contact__r.Portal_User_ID__c ;
// SET THE ACCESS LEVEL.
physicianShr.AccessLevel = 'read';
// SET THE APEX SHARING REASON FOR PHYSICIAN.
physicianShr.RowCause = Schema.Patient__Share.RowCause.Physician_Portal_User__c;
// ADD OBJECTS TO LIST FOR INSERT.
patientShrs.add(physicianShr);
}//end of for loop
}//end of for loop
}//end of for loop
}//edn if loop
}
Field is not on the list. It's on a particular element of the list.
something like
listx.get(0).field__c
Your code has a superfulous for loop - This:
for(List<Patient__c> Patients : [Select id, name From Patient__c Where name= rescriptions.Patient_MRN__c])
{
// loop thru the list of interviewers and create sharing records
for(Patient__c p1 : Patients)
{
Could just be this:
for(Patient__c p : [Select id, name From Patient__c Where name= rescriptions.Patient_MRN__c])
{
Also, I'm not sure why this:
for(List<Prescription__c> prescriptions : [Select id,Patient_MRN__c,r.Physician_Contact__r.Portal_User_ID__c,Patient_MRN__r.id From Prescription__c r where r.Physician_Contact__r.Portal_User_ID__c!=null])
Isn't just this:
for(Prescription__c prescription : [Select id,Patient_MRN__c,r.Physician_Contact__r.Portal_User_ID__c,Patient_MRN__r.id From Prescription__c r where r.Physician_Contact__r.Portal_User_ID__c!=null])
Study its sample code and compare it to your own.
// WHEN NEW PATIENT IS ADDED OR UPDATED, TRIGGER CREATES A PATIENT__SHARE IF AN ASSOCIATED PORTAL // USER EXISTS. IF NOT, PATIENT SHOULD BE ADDED WITHOUT SHARING OR ERROR. trigger PhyPortalPatientApexSharing on Patient__c (after insert, after update) { // CREATE A NEW LIST OF SHARING OBJECTS FOR PATIENT. List patientShrs = new List(); // DECLARE VARIABLES FOR PATIENT SHARING. Patient__Share physicianShr; Patient__Share patientShr; for(Patient__c p : Trigger.new) { // for associated prescription associated protal user. for(List prescriptions : [Select id,Patient_MRN__c,r.Physician_Contact__r.Portal_User_ID__c From Prescription__c r where r.Physician_Contact__r.Portal_User_ID__c!=null]) { if(prescriptions.Prescription__c != null) { // select the id of patient that needs to be shared with the user whcih is attched with prescription Patient__c Patient = [Select id, name From Patient__c Where name=:prescriptions.Patient_MRN__c]; // INSTANTIATE THE SHARING OBJECTS. physicianShr = new Patient__Share(); // SET THE ID OF THE RECORD BEING SHARED. physicianShr.ParentId = Patient.id; // GET THE ID OF THE RELATED USER BEING GRANTED ACCESS. THERE MAY BE MORE THAN 1 // PHYSICIAN PORTAL USER TO SHARE TO. //Prescription__c pe = [Select Physician_Contact__r.Portal_User_ID__c From Prescription__c Where Id=:prescriptions.Id]; // SET THE ID OF THE USER BEING GRANTED ACCESS. physicianShr.UserOrGroupId = prescriptions.Physician_Contact__r.Portal_User_ID__c ; // SET THE ACCESS LEVEL. physicianShr.AccessLevel = 'read'; // SET THE APEX SHARING REASON FOR PHYSICIAN. physicianShr.RowCause = Schema.Patient__Share.RowCause.Physician_Portal_User__c; // ADD OBJECTS TO LIST FOR INSERT. patientShrs.add(physicianShr); }//end of for loop }//edn if loop } // INSERT SHARING RECORDS AND CAPTURE SAVE RESULT. // FALSE PARAMETER ALLOWS FOR PARTIAL PROCESSING OF MULTIPLE RECORDS. Database.SaveResult[] lsr = Database.insert(patientShrs,false); // CREATE COUNTER Integer i=0; // PROCESS SAVE RESULTS for(Database.SaveResult sr : lsr) { if(!sr.isSuccess()) i++; } }
I have modified my code as below. Stll ia m getting the same error.
Prescription__c object is linked by Patient__c object by by pateint_mrn__C. portaluser are connected to prescription not pateint. So I am trying to implement the trigger like this. You acn suggest me some other way if it can be done.
// WHEN NEW PATIENT IS ADDED OR UPDATED, TRIGGER CREATES A PATIENT__SHARE IF AN ASSOCIATED PORTAL // USER EXISTS. IF NOT, PATIENT SHOULD BE ADDED WITHOUT SHARING OR ERROR.
trigger PhyPortalPatientApexSharing on Patient__c (after insert, after update)
{
// CREATE A NEW LIST OF SHARING OBJECTS FOR PATIENT.
List patientShrs = new List(); // DECLARE VARIABLES FOR PATIENT SHARING.
Patient__Share physicianShr;
Patient__Share patientShr;
for(Patient__c p : Trigger.new)
{
// for associated prescription associated protal user.
for(List prescriptions : [Select id,Patient_MRN__c,r.Physician_Contact__r.Portal_User_ID__c From Prescription__c r where r.Physician_Contact__r.Portal_User_ID__c!=null])
{
if(prescriptions.Prescription__c != null)
{
// select the id of patient that needs to be shared with the user whcih is attched with prescription
Patient__c Patient = [Select id, name From Patient__c Where name=rescriptions.Patient_MRN__c];
// INSTANTIATE THE SHARING OBJECTS. physicianShr = new Patient__Share();
// SET THE ID OF THE RECORD BEING SHARED. physicianShr.ParentId = Patient.id;
// GET THE ID OF THE RELATED USER BEING GRANTED ACCESS. THERE MAY BE MORE THAN 1
// PHYSICIAN PORTAL USER TO SHARE TO.
//Prescription__c pe = [Select Physician_Contact__r.Portal_User_ID__c From Prescription__c Where Id=rescriptions.Id];
// SET THE ID OF THE USER BEING GRANTED ACCESS. physicianShr.UserOrGroupId = prescriptions.Physician_Contact__r.Portal_User_ID__c ;
// SET THE ACCESS LEVEL.
physicianShr.AccessLevel = 'read';
// SET THE APEX SHARING REASON FOR PHYSICIAN.
physicianShr.RowCause = Schema.Patient__Share.RowCause.Physician_Portal_User__c;
// ADD OBJECTS TO LIST FOR INSERT.
patientShrs.add(physicianShr);
}//end of for loop }
//edn if loop }
// INSERT SHARING RECORDS AND CAPTURE SAVE RESULT.
// FALSE PARAMETER ALLOWS FOR PARTIAL PROCESSING OF MULTIPLE RECORDS.
Database.SaveResult[] lsr = Database.insert(patientShrs,false);
// CREATE COUNTER Integer i=0;
// PROCESS SAVE RESULTS
for(Database.SaveResult sr : lsr) { if(!sr.isSuccess()) i++; } }
Thanks for all these replies
I have modified my code as below. Stll ia m getting the same error. Prescription__c object is linked by Patient__c object by by pateint_mrn__C. portaluser are connected to prescription not pateint. So I am trying to implement the trigger like this. You acn suggest me some other way if it can be done. Solution? 08-05-2009 01:12 PM