0

I'm implementing my invoice parser app. I have service which I've written in python,it parses invoice PDF that comes from LWC file uploader and returns JSON which apex parses and stores extracted fields from there as Opportunity objects. As all files in SF stored in Files Home, I need to query them (service does the query). Now my query gets only one file

querySOQL = """
SELECT ContentDocumentId, Title, FileExtension, VersionData 
FROM ContentVersion 
WHERE FileExtension LIKE '%pdf%' AND IsLatest=True
ORDER BY CreatedDate DESC LIMIT 1
"""

But I want my service to parse as many files as user uploaded. What I am trying to do is

SELECT ContentDocumentId, Title, FileExtension, VersionData, CreatedDate
FROM ContentVersion
WHERE CreatedDate = TODAY AND
FileExtension LIKE '%pdf%'
AND IsLatest=TRUE ORDER BY CreatedDate DESC 

It gets all files that were uploaded during the current day but how to query all files uploaded in past several minutes range? If you have any ideas help me please. Thank you in advance.

1 Answer 1

2

The documentation on Date Formats and Date Literals is a good place to start.

That said, while Salesforce does give us literals like TODAY, and N_DAYS_AGO:<integer>, they do not provide literals for time intervals (so no N_MINUTES_AGO:<integer>).

That means that if you want to look at seconds, minutes, or hours, you're going to have to construct the appropriate ISO 8601 datetime. E.g. something like 2022-11-15T13:56:00Z or 2022-11-15T08:46:00-05:00.

Salesforce stores datetimes in UTC (a.k.a. "Zulu time", which is where that "Z" comes from) and then converts to local time and format on display (based on the locale in the user's profile). So if you want to query for times in your own timezone, then you need to drop the 'Z' and add your UTC offset (positive or negative).

Generating that datetime is something to handle in your Python script. In Apex, it'd be something like Datetime.now().addMinutes(-15).format('YYYY-MM-DD\'T\'HH:mm:ss-05:00');

1
  • OK now I get it. Thanks for your response.
    – user120280
    Commented Nov 15, 2022 at 15:15

You must log in to answer this question.