You need to sign in to do that
Don't have an account?
PamSalesforce
Generate Text file using apex code
Hi,
I want to generate a text file using Apex code based on certain criteria.If anyone has implemented it or know how to do so .Please help me or post the code snippet.
Thanks.
You'll have to create a document record or an attachment record that will store your text data. Something like:
Document d = new Document(); d.Name = 'my text file'; String myContent = 'aabbcc'; d.Body = Blob.valueOf(myContent); d.ContentType = 'text/plain';
d.Type = 'txt';
insert d;
This will create a plain text file.
Hi,
Thanks for the reply. It worked.
I am new programming in Salesforce, so I do not know where to put this code, can you help me?
What I need is the following: when I click on a button I need to create a plane text file with a list of opportunities with very specific format and calculations. Any ideas? I really appreciate any help.
Check the above link
Cheers!!!
Regards,
Magulan D
Where can i check the new created document.
I checked it under documents but it was not there.
Am i missing something
d.folderId = <your folder id>; // Perhaps get from SOQL query to Documents by a special named folder.
// Better though to probably already HAVE a document you update periodically and just query it in SOQL, fetch and clone it to new name perhaps.
Also perhaps a 'global' org folder for some kinds of text documents might be good. Not sure if names need to be unique. But might be good to even update an existing text document - perhaps to allow download of some text file from Salesforce data you need to use for another purpose such as a static file on your website. We do something like that on our website. Not elegant but works. Sure something better and more automated exists but beyond our budget! And needs updating infrequently.
Document d = new Document();
d.Name = 'mytextfile.txt';
d.folderId = 'Temp'; // Error is: System.StringException: Invalid id: Temp
String myContent = 'aabbcc';
d.Body = Blob.valueOf(myContent);
d.ContentType = 'text/plain';
d.Type = 'txt';
insert d;
I need to extract actual data from one Salesforce Org to process it and move it to another Org. I can use APEX (with SOQL) to extract the data. I can process any data that I can get ahold of, but I'm having trouble getting it out to where I can proces it. Any tips would be appreciated.