Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

If a user clicks 'Edit' on an opportunity which he isn't allowed to edit, the "Insufficient Privileges" page directly appears. This is good. If a user clicks 'Edit' on a custom object (which has an edit override that points to a visualforce page), he first sees the form without problems, and the "Insufficient Privileges" page only appears when he tries to save it. This behaviour is misleading for the users, because they think they can manipulate the data and put effort into it, and only afterwards they realize that this wasn't possible after all.

An idea was to check at page load if the user has edit permissions and otherwise redirect him to the "Insufficient Privileges" page.

Might there be another way? Thanks!

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

You can query the UserRecordAccess object to find out if a particular user has edit access to a record. Something like this should tell you if the particular user has edit access to the particular record.

select RecordId, HasEditAccess from UserRecordAccess where UserId = :UserInfo.getUserId()
and RecordId = :id]

I wrote a blog article about this a while ago that has some more details.

share|improve this answer
    
This is awesome! –  eyescream Jan 29 '13 at 19:20
    
This sounds like the most straight forward solution, also I wanted to try to avoid APEX code. Great job! –  Nisse Knudsen Feb 4 '13 at 22:23
add comment

Security settings generally (Profiles + Permission Sets)

I'm going to copy-paste a bit from one of my old answers:

Anything you can do in VF with {!$ObjectType.Opportunity.accessible} you can check with Opportunity.sObjectType.getDescribe().isAccessible()

Except in your case you'd be looking at isUpdateable. If it's false - block the access right away, easy :)

Edit rights to "this" particular record

Even if people can in general edit your objects, your org might be set up in a way that lets them edit only data they own for example (all other users' stuff is readonly).

You'd have to examine sharing settings and if the sharing model is complex - query the Opportunity__Share table. That one might be a bit tricky and you might have to waste several queries before you'll determine the access level. I'm going to be lazy again - check out Querying for OpportunityShare Rule

share|improve this answer
    
Thank you for this idea! But as you already mentioned this is only considering the profile's CRUD settings, not for specific records! I would love to go your way, because it would be easy to implement this in VF... –  Nisse Knudsen Feb 4 '13 at 22:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.