While inserting attachment I am getting this error :
System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []
I double Checked my user is active and case is inserted properly.
@istest
public class Testclasstoinsertattachemnt{
static Account acc;
static Contact con;
static User newUser;
static Profile p;
Static testmethod void firstTestMethod()
{
loadata();
System.runAs(new User(Id = newUser.id))
{
RecordType rt = [select id,Name from RecordType where SobjectType='Case' and Name='General Customer Service' Limit 1];
Case cse=new Case();
cse.RecordTypeId=rt.id;
cse.AccountId=acc.id;
cse.ContactId=con.id;
insert cse;
System.assertNotEquals(null, cse.id);
***Attachment attach=new Attachment();
attach.Name='Unit Test Attachment';
Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body');
attach.body=bodyBlob;
attach.parentid=cse.Id;
insert attach;***
}
}
static void loadata()
{
insertAccount();
insertcontact();
insertUser();
}