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
Don Schueler 6Don Schueler 6 

Package apex that references ContactShare ContactID

I have a VF Page that is used in the Partner Community to lookup a contact that they might not have access too and gain access.  This works fine in my Dev org....but I had to switch Contact to Private from Controlled by Parent to both save the code AND to run the test class successfull.

So far my code works since I do an Organization query to see if my Contact is 'ControlledbyParent', if it is I don't update the ContactShare object, I just Share the Account.  Note...as many might know, you can't even save your APEX with ContactShare cShare = new ContactShare(ContactId=cid, UserOrGroupId=UserInfo.getUserId(),ContactAccessLevel='Edit');   in it  if you have Controlled By Parent for Contact set as your default sharing. This is the only case I am aware of in SF where a configuration setting impacts the ability to save code or run a test or include in a package. Seems wrong to me...we should be able to handle this in code and have it be OK.

THE PROBLEM NOW IS: I can't include this in my managed package....I get: Dependent class is invalid and needs recompilation: Class ApexBaseClass : Field is not writeable: ContactShare.ContactId

So I am looking for either solutions to this from a packaging standpoint OR a better way to accomplish the functionality. Thinking aloud..I guess I coud do it in AJAX using API...not that I would love it there... Looking for other alternatives.....thanks in advance.
Don Schueler 6Don Schueler 6
Answering my own question here ;0 - I had switched sharing for contact back to Controlled By Parent for testing and forgot to switch back before uploading package - DOH! I switched back to Private and now I can package. I am not 100% convinced this is going to fly perfectly but will let you all know if I have any updates.
Don Schueler 6Don Schueler 6
Update...While this can be packaged, the package install will fail if the Sharing is not set to Private on the install org. This is really a PAIN!
Any thoughts out there???