I have a Visualforce Page that uses a standard controller for custom object and an extension. In the extension I have a method that get details of selected record, which is selected in select control. The extension is "with sharing". I am setting relational field's values from selected object to inputHidden control in VisualForce page. So I can use that values in javascript. When I try to do that I receive this error:
"system.security.NoAccessException: Create access denied for custom object, controller action methods may not execute"
I found one solution which is mentioned below post, I used Apex:Variable for storing values. system.security.NoAccessException: Update access denied for RecordType
But I am not able to access apex:variable in javascript.
Any help will be greatly appreciated
Apex Controller
public with sharing class SNQuoteController {
public SN_Quote__c objQuote { get; set; }
public list<SN_Product__c> lstProducts { get; set; }
public SN_Product__c selectedProduct { get; set; }
public SNQuoteController(ApexPages.StandardController stdController){
try{
selectedProduct = new SN_Product__c();
lstProducts = [SELECT Active__c, Allow_Multiple__c, Allow_Multiple_Per_Service_Type__c, Allow_Overlapping__c, BusinessId__c,
ConfiguratorType__c, ExternalId__c, IsRenewable__c, MaxQuantity__c, MinQuantity__c, Order_Types__c, OwnerId,
Product_Base__c, Product_Line__c, Product_Line__r.Name, Name__c, Name, Id, Renewal_Terms__c, Required_Contact_Types__c,
Service_Type__c, Start_Date_Rule__c FROM SN_Product__c WHERE Pricing_Type__c = 'Quote' AND Active__c = true ORDER BY Name];
}
catch(Exception e){
throw e;
}
}
public void GetSelectedProductDetail(){
try{
if(lstProducts != null && lstProducts.size() > 0){
selectedProduct = (new Map<Id, SN_Product__c>(lstProducts)).get(objQuote.Product__c);
}
}
catch(Exception e){
throw e;
}
}
}
Visual Force Page
<apex:page standardController="SN_Quote__c" showHeader="true" sidebar="true" extensions="SNQuoteController">
<apex:form id="frmQuote" style="width : 100%;" >
<apex:pageBlock title="Quote Detail" id="pnlMain">
<apex:variable value = "{!selectedProduct.Id}" var = "selectedProId"/>
<apex:variable value = "{!selectedProduct.Product_Line__c}" var = "selectedProLineId"/>
<apex:selectList id="ddlProducts" size="1" value="{!objQuote.Product__c}">
<apex:actionSupport event="onchange" action="{!GetSelectedProductDetail}" rerender="pnlMain" />
<apex:selectOptions value="{!lstProductOption}"/>
</apex:selectList>
</apex:pageBlock>
</apex:form>
<script>
function openModal(){
//I need to access those apex:variable here with frequent value changes as per apex:selectList onchange
return false;
}
</script>
</apex:page>