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
MohaMoha 

Insufficient Privileges You do not have the level of access necessary to perform the operation

hell i have this error and i don't know why it's rendering it to me, i had all things working well, sudently it gives me this : Insufficient PrivilegesYou do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary. 
 help please

Best Answer chosen by Admin (Salesforce Developers) 
MohaMoha
hey, i solved it , i tried to delete the VFpage and the Apex Class, then recreate them, and it worked !!! so until this moment i still dont know where the problem was, thank you Mister @Markot for your effort and your help, i'm greatful thanks again

All Answers

Marko LamotMarko Lamot

explain what you want to do.

are you system administrator?

MohaMoha

I'm a developper, i had a functionnality that allow to do a MassUpdate on a field of selected contacts, it was working very well sudenly i doesn't !!

i select contacts i click on 'MassUpdate' button on the ListView, i have a wizard the first step that show me the records it working the second step that retrieves all the fields of the Contact object in a picklist its working, but when i want to go to the third step where i'm going to update the Value of the selected field it gives me this error

Marko LamotMarko Lamot

edit one contact and try to change one of the fields which you would do normally via mass update. 

Does it allow yout to EDIT/Save the contact? If not, then somebody changed your conacts access right permisions.

 

MohaMoha

well i can edit and save a contact normally, i checked my profil i have all the permissions from read to modify all, but when i want to use mass update for even one contact it still the same error

Marko LamotMarko Lamot

then check if somebody changed access to "visualforce pages" & "apex classess" that executes massupdate ? 

MohaMoha

both of them are checked, and if i didn't have to right to acces VF it won't let me in to the 2snd step of the Wizard, honestly i don't know what the problem is, i don't get it

Marko LamotMarko Lamot

ok, then post the code (VF and apex), where error eccurs

MohaMoha

Apex Class it's generic :  

