You need to sign in to do that
Don't have an account?
Abhishek Tiwari 25
manual sharing of Case Record
Insertion is done successfully but the record is not shared to the corresponding user.Please help
//This class is used for manual sharing of Case Record
public class ManualSharingRecord {
//This method takes two parameter first the record ID which you want to share
//and second one to whom you want to share the record(Either user or group)
public static Boolean successfullCaseSharing(ID recordId,ID userORGroup)
{
//create the object of caseshare object type
CaseShare csShare=new CaseShare();
//set the record level of sharing
csShare.CaseAccessLevel='edit';
//put the recordId which you want to share
csShare.CaseId=recordId;
system.debug('Record Id'+ csShare.CaseId);
//put the userORGroup id to whom you want to share the record
csShare.UserOrGroupId=userORGroup;
system.debug('userId'+csShare.UserOrGroupId);
csShare.RowCause=schema.caseShare.RowCause.manual;
Database.SaveResult save=Database.insert(csShare,false);
{
if(save.issuccess())
{
return true;
}
else
{
Database.Error err=save.getErrors()[0];
system.debug('Error'+save.getErrors()[0].getMessage());
if(err.getStatusCode()==statuscode.FIELD_FILTER_VALIDATION_EXCEPTION &&err.getMessage().contains('Accesslevel'))
{
return true;
}
else
{
return false;
}
}
}
}
}
case cs=new case(status='new',origin='phone');
insert cs;
ID recordId=cs.id;
User us=[select id from user where name like '%abc%'];
ID userORGroup=us.id;
boolean rs=ManualSharingRecord.successfullCaseSharing(recordId, userORGroup);
system.debug('result'+rs);
//This class is used for manual sharing of Case Record
public class ManualSharingRecord {
//This method takes two parameter first the record ID which you want to share
//and second one to whom you want to share the record(Either user or group)
public static Boolean successfullCaseSharing(ID recordId,ID userORGroup)
{
//create the object of caseshare object type
CaseShare csShare=new CaseShare();
//set the record level of sharing
csShare.CaseAccessLevel='edit';
//put the recordId which you want to share
csShare.CaseId=recordId;
system.debug('Record Id'+ csShare.CaseId);
//put the userORGroup id to whom you want to share the record
csShare.UserOrGroupId=userORGroup;
system.debug('userId'+csShare.UserOrGroupId);
csShare.RowCause=schema.caseShare.RowCause.manual;
Database.SaveResult save=Database.insert(csShare,false);
{
if(save.issuccess())
{
return true;
}
else
{
Database.Error err=save.getErrors()[0];
system.debug('Error'+save.getErrors()[0].getMessage());
if(err.getStatusCode()==statuscode.FIELD_FILTER_VALIDATION_EXCEPTION &&err.getMessage().contains('Accesslevel'))
{
return true;
}
else
{
return false;
}
}
}
}
}
case cs=new case(status='new',origin='phone');
insert cs;
ID recordId=cs.id;
User us=[select id from user where name like '%abc%'];
ID userORGroup=us.id;
boolean rs=ManualSharingRecord.successfullCaseSharing(recordId, userORGroup);
system.debug('result'+rs);
All Answers