how to insert content version in test class

  • what value set for versionData
  • pathOnClient
  • FirstPublishLocationId
public ID setupContent(){ 
RecordType ContentRT = [select Id FROM RecordType WHERE Name='Sales Documents'];
 ContentVersion testContentInsert =newContentVersion(); 
 testContentInsert.ContentURL='<a target="_blank" href="http://www.google.com/';" rel="nofollow">http://www.google.com/';</a> 
 testContentInsert.Title ='Google.com'; 
 testContentInsert.RecordTypeId = ContentRT.Id; 
 insert testContentInsert; 

 ContentVersion testContent = [SELECT ContentDocumentId FROM ContentVersion where Id = :testContentInsert.Id]; 
 ContentWorkspace testWorkspace = [SELECT Id FROM ContentWorkspace WHERE Name='Opportunity Documents ']; 

 ContentWorkspaceDoc newWorkspaceDoc =newContentWorkspaceDoc(); 
 newWorkspaceDoc.ContentWorkspaceId = testWorkspace.Id; 
 newWorkspaceDoc.ContentDocumentId = testContent.ContentDocumentId; 
 insert newWorkspaceDoc;

 testContent.iPad_Content_Views__c =0; 
 update testContent;

 return testContentInsert.Id; 

Please use this sample code to create contentversion in test cl ass.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.