/**
* This is the controller for the mass update app
* @author cchen
*/
public with sharing class MassUpdateSimpleController {

private final ApexPages.StandardSetController cntr;
private final PageReference fromPage;
private final List<SObject> objs;
private Map<String, Schema.SObjectField> fieldMap;
private transient ApexPages.Message currentMsg;
private final String newLine ='<br></br>';
private Schema.SObjectField field;
private String sType;
private Object convertedFieldData;
private List<SelectOption> picklistValues;
private String currentStep;


public MassUpdateSimpleController(ApexPages.StandardSetController controller) {
currentStep = '1';
controller.setPageSize(1000);
cntr = (ApexPages.StandardSetController)controller;
fromPage = cntr.cancel();
if (this.objs == null) {
this.objs = (List<SObject>)cntr.getSelected();
}
if (getRecordSize()<1) {
String msg = 'No record was selected on the list view. Please click Previous button and select records for mass update.';
currentMsg = new ApexPages.Message(ApexPages.severity.ERROR, msg);
} else {
sType= discoverSObjectType(objs.get(0)).getName();
String msg = 'Number of records selected for update: ' + getRecordSize();
currentMsg = new ApexPages.Message(ApexPages.severity.INFO, msg);
}
ApexPages.addMessage(currentMsg);


}


/* public MassUpdateSimpleController() {
System.debug('ids: ' + ApexPages.currentPage().getParameters().get('ids'));
selected = ApexPages.currentPage().getParameters().get('id0');
return;
cntr = new ApexPages.StandardSetController(objs);
fromPage = cntr.cancel();
if (this.objs == null) {
this.objs = (List<SObject>)cntr.getSelected();
}
if (getRecordSize()<1) {
String msg = 'No record was selected on the list view. Please click Previous button and select records for mass update.';
currentMsg = new ApexPages.Message(ApexPages.severity.ERROR, msg);
} else {
sType= discoverSObjectType(objs.get(0)).getName();
String msg = 'Number of records selected for update: ' + getRecordSize();
currentMsg = new ApexPages.Message(ApexPages.severity.INFO, msg);
}
ApexPages.addMessage(currentMsg);
} */
public String getStep() {
return currentStep;
}

public String getsType() {
return sType;
}

public integer getRecordSize() {
if (objs!=null) {
return objs.size();
} else {
return 0;
}
}

public String filterId {
get;
set;
}


public String getNow(Boolean bShowTime) {
DateTime now = DateTime.now();
if (bShowTime)
return now.year() + '-' + now.month()+ '-' + now.day()+' '+now.hour()+ ':' +now.minute() + ':' + now.second();
else
return now.year() + '-' + now.month()+ '-' + now.day();
}

public List<SObject> objsToUpdate {
get {
return (List<SObject>) cntr.getSelected();
}
set;
}

public String valueToUpdate {
get;
set;
}

public String fieldName {
get;
set {
fieldName=value;
field = fieldMap.get(value);
fieldType = field.getDescribe().getType().name();
}
}

public String fieldType{
get;
set;
}

private Object convertUserInputToFieldData(){
if (field==null) return null;
DisplayType t = field.getDescribe().getType();
Object s = null;

try {
if (t==DisplayType.Double||t==DisplayType.Currency || t==DisplayType.Integer || t==DisplayType.Percent){
s = decimal.valueOf((String)valueToupdate);
} else if (t==DisplayType.Boolean){
if (valueToUpdate=='true'){
s = true;
} else if (valueToUpdate=='false'){
s = false;
} else {
s = Boolean.valueOf(valueToUpdate);
}
} else if (t==DisplayType.Date) {
s = Date.valueOf(valueToUpdate);
} else if (t==DisplayType.DateTime) {
s = DateTime.valueOf(valueToUpdate);
} else if ((t==DisplayType.PickList || t==DisplayType.PickList) && valueToUpdate==null) {
s = '';
}else {
s = valueToupdate;
}
} catch (System.TypeException e){
System.debug('Type exception: ' + e.getMessage());
currentMsg = new ApexPages.Message(ApexPages.severity.ERROR, e.getMessage());
return null;
}

return s;
}


public String getFieldInfoToDisplay() {
if (field==null) return '';
String msg = 'Field type of selected field: ' + fieldType + newline;

Schema.DescribeFieldResult d = field.getDescribe();

if (d.getType()==DisplayType.TextArea || d.getType()==(DisplayType.String)||d.getType()==(DisplayType.URL)) {
msg += 'Max lengh: ' + d.getLength();
valueToUpdate='';
} else if (d.getType()==DisplayType.DateTime ){
msg += 'Format: yyyy-MM-dd HH:mm:ss';
valueToUpdate=getNow(true);
} else if (d.getType()==DisplayType.Date){
msg += 'Format: yyyy-MM-dd';
valueToUpdate=getNow(false);
} else if (d.getType()==DisplayType.Picklist){

picklistValues = new List<SelectOption>();
if (d.isNillable()) {
picklistValues.add(new SelectOption('', '--None--'));
}
for (Schema.PicklistEntry p : d.getPickListValues()) {
picklistValues.add(new SelectOption(p.getValue(), p.getLabel()));
}
msg += newline + 'Please select a picklist value';
} else if (d.getType()==DisplayType.MultiPicklist){

msg += 'Valid Picklist Values: ';
String combined ='';

for (Schema.PicklistEntry p : d.getPickListValues()) {
msg += newLine + '&nbsp;&nbsp;&nbsp;&nbsp;<b>' +p.getValue()+'</b>';
combined += p.getValue()+';';
}
msg += newline + 'Use ; to seperate each picklist value you want to select';
msg += newline + 'For example, to select all the picklist values, enter <b>' + combined + '</b> in the textbox below to select all picklist values';
} else if (d.getType()==DisplayType.Integer){
msg += 'Max digits: ' + d.getDigits();
} else if (d.getType()==DisplayType.String){
msg += 'Max length: ' + d.getLength();
} else if (d.getType()==DisplayType.Double || d.getType()==DisplayType.Currency || d.getType()==DisplayType.Percent){
msg += 'Format: (' + (d.getPrecision()-d.getScale()) + ','+d.getScale() +')';
} else if (d.getType()==DisplayType.Reference){
msg += 'Use this to change selected records to reference a different record, or even dereference records if the filed is left blank' + newLine;
msg += 'Please enter ' + d.getName() + ' that the selected records should reference to';
}

return msg;
}


public PageReference cancel() {
return fromPage;
}
public PageReference step1() {
currentStep='1';
return ApexPages.currentPage();
}

public PageReference step2() {
if(getRecordSize()<1) return fromPage;
currentStep='2';
return ApexPages.currentPage();
}

public PageReference step3() {
currentMsg = new ApexPages.Message(ApexPages.severity.INFO, getFieldInfoToDisplay());
ApexPages.addMessage(currentMsg);
currentStep='3';
return ApexPages.currentPage();
}

public PageReference step4() {
convertedFieldData = convertUserInputToFieldData();

// data type validation
if (currentMsg!=null) {
ApexPages.Message msg = new ApexPages.Message(ApexPages.severity.INFO, getFieldInfoToDisplay());
ApexPages.addMessage(msg);
ApexPages.addMessage(currentMsg);
return ApexPages.currentPage();
}

String msg = 'Please review your selections before confirm: <br></br>';
msg = msg + '<br><b>Records Selected:</b> ' + getRecordSize() +'</br>';
msg = msg + '<br><b>Field To Be Updated:</b> ' + fieldName + '</br>';
msg = msg + '<br><b>New Value:</b> ' + convertedFieldData + '</br>';
currentMsg = new ApexPages.Message(ApexPages.severity.INFO, msg);
ApexPages.addMessage(currentMsg);
currentStep='4';
return ApexPages.currentPage();
}

public PageReference step5() {
currentMsg = (new MassUpdater(objs, field, convertedFieldData)).massUpdate();
ApexPages.addMessage(currentMsg);
currentStep='5';
return ApexPages.currentPage();
}

public DescribeSObjectResult discoverSObjectType(SObject s) {
Map<String, Schema.SObjectType> des = Schema.getGlobalDescribe();

for(Schema.SObjectType o:des.values()) {
if( s.getSObjectType()==o) {
return o.getDescribe();
}
}
return null;
}

public List<SelectOption> getFieldTypeOptions() {
// prevent url hacking
if (objs.size()>0){
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('','-None-'));

Schema.DescribeSObjectResult sObj = discoverSObjectType(objs.get(0));

fieldMap = sObj.fields.getMap();

// List<String> keys =sortByFieldLabel(fieldMap) ;
// keys.add('');
//sortByFieldLabel(fieldMap)
for(String key : fieldMap.keySet()) {
// key ='';
Schema.DescribeFieldResult d = fieldMap.get(key).getDescribe();
// Schema.DescribeFieldResult d = field.getDescribe();
if(d.isAccessible() && d.isUpdateable()) {
if (isSupportedFieldType(d)) {
String label = d.getLabel();
if(d.isCustom()) label += ' (' + key + ')';
options.add(new SelectOption(key, label));
}
}
}

return options;
}else {
return null;
}

}

