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
KbhaskarKbhaskar 

Apex Code to Update fieldpermission set

I'm getting the following error:

Error: Compile Error: Initial term of field expression must be a concrete SObject: Map<Id,FieldPermissions> at line 71 column 9

Here are the snippets of code 
//update field permission for Opportunity  permission
        fieldpermissions fp=new fieldpermissions();
        Map<id,fieldpermissions>rt=new Map<id,fieldpermissions >([select id,Field FROM fieldpermissions where parentid=:parameterValue AND SobjectType='Opportunity']);
        if(!rt.isempty()) //Compile Error
        {
        rt.id=rt[0].id ;
        }else{
          rt.parentid          = parameterValue ;
          rt.SobjectType       ='Opportunity'; 
        }
        
        for(wrapper i:lstwrapperIntString) //wrapper loop
        {
        if(i.selectedread ==true){
         rt.PermissionsRead= true;
        }
        if(i.selectedwrite ==true){
         rt.PermissionsEdit=true;
         rt.PermissionsRead= true;
         }
           upsert rt;
        }
           return null;

    }

 
Best Answer chosen by Kbhaskar
Tejpal KumawatTejpal Kumawat
Hello Bhaskar,

This issue coming in following snippt.
{
        rt.id=rt[0].id ;
        }else{
          rt.parentid          = parameterValue ;
          rt.SobjectType       ='Opportunity'; 
        }
You need to use use get() & put map method.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_map.htm

Regards
Tej Pal Kumawat
Skype : tejpalkumawat1991

If this answers your question mark Best Answer it as solution and then hit Like!