2

What value do I set for the VersionData, PathOnClient and FirstPublishLocationId fields?

2 Answers 2

7
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.

-1

With this method the test fails

Error : System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD, URL must have a valid protocol: [ContentUrl] Adding contentUrl I get this other : System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Unable to complete operation.: []

The second error is only obtained in test classes, with execution from exsecute anonymous the DML insert works

Translated with www.DeepL.com/Translator (free version)

1
  • 1
    This strikes me more as a comment than an answer in its own right.
    – Derek F
    Apr 6, 2023 at 11:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .