SalesForce and JSON

Nerding, SalesForce on March 5th, 2009 2 Comments

I found this open source library, and quickly realized that I needed some examples of how to use it.  Finding none, anywhere on the internet, I struggled for about two hours before learning that you can chain together class names to reach internal classes.

It wouldn’t be a SalesForce blog post without me bitching about something, so here it is:  I was originally using an HTTP callout to an XML web service (namely, the Twitter API).  But lo and behold, some returned pages of 100 followers were over the 100k limit for callouts.  I looked around, but this limit, like all the others, is not negotiable.  So, I refactored the XML parsing functions to use JSONObject, and after some debugging was able to parse some of the JSON.  I then found I needed to add a few lines of code to the JSONObject.JSONTokener.nextString(string quote) function, because it wasn’t handling escaped quotes like \”this\”.

Can you guess what happened then?  That’s right, because JSON functions are not available in Apex, all the extra overhead of JSONObject brought me over the 200k line script limit.  So if you’re reading this, SalesForce, here’s why I was unable to finish a modest but useful entry to your AppExchange.

Your 100kB callout limit is unreasonably small – not everyone can control their data sources.  Oh yeah, not to mention it isn’t currently documented (grr!).

Your lack of JSON support requires a bunch of extra hoops to jump through.

Your 200,000 line limit on script statements is reasonable, except when the other limitations of your platform require building or including large custom code structures.

In summary, I’ve spent about a month developing this, and now I’m pissed.  As far as I can tell, there’s no way to retrieve and parse a full page of Twitter followers, unless I’m willing to massively rewrite JSONObject – with regular rexpressions, perhaps.  Even then, it might still not work for some other reason.

Look, I know that maintaining a massive enterprise system like SalesForce is very, very difficult, and that the limits exist so rambunctious developers don’t bring it down.  But every time I read glowing sales copy that says anything is possible, I’ll get a little grumpier, because in at least this case, it isn’t.

P.S.  Since posting this Jeff Douglas has written about JSON in SalesForce twice.

Note, the code sample I had here keeps disappearing (using ‘Code Snippet’ plugin) – I’ll get it back in some form soon.

$suSQL = Array
(
‘type’  =>’mysql’,
‘db’      =>’igloocommercial’,
‘host’  =>’:/tmp/mysql.sock’,
‘port’  =>”,
‘user’  =>’root’,
‘pswd’  =>’sample’,
);
}

Tags: , ,

2 Responses to “SalesForce and JSON”

  1. Jeremy Kraybill says:

    I’d definitely suggest both posting IdeaExchange ideas for lifting or extending each of these limits, as well as submitting formal SF support requests. These actually do carry weight with SF. You can also hype them up on the SF discussion boards to get more votes.

    One thing I learned from a senior SF person is that all VisualForce ideas in particular get serious consideration from the team each release, because there are so few of them submitted. I submitted one and it was implemented within a couple weeks just in front of the release cutoff.

Leave a Reply