You need to sign in to do that
Don't have an account?

How to retrive archived document from contentdocument object ?
HI All ,
In batch class they have wriiten query like this
global Database.querylocator start(Database.BatchableContext BC)
{
query='select id,IsArchived from ContentDocument where IsArchived=true ALL ROWS';
return Database.getQueryLocator(query);
}
But while executing from test class it will not return any records, So it will not execute "execute" method from batch class.
Please refer the below test class :
Test.startTest();
string before = 'Testing base 64 encode';
Blob beforeblob = Blob.valueOf(before);
ContentVersion cv = new ContentVersion();
cv.title = 'test content trigger';
cv.PathOnClient ='test';
cv.VersionData =beforeblob;
insert cv;
ContentVersion testContent = [SELECT id, ContentDocumentId FROM ContentVersion where Id = :cv.Id];
ContentWorkspace testWorkspace = [SELECT Id FROM ContentWorkspace limit 1];
ContentWorkspaceDoc newWorkspaceDoc =new ContentWorkspaceDoc();
newWorkspaceDoc.ContentWorkspaceId = testWorkspace.Id;
newWorkspaceDoc.ContentDocumentId = testContent.ContentDocumentId;
insert newWorkspaceDoc;
ContentDocument cd = [select id, IsArchived from contentdocument where id=:testcontent.contentdocumentid limit 1];
cd.IsArchived = true;
//update cd;
System.debug('Cd Size ' + cd);
System.debug('DDDDDDD ' + cd.IsArchived);
BatchContentArchived objDocs = new BatchContentArchived();
objDocs.query='select id,IsArchived from ContentDocument where IsArchived=false limit 2 ALL ROWS';
/*objDocs.query='select id,title from ContentVersion limit 2 ALL ROWS';*/
ID batchprocessid = Database.executeBatch(objDocs);
Test.stopTest();
-------------------------------------------------------------------------------------------------------------------------------------
Can anyone please let me know how to cover the code ????
Thanks in Advance ....
Hi,
Please modify your code as following:
1. In Batch Class
global Database.querylocator start(Database.BatchableContext BC)
{
if(Test.isRunningTest()){
query='select id,IsArchived from ContentDocument ALLROWS where IsArchived=true LIMIT 1';
}else{
query='select id,IsArchived from ContentDocument where IsArchived=true ALLROWS';
}
return Database.getQueryLocator(query);
}
2. In Test Class write SeeAllData(True) just above test class definition as follows:
and
BatchContentArchived objDocs = new BatchContentArchived();
ID batchprocessid = Database.executeBatch(objDocs);
/**If this post helps you, please throw a kudos**/
Thanks
Grazitti
All Answers
Hi,
Please modify your code as following:
1. In Batch Class
global Database.querylocator start(Database.BatchableContext BC)
{
if(Test.isRunningTest()){
query='select id,IsArchived from ContentDocument ALLROWS where IsArchived=true LIMIT 1';
}else{
query='select id,IsArchived from ContentDocument where IsArchived=true ALLROWS';
}
return Database.getQueryLocator(query);
}
2. In Test Class write SeeAllData(True) just above test class definition as follows:
and
BatchContentArchived objDocs = new BatchContentArchived();
ID batchprocessid = Database.executeBatch(objDocs);
/**If this post helps you, please throw a kudos**/
Thanks
Grazitti
HI Thanks for your reply,
Still execute method is not covered :(
Seems the query will not return any records ... Can u please modify the query ... as per suggestion i have included (seealldata=true) also...
By the way,
If i m trying to execute the below query in devloper console , then also it will not return any records. coz once the document is getting archived the record will record will be remove from the contentdocument object.
select id,IsArchived from ContentDocument ALLROWS where IsArchived=true LIMIT 1
But if am trying to execute same query using apex code it will return records. Any idea ?
Hi All,
Issue has been resolved, Using below query
global Database.querylocator start(Database.BatchableContext BC)
{
if(Test.isRunningTest()){
query='select id,IsArchived from ContentDocument where IsArchived=true LIMIT 1 ALL ROWS';
}else{
query='select id,IsArchived from ContentDocument where IsArchived=true ALL ROWS';
}
return Database.getQueryLocator(query);
}
Thanks