Salesforce Get a list of all opportunities which are new, updated or deleted since a given date using api - salesforce

I am trying to receive a list of all opportunities that are created/updated/deleted since a given date. When I run query: SELECT Id FROM Opportunity WHERE SystemModStamp >= '2022-09-20' AND isDeleted = TRUE ALL ROWS I get a response stating "message": "ALL ROWS not allowed in this context", "errorCode": "MALFORMED_QUERY".
Going over the salesforce documentation I found out using queryAll() api method we can also get the opportunities which are created/updated/deleted. But I am not able to find an example of how to use this api. Any help in this direction would be highly appreciated.
Salesforce queryAll documentation: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_queryall.htm

Have you tried using queryAll instead of query? Start with
/services/data/v54.0/queryAll?q=SELECT+Id,+Name,+isDeleted,+StageName+FROM+Opportunity+ORDER+BY+isDeleted+DESC+LIMIT+20
and experiment, remove the ORDER BY, put filter by date...
SELECT Id, Name, isDeleted
FROM Opportunity
WHERE LastModifiedDate >2022-09-01T00:00:00Z
There's also dedicated "data replication API" which you can use to get opportunities updated / deleted in given time window (imagine an oppty that's edited 3 times in September, once in October - the last modified date will happily say October, how would you retrieve the fact it was touched in September too?). It'll give you just the IDs, you'd have to collect them and send the query for actual data - but it's something.

Related

delleting bulk comment_type="order_note" from woocommerce DB

wocoommerce after each change status on an order sends comments that types are "order_note" in database.
how can i remove all or disable some of it.
they are 36000 rows in my database now.
some of the order status note comments are not important for us.
picture
36000 rows actually is not that big of a deal. WooCommerce has many performance and database structure related imperfections you should keep in mind, this is probably not one of them.
Anyway...
WooCommerce stores it's order notes inside wp_comments table, with the comment type set as order_note.
You can safely delete these rows as you wish. For example if you want to delete order notes from year 2021 and earlier (and keep only those from 2022), you can run this query:
DELETE FROM `wp_comments` WHERE `comment_type` = 'order_note' AND `comment_date` <= '2021-12-31';
If you want to delete order notes for specific order IDs (e.g. for order 12345 and older), you can do it the similar way:
DELETE FROM `wp_comments` WHERE `comment_type` = 'order_note' AND `comment_post_ID` <= 12345;
You can implement this SQL query as a PHP script using $wpdb, e.g. to automatically delete order notes, that had been created last year or earlier:
global $wpdb;
// Delete all order notes created last year and earlier
$delete_before = date( 'Y-m-d', strtotime( 'last year December 31st' ) );
$wpdb->query($wpdb->prepare("DELETE FROM `wp_comments` WHERE `comment_type` = 'order_note' AND `comment_date` <= %s;", $delete_before));
You can implement such script as a function and trigger it automatically, either with wp_schedule_event() or as a standard CRON job.

soql to find data modified in last 1 hour

i am using salesforce SOQL to find the data that was modified in last 1 hour using the below query
SELECT name FROM Lead WHERE LastModifiedDate = TODAY AND HOUR_IN_DAY(LastModifiedDate) > 1
this does not work reliably though. I have seen some solutions where it expects to create a custom formula field and then use it to query. Is it possible to do by just fixing the above query?
you can find the Leads that were modified in the last hour like so:
DateTime dt = System.Now().addHours(-1);
List<Account> accLst = [SELECT Name FROM Lead WHERE Lead.LastModifiedDate>=:dt];
You can check this article to understand more - How to get modified records in the last hour using SOQL

Data Collection Report

I Use DataCollection on SSMA\Object Explorer\Management\DataCollection in 2 day ago.
But each time I get report from Data Collection, no data available to display. The following image is a sample Server Activity History report of data collection reports.
this query will confirm if a snapshot was actually taken on that date: (change the name of your Data Management Warehouse)
SELECT [snapshot_time_id]
,[snapshot_time]
FROM [DATA_MANAGEMENT_WAREHOUSE].[core].[snapshot_timetable_internal]
WHERE CAST(snapshot_time AS DATE) = CAST('2014-06-19' AS DATE)
if there is no result set, run without the filter to confirm when the snapshots first started and what the interval is.
SELECT [snapshot_time_id]
,[snapshot_time]
FROM [DATA_MANAGEMENT_WAREHOUSE].[core].[snapshot_timetable_internal]
Then, if you have no results, check to see if the Agent service is on. I believe it could be related to one of these things.
EDIT: added another query to check for wait stats.
SELECT [wait_type]
,[waiting_tasks_count]
,[wait_time_ms]
,[signal_wait_time_ms]
,[collection_time]
,[snapshot_id]
FROM [DATA_MANAGEMENT_WAREHOUSE].[snapshots].[os_wait_stats]

