+ Start a Discussion
NageshTNageshT 

How to read property file using Apex language on force.com

HI,

 

I am Nagesh. I am new dev for Force.com.

I want to find, How can we read files using apex language on force.com platform.

 

Is there any way to read property files???

 

I have tried following ways to read file but i havn't get success.

1) create simple file 'Temp.properties' in staticResource in force IDE. and try to populate it from StaticResource Table.

2) Using file app upload a file and try to populate it from Document Table.

In both case, No rows generated.

 

Please help me to solve this problem.

Send mail on::

nagesh.takle@gmail.com

 

Thanks in advanced

--Nagesh

Best Answer chosen by Admin (Salesforce Developers) 
NageshTNageshT

HI

 

Thanks for your help.

 

I got the solution for my problem.

 

I have created StaticResources on force.com (Upload properties file having Key=Value pair data), Which stores the file content in StaticResource table on Force.com. I have created Properties class like java on Force.com, Which load the file content from table to cache and creates Key=Value Map.

 

In this way, I have achieve to read properties file on force.com using apex code.

 

Thank you very much for your great help Mr. Mariagus.

Please send me your mail Id on nagesh.takle@gslab.com for communication.

I hope you will help me in future also !!!

 

Thanks

--Nagesh

All Answers

mariagusmariagus

Hi,

 

Please, add to this thread also the other information that you gave me in my post, so everybody would be able to read all the information.

 

You can create a document easyly:

 

String docBody = 'my text';

Document dFormat = new Document();
dFormat.Name = 'My document'
dFormat.Body = Blob.valueOf(docBody );
dFormat.ContentType = 'text/plain';
dFormat.Type = 'txt';
dFormat.Description = 'My description';
dFormat.IsInternalUseOnly = false;
dFormat.IsPublic = true;
dFormat.Keywords = 'My Document';
dFormat.FolderId = folderId;
insert dFormat;

Also attachments are easy to create and likely documents. I've never created a Static Resource in apex, and actually, I'm not sure if it is possible.

 

I know SalesForce provide some methods to read JSON files, and somecolleagues created their onw class to read csv files.

 

Regarding your requirement of reading the property (Key = Value pair format) I've never do it, but can you use the document.KeyWords?

 

I hope this helps. If does, clicks the solution button.

NageshTNageshT

HI,

 

Thanks for your help.

 

I had used this. This is quite useful. For this, I have to create file text before and then add it into Document table.

 

But my requirement is::

I want to read remote file using Apex code and store it into Document table.

 

Second part is done with your help. But Reading file from remote location is not complete.

 

Please help me ASAP.

 

Thanks

--Nagesh

mariagusmariagus

Hi,

 

I'm sorry but I've never read a file from a remote place. Has this place an API with methods that you can use to download the file? Or can you create your own access to this with REST, for instance?

 

What I have done is to create a VF page with a Search File button, and use the content of the file. Not sure if this can help you, but just in case, this link is quite useful: Search File button and read a file

 

I hope this helps.

NageshTNageshT

HI

 

Thanks for your help.

 

I got the solution for my problem.

 

I have created StaticResources on force.com (Upload properties file having Key=Value pair data), Which stores the file content in StaticResource table on Force.com. I have created Properties class like java on Force.com, Which load the file content from table to cache and creates Key=Value Map.

 

In this way, I have achieve to read properties file on force.com using apex code.

 

Thank you very much for your great help Mr. Mariagus.

Please send me your mail Id on nagesh.takle@gslab.com for communication.

I hope you will help me in future also !!!

 

Thanks

--Nagesh

This was selected as the best answer
ChakriChakri

 

 

 

hi ,

 

can u please share the sample code and more details for this.

 

Thanks,

Chakravarthy.

Ankush SamudralaAnkush Samudrala

Can you please share the sample code which have you done...?

 

I have a requirement to develop a dictionary application,for that purpose i need to know the readaing/retriving data form propertiece file...for this purpose i have decided to gowith propertiece file.

 

can u plz share the sample code..

 

Thank you.

Sab L 10Sab L 10
We have custom settings object in SF, which is equivalent to using properties in JAVA. Pls refer related question in http://stackoverflow.com/questions/15947561/how-to-store-single-values-in-salesforce. Hope it helps.