private List<String> sortByFieldLabel(Map<String, Schema.SObjectField> gd) {
List<String> keys = new List<String>();

Map<String, List<String>> labelMap = new Map<String, List<String>>();

for(Schema.SObjectField s:gd.values()) {
String label = s.getDescribe().getLabel();
if(labelMap.get(label) == null) {
labelMap.put(label, new List<String>());
}

labelMap.get(label).add(s.getDescribe().getName());
}

List<String> labels = new List<String>(labelMap.keySet());
labels.sort();

for(String label:labels){
keys.addAll(labelMap.get(label));
}

return keys;
}

public List<SelectOption> getPicklistValues() {
return picklistValues;
}

private boolean isSupportedFieldType(DescribeFieldResult d) {
// always return true for now, but in future some fields might not be supported
return true;
}


}

 

 

VisualForce Page : 

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""*Step2 :***************************************

<apex:pageBlock id="field" title="Step 2. Specify the field to be udpated" mode="edit" rendered="{!step='2'}">
<apex:pagemessages escape="false"></apex:pagemessages>
<apex:selectList id="pickList" size="1" value="{!fieldName}" required="true">
<apex:selectOptions value="{!FieldTypeOptions}"/>
</apex:selectList>

""""""""""""""""""""""""""""""""""""""""""""""""Step 3************************************************
<apex:pageBlock id="step3" title="Step 3. Specify the new value for field - {!fieldName}" mode="edit" rendered="{!step='3'}">
<apex:pagemessages escape="false"></apex:pagemessages>
<apex:inputText rendered="{!fieldType='CURRENCY'}" value="{!valueToUpdate}" />
<apex:inputText rendered="{!fieldType='DATE'}" value="{!valueToUpdate}" />
<apex:inputText rendered="{!fieldType='DATETIME'}" value="{!valueToUpdate}" />
<apex:inputText rendered="{!fieldType='TEXT'}" value="{!valueToUpdate}" />
<apex:inputText rendered="{!fieldType='NUMBER'}" value="{!valueToUpdate}" />
<apex:inputText rendered="{!fieldType='COMBOBOX'}" value="{!valueToUpdate}" />
<apex:inputText rendered="{!fieldType='DOUBLE'}" value="{!valueToUpdate}" />
<apex:inputText rendered="{!fieldType='EMAIL'}" value="{!valueToUpdate}" />
<apex:inputText rendered="{!fieldType='ID'}" value="{!valueToUpdate}" />
<apex:inputText rendered="{!fieldType='INTEGER'}" value="{!valueToUpdate}" />
<apex:inputText rendered="{!fieldType='PERCENT'}" value="{!valueToUpdate}" />
<apex:inputText rendered="{!fieldType='MULTIPICKLIST'}" value="{!valueToUpdate}" />
<apex:inputText rendered="{!fieldType='PHONE'}" value="{!valueToUpdate}" />
<apex:inputText rendered="{!fieldType='STRING'}" value="{!valueToUpdate}" />
<apex:inputText rendered="{!fieldType='REFERENCE'}" value="{!valueToUpdate}" />
<apex:inputText rendered="{!fieldType='BASE64'}" value="{!valueToUpdate}" />
<apex:inputTextArea rendered="{!fieldType='TEXTAREA'}" rows="15" cols="100" value="{!valueToUpdate}" />
<apex:inputCheckBox rendered="{!fieldType='BOOLEAN'}" value="{!valueToUpdate}" />
<apex:selectList rendered="{!fieldType='PICKLIST'}" value="{!valueToUpdate}" size="1">
<apex:selectOptions value="{!picklistvalues}"/>
</apex:selectList>
<apex:pageBlockButtons >
<apex:commandButton action="{!step2}" value="Previous"/>
<apex:commandButton action="{!step4}" value="Next"/>
<apex:commandButton action="{!cancel}" value="Cancel" onclick="return confirmCancel()" immediate="true" style="margin-left: 2em"/>
</apex:pageBlockButtons>
</apex:pageBlock>

