function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Felix Jong Seok ChaeFelix Jong Seok Chae 

Text Scanner In Apex

In Java, we can easily create a list/set to collect strings in a text file with Scanner object.
What is the equivalent way of scanning a text file in Apex?
Best Answer chosen by Felix Jong Seok Chae
HARSHIL U PARIKHHARSHIL U PARIKH
Try to look at this question if this helps,

https://developer.salesforce.com/forums/?id=906F00000008z7EIAQ

All Answers

HARSHIL U PARIKHHARSHIL U PARIKH
In Apex there are multiple types of collections exists.

1) List
List<String> strList = New List<String>();

2) Set
Set<ID> IdSet = New Set<Id>();

3) Map
Map<String, Integer> stateToZipMap = New Map<String, Integer>();

In addition, you can also use SObject (Salesforce Object) as one of the data type!
e.g.,
      List<Account> acts = New List<Account>();

 
Felix Jong Seok ChaeFelix Jong Seok Chae
Thank you for your response, but I would like to know of how we can "read" strings from a txt file like scanner object does in java.
 
HARSHIL U PARIKHHARSHIL U PARIKH
Try to look at this question if this helps,

https://developer.salesforce.com/forums/?id=906F00000008z7EIAQ
This was selected as the best answer
Felix Jong Seok ChaeFelix Jong Seok Chae
Thank you.
In the link you provided, OP said a text file is in Document. Is he talking about a document object(table) in salesforce or a directory? 
If it is the former one, how do I upload a text file in Document object first?
HARSHIL U PARIKHHARSHIL U PARIKH
Yes Felix,

Document is a standard object in salesforce. It has its own tab out of the box just like how Account object has.

If you don't have "Document" obejct tab already then You can Click + button on salesforce UI Search for Document object and then new button to create a document record.