You need to sign in to do that
Don't have an account?
saad mechiche alami
Error when insterting contentversion in a unit test
hello ,
I am currently runing a test where i need to query the contentversion object , in my test i have added the following lines :
however , when i run my test i get the following error :
Could you please help , many thanks
I am currently runing a test where i need to query the contentversion object , in my test i have added the following lines :
ContentVersion cv = new ContentVersion(contentdocumentid='069L00000000xEI'); insert cv;
however , when i run my test i get the following error :
Could you please help , many thanks
SystemDmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference
you cannot insert record like this, in your test class.
I assume you are new to test Classes
Read this Post : http://abhithetechknight.blogspot.in/2013/10/salesforce-test-class-basics.html
Regards,
Abhi Tripathi || Salesforce Certified Developer
Join My Blog : http://abhithetechknight.blogspot.in/
Thanks for you answer , and yes i am new to test classes , but i didn't know exactly what to do when i went to your tutorial , could you please elaborate ?
Thanks for your help :)
In my tutorial shows how to write the test class, in perfect manner.
You just need to create a dummy/ test record of the Object ContentVersion, for this go to the Object get the Required fields name, and those who satisfiy the condition in your class.
Like this one below , inserting Account object record in test class
//Insert Account
Account account = new Account( Name = 'Test', Website = 'CoudIsFuture', Phone=987654321);
insert account;
then you need to call you Apex Class controller, when you call that, test class will run the your controller class, with Testing Data.
Regards,
Abhi
When I run the test , i get the following error message:
FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: SetupOwnerId duplicates value on record with id: 00DL00000029G1m:
This is how its done
RecordType ContentRT = [select Id FROM RecordType WHERE Name='Sales Documents'];
ContentVersion testContentInsert =newContentVersion();
testContentInsert.ContentURL='http://www.google.com/';
testContentInsert.Title ='Google.com';
testContentInsert.RecordTypeId = ContentRT.Id;
insert testContentInsert;
And for user, you dont need to insert user, just use this UserInfo.getUserId(); method, this will get you the Id of current logged in User.
For more detail go for this link : https://developer.salesforce.com/forums/ForumsMain?id=906F00000008lcnIAA
If this answer helps you out, mark it as the best answer for the help of others.
Regards,
Abhi Tripathi || Salesforce Developer
Join My Blog : http://abhithetechknight.blogspot.in/