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
AniqaaaAniqaaa 

get objPerms then build Map

Hey Guys,

I need to get Object Permissions then build a Map doing something like
'<Parent__r.ProfileId, ObjectPermissions>
         map<Id, ObjectPermissions[]>'

 

I have wriiten a piece of code below, but the error says (SELECT Id,  //Whichever other fields I may need

SELECT is an unexpected token

 

 

Also follwoing the data model on http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_erd_profile_permissions.htm

the code below seems to be not following the diagram.

 

//get objPerms  then build Map<Parent__r.ProfileId, ObjectPermissions>
         // map<Id, ObjectPermissions[]>
    //from ObjectPermissions Parent__r.ProfileId in the set
    map<Id, ObjectPermissions[]> mapProfileIdtoObjectPermissions = new map<Id, ObjectPermissions[]>();
    for(PermissionSet PS : [SELECT Id, ProfileId
    (SELECT Id,  //Whichever other fields I may need
        FROM ObjectPermissions) // could have issue with ObjectPermissions, I need to get correct child name
        FROM PermissionSet
        WHERE ProfileId IN: profileIds]){
    //we check whether the key has already been put to the map, if not, we perform a put
    if(mapProfileIdtoObjectPermissions.get(PS.ProfileId) == null)
        mapProfileIdtoObjectPermissions.put(PS.ProfileId, new list<ObjectPermissions>{PS.ObjectPermissions});
    // else, the key has already been put, so we just add all ObjectPermissions that are related to this ProfileId
    else
        mapProfileIdtoObjectPermissions.get(PS.ProfileId).addAll(PS.ObjectPermissions);
}

 

 

 

If someone could help I would appreciate there I am noew to Salesforce and its programming language.

 

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
netspidernetspider

I think Ive spotted something 

 (SELECT Id,  //Whichever other fields I may need

 

Remove the ','

All Answers

netspidernetspider

I think Ive spotted something 

 (SELECT Id,  //Whichever other fields I may need

 

Remove the ','

This was selected as the best answer
AniqaaaAniqaaa

I tried, but I think the problem is more than that.

 

Thanks for your help. :)

SLockardSLockard

Try putting a comma after ProfileId like this:

 [SELECT Id, ProfileId,
    (SELECT Id,  //Whichever other fields I may need
        FROM ObjectPermissions) // could have issue with ObjectPermissions, I need to get correct child name
        FROM PermissionSet
        WHERE ProfileId IN: profileIds]

 

AniqaaaAniqaaa

Thanks it solved the problem.

SLockardSLockard

No problem