You need to sign in to do that
Don't have an account?
Balakumar 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-------------
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-------------
Correct the below line:
you are assigning List to Id, assign Id to userOrGroupId.
Thanks,
Vatsal
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
with