strange appengine query result

What am I doing wrong in this query?
SELECT * FROM TreatmentPlanDetails
WHERE
accountId = 'ag5zfmRvbW9kZW50d2ViMnIRCxIIQWNjb3VudHMYtcjdAQw' AND
status = 'done' AND
category = 'chirurgia orale' AND
setDoneCalendarEventStartTimestamp >= [timestamp for 6 june 2012] AND
setDoneCalendarEventStartTimestamp <= [timestamp for 11 june 2012] AND
deleteStatus = 'notDeleted'
ORDER BY setDoneCalendarEventStartTimestamp ASC
I am not getting any record and I am sure there are records meeting the where clause conditions. To get the correct records I have to widen the timestamp interval by 1 millisecond. Is it normal? Furthermore, if I modify this query by removing the category filter, I am getting the correct results. This is definitely weird.
I also asked on google groups, but I got no answer. Anyway, for details:
https://groups.google.com/forum/?fromgroups#!searchin/google-appengine/query/google-appengine/ixPIvmhCS3g/d4OP91yTkrEJ
Let's talk specifically about creating timestamps to go into the query. What code are you using to create the timestamp record? Apparently that's important, because fuzzing with it a little bit affects the query. It may be relevant that in the datastore, timestamps are recorded as integers representing posix timestamps with microseconds, i.e. the number of microseconds since 1/1/1970 UTC (not counting leap seconds). It's also relevant that dates (i.e. without a time) are represented as midnight, i.e. the earliest time on that day. But please show us the exact code. (It may also be important to show the actual content of the record that you're attempting to retrieve.)
An aside that is not specific to your question: Entity property names count as part of your storage quota. If this is going to be a huge dataset, you might pay more $$ than you'd like for property names like setDoneCalendarEventStartTimestamp.
Because you write :
if I modify this query by removing the category filter, I am getting
the correct results
this probably means that the category was not indexed at the time you write the matching records to the data store. You have to re-write your records to the data store if you want them added to the newly created index.

Query timeout, depending on dates

we have some user forms that include a 'period' menu, where the user can request the server to return data for a specific date range, such as "Purchase Orders issued between the 1st and the 10th of October 2008".
The logic is then to add "on the fly" the date range to the original sql query and requery the data. The syntax of the filter added to the query is:
WHERE myDate >=dateMin and myDate <= dateMax
or, if the original query already has a filter clause:
WHERE <original filter> AND (myDate >=dateMin and myDate <= dateMax)
With both dateMin and dateMax in the 'YYYYMMDD' format.
We began yesterday to get some query timeouts for our 'errors' form, which specifically requests our 'errors' table. After some tests, it appeared this timeout issue was happening only when data was requested from the Error table and for the month of October. The same query, with the very same syntax (only dateMin and dateMax values are changed) when sent with another range (september, august, or whatever) on the same table, did not time out! This happened either when sent from the app or directly from the Sql Server Management Studio.
We avoided the timeout problem by adding an index on the errorDate column of the Errors Table (we should have done this before, I know, but we forgot!). We still have a query delay which is 4 to 5 times longer than the standard one when requesting on October's dates!
We have been trying to query on smaller intervalls, like "first 15 days", "last 15 days". The "first 15 days" query takes longer than the last 15 days one, which is still significantly slower than queries on other periods.
I feel like the problem is only avoided, not really solved, and I still feel quite disturbed by this behaviour. Has anyone ever noticed such weird things, or does anyone have any idea about what is happening?
I recommend you update your statistics and rebuild the indexes.
Also, note that you can use BETWEEN, e.g.:
WHERE myDate BETWEEN dateMin and dateMax

Resources