0

So,

Currently doing code maintenance for my org.

i NEVER touched any part of this code or apex class but somehow it is throwing an error after working just fine.

List<PO_Invoice__share> newListToInsert = new List<PO_Invoice__share>(); the error "Invalid type: PO_Invoice__share" shows up for this one, even though PO_Invoice__c is controlled by it's parent, which is private. So I don't know why PO_Invoice__share is all of the sudden randomly not working. I never even touched this line of code.

Then I get an error on this line of code saying "Variable does not exist: OwnerId"

for(PO_Invoice__c invoice: newList){
            if(oldMap == null || (oldMap != null && invoice.Company_FF__c != oldMap.get(invoice.Id).Company_FF__c) || (oldMap != null && invoice.OwnerId != oldMap.get(invoice.Id).OwnerId)){   //Updated by Purnima for Story S-570738
                purchaseId.add(invoice.Id);
            }
     }

anyone know why this is happening? I have no clue because nothing was changed.

4
  • 3
    This probably is because a master-detail field was created on the object after the last deployment of the code. Objects on the detail side of a master-detail cannot have apex sharing. Commented Jun 12, 2020 at 14:54
  • Hmm.. So there is no way around this other than to just comment the code out? Another thing is, and I don't know if this is the cause. But since this error happened. I can edit a PO Invoice record and save it fine, but I cannot create one, yet I have all the appropriate permissions for the object. Any idea? Commented Jun 12, 2020 at 15:09
  • Without any more information it's hard to figure out why you cannot create records.. Does it give you an error? If your triggers are only executed on insert, the issue could be related (because now the trigger gets a runtime error during insertion) Commented Jun 12, 2020 at 15:11
  • I just tested by deleting the trigger and creating a record again, still nothing. I don't know why it would be doing this. It just throws the error saying I have insufficient privileges. Commented Jun 12, 2020 at 15:16

1 Answer 1

1

As rael_kid mentioned, the absence of an OwnerId indicates that PO_Invoice__c is now on the detail side of a master-detail relationship and as such, will also have no PO_Invoice__share object associated with it (as sharing is controlled by the parent object).

As for the issue of not being able to edit the records anymore, that is controlled by this setting on the relationship field (writeRequiresMasterRead): enter image description here

3
  • Thank you! Very useful information, however; I do have full access to the parent object and I am trying to create the record on the parent object but still for some reason won't let me create it. Commented Jun 12, 2020 at 15:35
  • What is the error message? Without that it would be hard to guess the cause.
    – Stephen SS
    Commented Jun 12, 2020 at 15:53
  • Okay, I figured it out. I don't know if it was just me not knowing the business process of the "apparatus" i was working on or if it was something I fixed. But either way it's working again now and the code issue I just kind of commented it out since it was useless anyways. Commented Jun 12, 2020 at 18:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .