3

I work with a Salesforce dev team (as a program manager), and on our last project we have an HTML-formatted email that comes in from an internal system that needs to be parsed to extract certain details. The information is contained within a series of tables in the HTML and the devs were not able to fully complete the work according to the requirements (meaning some of the data had to be populated manually in the Salesforce case by an admin, who has to look at the email).

The other day I was playing around with Python and BeautifulSoup, and found that I could quite easily extract all of the information from the email in a structured format, transforming them into Dataframes that are easy to work with.

We have another phase of the project coming up that requires us to parse even more info from the email (same format), and I'm trying to evaluate whether or not this can even be done in Salesforce.

Is there a library for Apex that allows you to parse HTML, similar to Python's BeautifulSoup (could even be a bit more low-level)? I don't want to run into a problem mid-stream where we determine that the devs are not able to meet the requirements, so my alternative is to build a web service on AWS that Salesforce can call, passing in HTML and getting back a well-formatted response to use.

Edit: Sample HTML that the team is having a hard time processing (the bulk of this data is needed for the next project).

<table class="table2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <tbody>
      <tr>
          <th>Line Number</th>
          <th>ID</th>
          <th>SKU</th>
          <th>Description</th>
          <th>Qty</th>
          <th>Price</th>
          <th>Currency</th>
          <th>Interval</th>
          <th>Term</th>
          <th>Line Type</th>
          <th>Change Type</th>
      </tr>
      <tr>
          <td>1.1</td>
          <td>A100000001</td>
          <td>SOME-SKU-GOES-HERE</td>
          <td>User License</td>
          <td>1</td>
          <td>100</td>
          <td>USD</td>
          <td>Monthly</td>
          <td>1MTH</td>
          <td>Initial</td>
          <td>New</td>
     </tr>
     <tr>
          <td>2.1</td>
          <td>A100000001</td>
          <td>SOME-OTHER-SKU-GOES-HERE</td>
          <td>Storage</td>
          <td>3</td>
          <td>300</td>
          <td>USD</td>
          <td>Monthly</td>
          <td>1MTH</td>
          <td>Initial</td>
          <td>New</td>
     </tr>
  </tbody>
  </table>
4
  • I've updated my answer, your HTML should be pretty straight forward to parse. What specifically did your developers say was not possible?
    – gNerb
    Dec 12, 2017 at 20:59
  • I didn't ask for details, but for instance they could not extract the ID column (the line repeats and they have to take the unique value and plug it into a field on the case, comma separated if there are multiple unique IDs). I will be meeting with a dev manager before kicking off the next project, so I will bring this up to him as well to make sure the team can handle it, I just wanted to get some input from the Salesforce community first, as my experience with the tools from a development standpoint is limited to SOQL queries.
    – Ryan
    Dec 12, 2017 at 21:02
  • Barring some piece of information that the developer's can provide, I don't see why they couldn't parse it reliably.
    – gNerb
    Dec 12, 2017 at 21:07
  • Yeah this is a feature for which they should build their own tool. Sounds like a team not familiar with DRY/SOC concepts.
    – Adrian Larson
    Dec 12, 2017 at 21:11

1 Answer 1

2

Many languages, while not natively built to parse html, do come with tools to parse XML. In the past, I've used these tools to parse HTML documents (since the structure is very simmilar). I'm not 100% positive if salesforce xml tools work on html; though, the fact that this is the first article that pops up when you google "sfdc parse html" is a good indicator that it might be a good way to go.

The biggest issue I can see is finding the data in the HTML as well as ensuring the HTML is strictly structured (proper open/close tags and proper tag nesting). As long as the data is structured predictably, it shouldn't be an issue.

I don't see any reason your table can't be parsed fairly easily based on your sample.

2
  • Thanks, updated with sample HTML code. The table I included is the one that is critical for the next phase of the project and the team was not able to extract data from it in a reliable manner.
    – Ryan
    Dec 12, 2017 at 20:59
  • 9
    Let me know if you want me to write the code, 100$ an hour :)
    – gNerb
    Dec 12, 2017 at 21:06

You must log in to answer this question.

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