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 

Need help to complete code successfully and also make it work

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 becasue I am new I don't think its doing anything.

 

 

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 by finishing of the code I would appreciate there I am new to Apex.

 

 

Thanks