You need to sign in to do that
Don't have an account?
Jonathan Wolff 7
Rewrite ContentVersion class to create working pdf
Hello, I made Anonymous window in my dev console to test a apex class to create a text file and save it in files. It does work fine, but when I replace .txt with .pdf, the pdf is created but when I open it, I got an error (I use edge browser, maybe this is the problem)
Could you show me what to change about the code to create a working pdf :)
Could you show me what to change about the code to create a working pdf :)
try{ string textFile = 'This is test data'; ContentVersion DocVer = New ContentVersion(); docVer.ContentLocation = 'S'; docVer.PathOnClient= 'Demo.txt'; docver.Title= 'Demo.txt'; Blob textData = Blob.valueOf(textFile); docver.VersionData = textData; insert DocVer; string Versid =[select contentDocumentid from contentVersion where id =: DocVer.id].contentDocumentid; ContentDocumentLink Doclink = New ContentDocumentLink(); doclink.ContentDocumentId =Versid; doclink.linkedEntityId = ''; doclink.sharetype = 'I'; doclink.visibility = 'AllUsers'; insert doclink; } catch(exception ex) { system.debug(ex.getmessage()); }