How can I update a few records in the database where a specific DML operation is currently not allowed?
I am currently working on a critical database system where a specific DML operation is currently not allowed because of ongoing maintenance. One of my colleagues urgently needs to update a few records in the database so that he can fix the issue that is impacting a live application. How can I handle this particular scenario, ensuring both the integrity of the database and the immediate resolution of the issue?
In the context of Salesforce, in this scenario, you can suggest your colleague create a temporary staging table in which he can make the necessary updates. This particular approach would ensure that the DML operation should be directly on the main table. Here is a step-by-step guide given:-
Create a staging table
Insert data into the staging table
The colleague can insert the required updates into the staging table:-
INSERT INTO temp_updates (id, column_to_update, new_value)
VALUES (1, ‘column_name’, ‘new_value’),
(2, ‘column_name’, ‘new_value’),
…
Apply updates by using a non-DML operation
You can apply the updates from the staging table in the main table by using a non-DML Operation such as a MERGE statement.
MERGE INTO main_table AS target
USING temp_updates AS source
ON target.id = source.id
WHEN MATCHED THEN UPDATE SET target.column_to_update = source.new_value;
Verify and cleanup
After applying the updates try to ensure that the changes are correct and then clean up by dropping the staging table:-
DROP TABLE temp_updates;