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
John Biundo 9John Biundo 9 

Problem running SOQL query joining accounts and activityHistories

Hi developer community,

I am using node.js and the JSforce library.  I am trying to build a report using a few rules to identify the last valid activity on an account.  My SOQL query looks like this:
SELECT Id,
(SELECT OwnerId, ActivityDate, Status, ActivityType, ActivitySubtype, Subject, LastModifiedDate
FROM ActivityHistories
WHERE OwnerId IN (<list of ids>)
AND ActivityDate > <earliest-date>
AND ActivityDate < <latest-date>
ORDER BY ActivityDate desc)
FROM Account

This query sometimes runs to completion, but often terminates with the following error:
{ [Error: socket hang up] code: 'ECONNRESET' }

I have searched around and the best information I get seems to indicate that "this just happens sometimes".  I'm wondering if anyone has any more specific advice on troubleshooting or solving this problem.

A little experimentation seems to indicate that the query may be too complex (though again, it's odd that it only fails some (most) of the time).  This conclusion comes from the fact that simplifying the query, so that I simply get ALL the history for each account, seems to fail less (so far, it's succeeded every time, knock on wood).  This gives me a possible workaround, though I end up getting back a LOT more data and doing a lot more processing on the client than if I were to just get the subset I would get in the original SOQL shown above.  Plus, I would think that (aside form a possible longer "query optimization" phase, the more refined query would put less burden on the salesforce servers.

So long story short, I'd love to find a way to be able to process the above query in a reliable, robust way.

Any ideas, suggestions, etc would be very welcome!

FearNoneFearNone
john,

I don't think it is related to your soql query. The error means there is no event in the socket or connection within the timeout period. Probably the server is not responding because the http-request was probably destroyed along the way. For you to see what is wrong, you have to log every http-request ((request.getBody()) and check when it happens. Another option is try-catch and re-send the request like three times.
John Biundo 9John Biundo 9

Thank you.

I had a similar suspicion.  However, since I'm using a library, it's not straightforward to do the logging or try/catch that you suggest.  At the moment, I'm constrained from being able to peel open the library and operate at that level.  Unfortunately, the library doesn't seem to offer a way to do retries.  It's awkward to handle the retry at the app level given the way the API works, but I'm probably going to have to do that.  What keeps me from being too happy with that situation is that I am seeing the error repeat many times, with an occassional success.  So retrying will be pretty clunky.  That also makes me think there's something transient going on, or that it may be related to the complexity of the query.  The other thing that argues for complexity is that I've now tried a much simpler query and it seems to succeed repeatedly.  So in some sense, it does appear to be query-related.
 

Unfortunately, the simpler query requires a lot more processing on the client side (and sending a lot more data across the wire).
 

Sigh.  I didn't expect a silver bullet, but still hoping someone has been down this path before.  Thanks again for the input.