+ Start a Discussion
etechcareersetechcareers 

Apex Code and Profile

I am building a search VF page and was wondering does the apex code take in account for the profile being used. Like for me it is bringing back every account no matter what recordtype. of course I am admin.

 

But would that be the same as a user. Would it restrict access to that user if they click on it.

 

Is there a way to make the code, search on based on the profile/recordtype?

 

Thanks

 

hisrinuhisrinu

You can make use of with sharing keyword, to work based upon user profile.

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_keywords_sharing.htm

sfdcfoxsfdcfox

There's a few considerations to take into account when building VF pages. Firstly, remember that Field Level Security may not apply, and so it's important that you not accidentally expose encrypted field values or fields that should not be visible to certain users. Secondly, as mentioned above, the with sharing keyword on a class will cause the sharing security model to be enforced based on the user's profile, default sharing model, sharing rules, role hierarchy inheritance, and so on to be considered for each and every SOQL and SOSL query that you perform. Finally, you may also manually check sharing by querying the related tables, such as AccountShare, which would allow you to inspect a user's ability to view, edit, or delete a record.