+ Start a Discussion
Amit Visapurkar 5Amit Visapurkar 5 

system.security.NoAccessException: Update access denied for PricebookEntry, controller action methods may not execute

Below is my code

<apex:page standardController="Order" extensions="selectProduct" docType="html-5.0" >
   <apex:form >    
        <apex:pageBlock >        
            <apex:pageMessages ></apex:pageMessages>
                <apex:pageBlockButtons >
                
         <!--   <apex:commandButton value="Save" action="{!Save}"/> -->
                
                <apex:commandButton value="Save" action="{!Submit}"/>
                <apex:commandButton value="Cancel" action="{!Cancel}"/>
                
                </apex:pageBlockButtons>   
         
         <apex:pageblockSection >
         
             <apex:pageBlockTable value="{!selectP}" var="q">
             
                 <apex:column value="{!q.Name} " HeaderValue="Product"/>
                 
                 <apex:column value="{!q.UnitPrice} " HeaderValue="Unit Price(USD)"/>
                  <apex:pageMessages ></apex:pageMessages>
                 <apex:column headerValue="Quantity">
                     
                         <apex:inputText value="{!q.Order_Quantity__c}"/>

                         
                 </apex:column>

             </apex:pageBlockTable>
 
         </apex:pageblockSection>
         
        </apex:pageBlock>    
    </apex:form>
</apex:page>


public class selectProduct{

String OrderSelect = ApexPages.currentPage().getParameters().get('param2');
public List<PricebookEntry> selectP{get;set;}

public selectProduct(ApexPages.StandardController stdController) {
       
       String OrderId= ApexPages.currentPage().getParameters().get('param1');
       String selectedString = string.valueOf(OrderId);             
       selectedString = string.valueOf(selectedString.substring(1,selectedString.length() - 1));     
       selectedString = selectedString.replace(' ',''); 
       String[] strList = selectedString.split(','); 
       selectP = new  List<PricebookEntry>();       
       selectP = [SELECT Id,Name,UnitPrice,Order_Quantity__c FROM PricebookEntry WHERE Id In :strList  AND CurrencyIsoCode='USD'];
       
    }   
    
     public pageReference Cancel(){
     
      PageReference h = new PageReference('/'+OrderSelect);
      h.setRedirect(true);
      return h;
     
     
     }
    
  //--------------  
  
  
      public pageReference Submit(){

        for(PricebookEntry e:selectP){
           if(e.Order_Quantity__c==null || e.Order_Quantity__c==0 || e.Order_Quantity__c<0.0){
           
               ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please enter a positive Value.'));
               return null;
           
           } 
           
           }  
           
 
    for(PricebookEntry r:selectP){
    
     system.debug('*************************OrderSelect************************'+OrderSelect);
   
     Orderitem t = new OrderItem();
     t.OrderId = OrderSelect;
     t.UnitPrice = r.UnitPrice;
     t.PricebookEntryId = r.Id;
     t.Quantity = r.Order_Quantity__c;
  
    
     }
     
    PageReference d = new PageReference('/'+OrderSelect);
    d.setRedirect(true);
    return d;

    
    }

}

Not able to get why this error is coming.Please help its urgent
Manish BhatiManish Bhati
Can you please tell in which method the following code is :-
for(PricebookEntry r:selectP){
    
     system.debug('*************************OrderSelect************************'+OrderSelect);
   
     Orderitem t = new OrderItem();
     t.OrderId = OrderSelect;
     t.UnitPrice = r.UnitPrice;
     t.PricebookEntryId = r.Id;
     t.Quantity = r.Order_Quantity__c;
  
    
     }
     
    PageReference d = new PageReference('/'+OrderSelect);
    d.setRedirect(true);
    return d;