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
ElkeElke 

How to use products independent from CRUD

We want to override the VF page for adding products to an opportunity.

We added 3 custom fields to our Product2 object for choosing the products. These are picklist fields with field dependencies in order to filter our list of products. The content of “Product Sub-Group” depends on a selection of “Product Group” whereby “Product Group” depends on the selection of “Main Article Group”.

This is very simple to develop if we use a variable p of type Product2 which is declared in the controller extension and accessed in the VF Page with <apex:inputField..> .  See this little code:

public without sharing class yAddProducts { public Product2 p {get;set;} public yAddProducts(ApexPages.StandardController controller) { p=new Product2(); } } <apex:page standardcontroller="Opportunity" extensions="yAddProducts"> <apex:Form > <apex:PageBlock > <apex:outputText value="{!$ObjectType.Product2.Fields.yMainArticleGroup__c.Label}"/><BR/> <apex:Inputfield value="{!p.yMainArticleGroup__c}"/><BR/> <apex:outputText value="{!$ObjectType.Product2.Fields.yProductGroup__c.Label}"/><BR/> <apex:inputField value="{!p.yProductGroup__c}"/><BR/> <apex:outputText value="{!$ObjectType.Product2.Fields.yProductSubGroup__c.Label}"/><BR/> <apex:Inputfield value="{!p.yProductSubGroup__c}"/><BR/> </apex:pageBlock> </apex:Form> </apex:page>

It’s possible to select values from the picklist with dependencies. Everything works as expected if we are logged in as system administrator.  But our users have only read permissions for the Product2 Object.  These users don’t see any listbox for the picklists at the VF page. The problem exists because of the permissions, but our users shall not be allowed to create, update or delete products. Note: we don’t want to save the product in variable p, we only need this as a "template" for the comfortable input with dependencies of the list boxes to use it as a filter. Of course, we could develop the dependencies of the picklist values with string arrays or whatever, but this is lot of work, especially if values in the picklist fields and their dependencies will change some day. Any idea how I can use <apex:inputField..> for an SObject independent of the given CRUD permissions for the logged in user?

Thanks,

Elke

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

You can't circumvent these permissions in Visualforce; they are always enforced. I would suggest using an alternative method. Here's some ideas: 1) A custom object without a tab that houses the necessary fields. 2) Set the profile permissions for Products so that they can create products (but not edit them). 3) Create your own code for dependent picklists.

All Answers

sfdcfoxsfdcfox

You can't circumvent these permissions in Visualforce; they are always enforced. I would suggest using an alternative method. Here's some ideas: 1) A custom object without a tab that houses the necessary fields. 2) Set the profile permissions for Products so that they can create products (but not edit them). 3) Create your own code for dependent picklists.

This was selected as the best answer
ElkeElke

Thanks sfdcfox,

Yes, we have thought about using an additional custom object as you suggest in your idea 1). Going to implement this now. Thanks for your recommendation,

Elke