I have Account.txt file to create Account records from Static Resource,how can i read Account.txt file in visualforce page?

<apex:page >
  <apex:form >
  <apex:commandButton value="Get Data From Txt"/>

and I have data in the Account.txt as below:

sobject-'Account' Name='ram' Name='hari'

1 Answer 1


One of the solution could be you can query on Static Resource object and get the body of that resource and then Process logic accordingly.

StaticResource srObject = [select id,body from StaticResource Where Name = 'SOME RESOURCE NAME'];
String contents = srObject.body.toString();
for(String line:contents.split('\n')) {
  // Process Logic Here

You can also check this useful blog

  • 1:53:01.0 (52364002)|USER_DEBUG|[7]|DEBUG|contents sobject-'Account' Name='ram' Name='hari' 11:53:01.0 (523862,,how can i pull out Sobject and Name colum,,can u please tel me how to do it,,
    – Satya
    Commented Aug 10, 2016 at 6:24
  • i had gone gone through your blog,still i didnot get an idea how to create Account records from Account.txt file
    – Satya
    Commented Aug 10, 2016 at 6:37
  • if u can help how to create records using getting the object name from the .txt will be very help full for me
    – Satya
    Commented Aug 10, 2016 at 8:07

You must log in to answer this question.

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