MohaMoha
did u find out anything yet ?
Yoganand GadekarYoganand Gadekar

if you are trying to access record which is not shared with you then you will get this error.

 

This depends on number of things related to your profile settings for that object also OWD for that object.

 

Thanks and Regards,

Salesforce knowledge sharing at:

Cloudfroec4u

Marko LamotMarko Lamot

when exactly do you get an error: is that when you are in page2 when you press "next" button -> instead of  page block "<apex:pageBlock id="step3" ...... "  appears, you get insuffisient error?

MohaMoha
yes this is it, when i'm in step 2 i have a picklist which contains all the fields of the Object, when i choose one and i Click on "Next button" that should take me to step 3, it show me this Error
yes
MellowRenMellowRen

Jamal

 

You said you were a developer, by any chance are you getting this error in a Sandbox? Straight after the Summer 13 release, my Sandbox produced exactly the same error although our Production environment was fine. I had to refresh it to get back to a working system :-/

 

Regards

MellowRen

MohaMoha
no not in a sandbox in production environnement, it was working fine just yesterday
Marko LamotMarko Lamot

What happen if you try this massupade in other browser?

Do you have any changes (setup related or new deployment from sandbox or package deploy....) to the system between yesterday and today?

MohaMoha
yes i tried, it's the same, and all what i did yesterday was Enable Publisher Actions it's the new feature in chatter, under customuze=>chatter, and i deactivate it and it still not working
did u find any bug in the Code ?
Marko LamotMarko Lamot

I don't see any obvious error.

 

I would next try disable the code in VF and see what happens.

 

<apex:selectList rendered="{!fieldType='PICKLIST'}" value="{!valueToUpdate}" size="1">
<apex:selectOptions value="{!picklistvalues}"/>
</apex:selectList>

 

 

 

MohaMoha
hey, i solved it , i tried to delete the VFpage and the Apex Class, then recreate them, and it worked !!! so until this moment i still dont know where the problem was, thank you Mister @Markot for your effort and your help, i'm greatful thanks again
This was selected as the best answer
~Onkar~Onkar

Your code is used "with sharing"

Check is the following OWD setting

 

1 Account is Private and contact is control by parent.

2 If Yes private check are u Owner of these records.

3. Any sharing rule.

 

or if you want execute in system mode "remove with sharing". It seems like previously your code was "without sharing"

 

~Onkar Kumar

 

 

Marko LamotMarko Lamot

Hm, interesting.   In that case I'm almost sure that the problem was casued by broser itself. And all that was needed was clearing browser cache....

 

Anyhow, I'm glad you solve the problem...

MohaMoha
hey thanks for the reply,no i don't think it was the browser, because i checked all the browsers with cleared cache, the important now that it's working, as it's supposed to be, thanks again
MohaMoha

Hello Marko, i'm wondering if you can help me with Test MEthod for this Class !!

Mahmoud BECHAAMahmoud BECHAA
I had exactly the same problem on insufficient privileges on accounts while doing a mass update. I had to create a new MassUpdateSimpleController that I named MyMassUpdateSimpleController and which was the exact copy of the original except for the class name and class constructor. Then I modified the VF Page named AccountMassUpdate to change the "extensions" attribute value which was carrying the name of the original controller (that's to say : MassUpdateSimpleController)  and set it to   "MyMassUpdateSimpleController". And there it goes ... It works but I'm interested in discovering what is the reason of such a problem on the original controller. For the moment I tested only on my sandbox and I'm waiting to see if there's not a cleaner solution. If someone can tell me ...