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
Balakumar Ramachandran 6Balakumar Ramachandran 6 

Illegal assignment from List to Id

I know why the error " Illegal assignment from List to Id" is coming here..how to resolve it. any ideas ?

public with sharing class ExamplePageController {
 
    public list<String> InitialList  {get;set;}
    public list<String> CurrentList  {get;set;}

    public ExamplePageController() {
    InitialList = new list<String>();
    InitialList.add(UserInfo.getUserId());
    CurrentList = new list<String>();
   
  }
   
  public PageReference manualShareRead(){
      Id recordId= ApexPages.currentPage().getParameters().get('parentid');
      //Id userOrGroupId='005f0000000jioGAAQ';
      Id userOrGroupId=CurrentList;
      // Create new sharing object for the custom object Job.
      Scheme__Share jobShr  = new Scheme__Share();
  
      // Set the ID of record being shared.
      jobShr.ParentId = recordId;  
      system.debug('-------------------Record Id----------'+recordId); 
      // Set the ID of user or group being granted access.
      jobShr.UserOrGroupId = userOrGroupId;
      system.debug('-------------------User Id----------'+userOrGroupId);
      // Set the access level.
      jobShr.AccessLevel = 'Edit';
       
      // Set rowCause to 'manual' for manual sharing.
      // This line can be omitted as 'manual' is the default value for sharing objects.
      jobShr.RowCause = Schema.Scheme__Share.RowCause.Manual;
       
    --------------- remaining code-------------
Vatsal KothariVatsal Kothari
Hi,

Correct the below line:
Id userOrGroupId=CurrentList;
you are assigning List to Id, assign Id to userOrGroupId.

Thanks,
Vatsal
Ruwantha  LankathilakaRuwantha Lankathilaka
What is the corresponding line 
Balakumar Ramachandran 6Balakumar Ramachandran 6
Thanks Vatsal for your response. I want it in List..I dont know how to convert the Id into List
Balakumar Ramachandran 6Balakumar Ramachandran 6
public with sharing class ExamplePageController {
 
    public list<String> InitialList  {get;set;}
    public list<String> CurrentList  {get;set;}

   
    public ExamplePageController() {
    InitialList = new list<String>();
    InitialList.add(UserInfo.getUserId());
    CurrentList = new list<String>();
   
  }
   
  public PageReference manualShareRead(){
  
      Id recordId= ApexPages.currentPage().getParameters().get('parentid');
      Id userOrGroupId='005f0000000jioGAAQ';
      Id userOrGroupId=CurrentList;
      // Create new sharing object for the custom object Job.
      Scheme__Share jobShr  = new Scheme__Share();
  
      // Set the ID of record being shared.
      jobShr.ParentId = recordId;  
     
      system.debug('-------------------Record Id----------'+recordId); 
      // Set the ID of user or group being granted access.
     
    
      jobShr.UserOrGroupId = userOrGroupId;
     
      system.debug('-------------------User Id----------'+userOrGroupId);
      // Set the access level.
      jobShr.AccessLevel = 'Edit';
       
      // Set rowCause to 'manual' for manual sharing.
      // This line can be omitted as 'manual' is the default value for sharing objects.
      jobShr.RowCause = Schema.Scheme__Share.RowCause.Manual;
       
      // Insert the sharing record and capture the save result.
      // The false parameter allows for partial processing if multiple records passed
      // into the operation.
      Database.SaveResult sr = Database.insert(jobShr,false);
   
       system.debug('#################################');
      // Process the save results.
      if(sr.isSuccess()){
         // Indicates success
         system.debug('SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS');
         //return true;
         ApexPages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Your Record has been added');
         ApexPages.addmessage(msg);
         PageReference redirectpage = new PageReference('/apex/WV_SchemeDetails?id='+recordId);
         return redirectpage;
         //return null;
      }
      else {
         // Get first save result error.
         Database.Error err = sr.getErrors()[0];
        
         // Check if the error is related to trival access level.
         // Access levels equal or more permissive than the object's default
         // access level are not allowed.
         // These sharing records are not required and thus an insert exception is acceptable.
         if(err.getStatusCode() == StatusCode.FIELD_FILTER_VALIDATION_EXCEPTION  && 
                  err.getMessage().contains('AccessLevel')){
                      system.debug('SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS');
            // Indicates success.
            //return true;
            return null;
                     
         }
         else{
            // Indicates failure.
            //return false;
            return null;
         }
       }
   } 
}


I want userOrGroupId values to be stored in List...Please help how to correct
Ruwantha  LankathilakaRuwantha Lankathilaka
Id to list
T myId = 'someId';
list<T> mylist = new list<T>();
mylist.add(myId);




Vatsal KothariVatsal Kothari
Why are you assigning List to Id, instead replace below line
Id userOrGroupId=CurrentList;
with
Id userOrGroupId = UserInfo.getUserId();