You need to sign in to do that
Don't have an account?
Pooja Nekkalapudi
how to solve System.NullPointerException: Attempt to de-reference a null object Class.UserAccessDetailsController.getObjectLabels
/*error: System.NullPointerException: Attempt to de-reference a null object
Class.UserAccessDetailsController.getObjectLabels: line 290, column 1
line 290 is this describe.get(op.SObjectType).getDescribe().getLabel()));
*/
public List<NameLabel> getObjectLabels() {
if (null == xObjectLabels) {
List<NameLabel> result = new List<NameLabel>();
Map<String,SObjectType> describe = Schema.getGlobalDescribe();
for (ObjectPermissions op : [SELECT SObjectType FROM ObjectPermissions
WHERE Parent.Profile.Name = 'System Administrator' ]) {
result.add(new NameLabel(op.SObjectType,
describe.get(op.SObjectType).getDescribe().getLabel()));
}
result.sort();
xObjectLabels = result;
}
return xObjectLabels;
}
Class.UserAccessDetailsController.getObjectLabels: line 290, column 1
line 290 is this describe.get(op.SObjectType).getDescribe().getLabel()));
*/
public List<NameLabel> getObjectLabels() {
if (null == xObjectLabels) {
List<NameLabel> result = new List<NameLabel>();
Map<String,SObjectType> describe = Schema.getGlobalDescribe();
for (ObjectPermissions op : [SELECT SObjectType FROM ObjectPermissions
WHERE Parent.Profile.Name = 'System Administrator' ]) {
result.add(new NameLabel(op.SObjectType,
describe.get(op.SObjectType).getDescribe().getLabel()));
}
result.sort();
xObjectLabels = result;
}
return xObjectLabels;
}
Pls try this, it should work fine for you - I checked -
describe.get(op.SObjectType) is coming null.
Thanks,
Sumit Kumar Singh
All Answers
System.debug( "value :" + op.SObjectType);
Pls try this, it should work fine for you - I checked -
describe.get(op.SObjectType) is coming null.
Thanks,
Sumit Kumar Singh
Error: System.NullPointerException: Attempt to de-reference a null object
Class.UserAccessDetailsController.getObjectPerms: line 361, column 1
Class.UserAccessDetailsController.getObjectPermStatus: line 317, column 1
Class.UserAccessDetailsController.__sfdc_flsObjectType: line 93, column 1
// this is for line 361// public Map<Id,Map<String,ObjectPermissions>> getObjectPerms() {
if (null == xObjectPerms) {
Map<Id,Map<String,ObjectPermissions>> result = new Map<Id,Map<String,ObjectPermissions>>();
for (NameLabel ps : permsetInfo) {
result.put(ps.Id, new Map<String,ObjectPermissions>());
for (NameLabel op : getObjectLabels()) {
result.get(ps.Id).put(op.apiName, new ObjectPermissions());
}
}
Map<String,ObjectPermissions> totalAccess = new Map<String,ObjectPermissions>();
result.put(null, totalAccess);
for (NameLabel op : getObjectLabels()) {
totalAccess.put(op.apiName, new ObjectPermissions());
}
for (ObjectPermissions op : [SELECT Id, SObjectType, ParentId,
PermissionsCreate, PermissionsRead, PermissionsEdit, PermissionsDelete,
PermissionsViewAllRecords, PermissionsModifyAllRecords
FROM ObjectPermissions
WHERE ParentId IN :extractPsIds(permsetInfo)]) {
Map<String,ObjectPermissions> opMap = result.get(op.ParentId);
opMap.put(op.SObjectType, op);
ObjectPermissions totalOp = totalAccess.get(op.SObjectType);
for (String apiName : getObjectPermFieldNames()) {
//this is line 361// totalOp.put(apiName, getWithDefault(totalOp, apiName, false) || getWithDefault(op, apiName, false));
}
}
xObjectPerms = result;
}
return xObjectPerms;
}
//this is for line 317// public MapHolder getObjectPermStatus() {
if (null == xObjectStatus) {
Map<String,Boolean> msb = new Map<String, Boolean>();
for (NameLabel nl : getObjectLabels()) {
{
msb.put(nl.apiName,
//this is line 317// getWithDefault(getObjectPerms().get(null).get(nl.apiName), READ, false)); }
}
xObjectStatus = new MapHolder(msb);
}
return xObjectStatus;
}
if(listOfObjectPermissions.size()>0){
for (ObjectPermissions op :listOfObjectPermissions ) { System.debug( "value :" + op.SObjectType); if(op.SObjectType!= null){ result.add(new NameLabel(op.SObjectType,describe.get(op.SObjectType).getDescribe().getLabel())); } }
}
Try to check firt null before for loop.
if(listOfObjectPermissions.size()>0){
for (ObjectPermissions op :listOfObjectPermissions ) { System.debug( "value :" + op.SObjectType); if(op.SObjectType!= null){ result.add(new NameLabel(op.SObjectType,describe.get(op.SObjectType).getDescribe().getLabel())); } }
}
Try to check firt null before for loop.