List update return Update access denied for object, controller action methods cannot be executed I would like a help with update for a list... For some reason when I click to update it returns the following error: "core.apexpages.exceptions.ApexPagesGenericException: system.security.NoAccessException: Update access denied for Business_Opportunity__c, controller action methods cannot be executed" so I searched the ''without sharing" should solve, but even putting it I keep getting an error..
Visualforce page
<apex:page language="{!IF(ISNULL(language),'pt_BR',language)}" id="OppNegocios" showHeader="false" docType="html-5.0" standardStylesheets="false" cache="false" controller="aSiteOppNegociosController" action="{!validate}">
<apex:define name="body">
<body class="nav-md footer_fixed" >
<center>
<div style="background-color:white; margin-top:100px; padding:20px; width:80%">
<div class="page-title">
<div class="title_left">
<h3 style="color:black">Oportunidades de Negócios</h3><!--Título: Anexo I-->
</div>
</div>
<hr width="90%" style="color:black;" />
<apex:form >
<apex:pageMessages />
<table>
<tr>
<th style="color:black;">Variedades:</th>
<th style="color:black;">Demanda:</th>
<th style="color:black;">Oferta:</th>
</tr>
<tr>
<td style="padding:5px;">
<apex:selectList id="selectedVariedade" value="{!selectedVariedade}" size="1" >
<apex:selectOptions value="{!VariedadeList}"></apex:selectOptions>
</apex:selectList>
</td>
<td style="padding:5px;"><apex:inputText value="{!demanda}"/></td>
<td style="padding:5px;"><apex:inputText value="{!oferta}"/></td>
<!--variedade-->
</tr>
<tr>
<td><apex:commandButton value="Inserir" action="{!save}"/></td>
</tr>
</table>
</apex:form>
<br/>
<hr width="90%" style="color:black; margin-bottom:0px;" />
<div >
<apex:pageMessages />
<br/><br/>
<apex:form id="changeStatusForm">
<apex:pageBlock>
<apex:pageBlockTable value="{!OppNegocios}" var="c">
<apex:column headerValue="Variedades">
<apex:outputText value="{!c.Variedade__r.Name}"/>
</apex:column>
<apex:column headerValue="Demanda">
<apex:inputText value="{!c.Demanda_Compra__c}"/>
</apex:column>
<apex:column headerValue="Oferta">
<apex:inputText value="{!c.Oferta_Venda__c}"/>
</apex:column>
</apex:pageBlockTable>
<div style="margin:10px"></div>
<apex:pageBlockButtons>
<apex:commandButton value="Atualizar" action="{!updateoppNegocios}"/>
</apex:pageBlockButtons>
<div style="margin:5px"></div>
</apex:pageBlock>
</apex:form><br/><br/>
</div>
</div>
</center>
</body>
</apex:define>
</apex:page>
Controller
global without sharing class aSiteOppNegociosController {
private String token;
private String idlicenciado {get; set;}
private SiteUser__c logUser;
private Account activeAccount;
private SiteUserSession__c activeSession;
public String safraActual {get;set;}
public String language {get;set;}
public Oportunidade_de_Negocios__c a {get;set;}
public List<Oportunidade_de_Negocios__c> oppNegocios;
public Double demanda{get;set;}
public Double oferta{get;set;}
public String selectedVariedade {get; set;}
//public List<Oportunidade_de_Negocios__c> oppNegocios = new List<Oportunidade_de_Negocios__c>();
public List<Variedade__c> Variedade = new List<Variedade__c>();
//public List<Safra__c> Safra=new List<Safra__c>();
global aSiteOppNegociosController () {
try{
language = [select id, LanguageLocaleKey from User where id =: UserInfo.getUserId()].LanguageLocaleKey;
}
catch(Exception e){
}
init();//Call the init method for the update
}
public PageReference validate() {
token = System.currentPageReference().getParameters().get('token');
if(token!=null){
logUser = aSiteAuthManager.VerifyUserSession(token);
System.debug('logUser: ' + logUser);
if(logUser!=null){
activeSession = aSiteAuthManager.getUserSession(token);
activeAccount = aSiteAuthManager.getActiveAccount_byUser(logUser);
safraActual = aSiteUtils.buildSafraByYear();
idlicenciado = logUser.Id;
return null;
}
}
PageReference p = new PageReference('/apex/aSiteLogin');
String marca = aSiteAuthManager.getMarcaBySession(token);
if (marca != null)
p.getParameters().put('comp',marca);
p.setRedirect(true);
return p;
}
//Insert the business opportunity
public PageReference save(){
try {
a=new Oportunidade_de_Negocios__c();
a.Demanda_Compra__c = demanda;
a.Oferta_Venda__c = oferta;
a.Licenciado__c=logUser.Id;
a.Conta__c =activeAccount.Id;
a.Variedade__c=selectedVariedade ;
a.Safra__c=safraActual;
a.OwnerId='005f4000000RIxAAAW';//to do
insert a;
//refresh the pag
PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
pageRef.setRedirect(true);
return pageRef;
} catch (Exception e) {
ApexPages.addMessages(e);
return null;
}
}
public void init(){
oppNegocios=[Select Id, Variedade__c,Variedade__r.Name, Oferta_Venda__c, LastModifiedDate, Licenciado__c, Safra__c,Demanda_Compra__c
FROM Oportunidade_de_Negocios__c WHERE Licenciado__c =: idlicenciado AND Safra__c =: safraActual ORDER BY LastModifiedDate DESC ];
System.debug('oppNegocios no init: '+oppNegocios);
}
public PageReference updateoppNegocios(){
System.debug('oppNegocios logo após o clique: '+oppNegocios);
try{
update oppNegocios;
}catch(DmlException ex){
ApexPages.addMessages(ex);
}
init();
return null;
}
//Assemble the product variety picklist options
public List <SelectOption>getVariedadeList(){
List<SelectOption> var=new List<SelectOption>();
List<Variedade__c> allvar=[Select Id, Name FROM Variedade__c WHERE Obtentor__c = 'HO' and Ativa__c = TRUE AND Disponivel_para_Negociacao__c = true];
for(Variedade__c i : allvar){
var.add(new SelectOption(i.Id, i.Name));
}
return var;
}
//Builds the list that displays all the licensee's business opportunities
public List<Oportunidade_de_Negocios__c>getOppNegocios(){
if(oppNegocios==null){
oppNegocios=[Select Id, Variedade__c,Variedade__r.Name, Oferta_Venda__c, LastModifiedDate, Licenciado__c, Safra__c,Demanda_Compra__c
FROM Oportunidade_de_Negocios__c WHERE Licenciado__c =: idlicenciado AND Safra__c =: safraActual ORDER BY LastModifiedDate DESC ];
}
// System.debug('oppNegocios: '+oppNegocios);
return oppNegocios;
}
}
Business_Opportunity__c
object? (which I'm guessing is indirectly updated by updatingOportunidade_de_Negocios__c
)