-1

I need to process xls files and create records from them, automatically, in APEX of flow. I know there is no native salesforce solution for it, what is the best way of doing so?

1
  • 2
    xls or xlsx? Recent developments in Apex make it theoretically possible to handle the latter, if the files are small enough.
    – sfdcfox
    Commented Mar 27 at 15:43

1 Answer 1

3

Tl;dr: The best way to do this in Salesforce is to not do it in Salesforce

The best way is probably to use a third party service instead of Salesforce (flows, Apex, etc...)

Salesforce isn't a platform for general computing, and the governor limits make it difficult to work with all but the most basic of file formats (and xls/xlsx are complex beasts) even if you find/make some Apex that is able to parse them.

xlsx, for example, is basically a fancy .zip file, and Zippex can unzip that, but anything larger than about 34 kB (suggested by issue #161 on the github repo) runs into the CPU limit; and that's just getting at the xml, not even parsing the xml.

Even as little as 500 rows with 4 integer columns, 3 email columns, and 3 general string columns is likely going to exceed that.

Using a dataweave script in Apex may be a better approach than trying to do something with Apex alone, but that specifically cannot handle xlsx. It does, however, appear to support the older xls format (which is a binary format).

Even if you can use Dataweave (or the Compression.ZipReader in developer preview at time of writing mentioned by sfdcfox), the CPU and Heap Space governor limits will dictate the size of data you can feasibly work with. Going off-platform (or possibly to Heroku) is going to mean you have a lot fewer restrictions.

1: There was some research done into making the blob->int conversion faster with pr #20, but it doesn't look like that work ever made it into a release. Even if you found a fork that did use that, it's at most an 18x speedup, meaning you'd be able to unzip up to about a 620 kB file. That's still without processing it into records, though.

2
  • 1
    +1, but note that Apex now has native ZIP support. I haven't tested it for performance, but I think Dom.Document + Compression.ZipReader could probably process decently larger files than Zippex could handle.
    – sfdcfox
    Commented Mar 27 at 16:23
  • @sfdcfox oh no, now I'm somewhat interested. Assuming the unzip part is handled, it looks relatively straightforward to get meaningful data out of a simple xlsx. ./xl/worksheets/sheetX.xml, <sheetData> is 1 level down from the root, with rows/cells/values, and cells reference data from ./xl/sharedStrings.xml when we see the attribute/value t="s" in the cell element.
    – Derek F
    Commented Mar 27 at 16:57

You must log in to answer this question.

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