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
Ken KoellnerKen Koellner 

Sites Guest User can't update Contact

We have a register site writing in SF Sites with VF/Apex.  The Site runs without login via a Sites Guest User.  The Apex controller is coded without sharing. 

 

We'd like to allow the visitor to the Site to update the email address on their Contact record.  But, update access to Contact can't be granted to the profile, only Read and Create.  So the update won't work.

 

Anyone know a work-around? 

 

The one thing I thought if is to save the email address to a custom object then have batch apex running under a different login sweep the data and make the changes to the Contact records.  Seems like a lot of work to build all that when all I want to do is a allow update access only through this VF page.

 

Vinita_SFDCVinita_SFDC

Hi,

 

After saving email id in a field in custom object, setup a cross object workflow filed update.

Ken KoellnerKen Koellner

Do workflows execute in the context of the original DML or a system context?  I would think if they run in the context of the original DML, that technique would also fail.

 

Ken KoellnerKen Koellner

I tried to create a field update.  The custom object has a lookup(Contact) field in it but when I trying to create the Field Update, the only objects I could pick for the target object were the custom object it's self and its parent in a master-detail relationship.  It has a master-detail to another custom object.  It needs to be a child of that other custom object, it can't be a master-detail to Contact.

 

Vinita_SFDCVinita_SFDC

Hi,

 

An object can have two master-detail relationships. Can you try establishing one MD relationship between custom object and contact, you can hide this MD field from layout.

 

Note: Once MD is established between Contact and custom object, child record will be deleted on deletion master record.

Ken KoellnerKen Koellner

Are you sure the workflow Field Update will fire under some context other than the Site Guest User that issues the original DML?  If not, it won't work.

 

It's a bit of setup work and some coding changes to get it to work that way and if I change the lookup(Contact) field to master-detail(contact), and want to go back, I'll have to delete and re-add it as I believe you can't demote a master-detail back to lookup.

Vinita_SFDCVinita_SFDC

Hi,

Workflow rule will fire whenever the evaluation criteria will meet, irrespective of the mode by which the record was created/edited. So if you choose evaluation criteria is 'Evaluate the rule when a record is edited' then whenever the field update would trigger, wf will run.

If you wish to restrict this wf rule to fired for few profiles then you can make a check in 'Rule criteria' of WF.

Let me know if i am misunderstanding your requirement.



Ken KoellnerKen Koellner

I'm asking about PERMISSIONS the workflow field update will have.  The Sites Guest User does not have permissions to update Contact.  If the workflow field update is running under the context of the user that issue the original DML to the custom object, I would think the Field Update would result in a permssions exception.

 

I'm trying to work around the permission restriction on the site guest user.

 

 

Vinita_SFDCVinita_SFDC

Hi,

 

WF will be created by someone who has access on contact and custom object both, now wf will function as expected even if the custom object is being edited by guest user who doesn't have edit access on contact.

Avish Samdani 5Avish Samdani 5
Hi Ken Koellner,

Don't bind direct Contact to VF page. Fetch contact in without sharing controller and map your contact data to wrapper class. Bind this wrapper class to the VF page. On click of update button again map wrapper to your contact and then try to update Contact.

OR
Fetch contact in sObject type variable not in Contact type. Bind this sObject to VF page. And update this sObject in controller.

Thanks,
Avish Samdani