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
rakhi78rakhi78 

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
            }

SuperfellSuperfell
prescriptions is declared as a list, so prescriptions.Patient_MRN__c doesn't make any sense, you need to look at a particular item from the list.
rakhi78rakhi78
can you please give me some idea how do I do it then. I am new to salesforce
MakMak

Field is not on the list. It's on a particular element of the list. 

something like

 

listx.get(0).field__c 

rakhi78rakhi78
can you please give me your contact information. I am not able to figure out this by my self. Please help me out. I need to talk to someone. It will not take moretime i am sure.
rakhi78rakhi78
can you please give me your contact information. I am not able to figure out this by my self. Please help me out. I need to talk to someone. It will not take moretime i am sure.
jlojlo

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])

 

The "Using Apex Managed Sharing to Create Custom Sharing Logic" article will be a useful resource for you: http://wiki.developerforce.com/index.php/Using_Apex_Managed_Sharing_to_Create_Custom_Record_Sharing_Logic

 

Study its sample code and compare it to your own.

Message Edited by jlo on 08-05-2009 10:25 AM
rakhi78rakhi78

// 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.

rakhi78rakhi78

// 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