Questions tagged [dml]

Use this tag for questions about DML, the data manipulation language used in apex to perform operations as insert, update, delete, and restore data in the database.

Filter by
Sorted by
Tagged with
-2 votes
1 answer
28 views

Which is a better approach when updating records using batch class, to place it in execute or finish method?

Sorry but I am new to this and I just wander, do you think it is better to put all the millions of records inside the Map object which is process by the execute method, however the dml where the ...
Kato's user avatar
  • 1
5 votes
1 answer
119 views

Executing SOQL with User Mode and then DML with user Mode causing Exception

I couldn't find if SOQL and DML become interlinked when using WITH USER_MODE with SOQL and DML both in single transaction. I've below sample code to be triggered on a button from an LWC: @AuraEnabled ...
VarunC's user avatar
  • 5,900
1 vote
1 answer
55 views

I'm trying to bulkify the update of parent field based on child

I've written a trigger that is called when child record is inserted. I want the room(Parent) status to be updated to Occupied when the patient(Child) closure is set to false. Here's the code that I ...
Anirudh Navin's user avatar
0 votes
0 answers
18 views

Is there a work around for Creating multiple Parent and Child Records in a Single Statement Using Foreign Keys for the same SObject?

Im working on inserting multiple campaign records with a self-relationship. I was hoping to do this with one DML statement using the method described here: Link I know in the first paragraph it says ...
JEbert's user avatar
  • 11
0 votes
1 answer
51 views

Execute a batch with custom delay between each batch processing

I have a batch class which update the primary field on the quote object using batch size of 1. I need to do this in such a way that each batch is processed 30 seconds after the previous one(there ...
Tony Jude's user avatar
0 votes
1 answer
73 views

Do I need to Bulkify a DML inside a loop followed by end in Flows

I have a flow that only fires once per case record when an email-to-case comes in. It finds the email alias the case came through and assigned some values to the case record. I'm assessing a flow that ...
eHarazi's user avatar
  • 133
0 votes
0 answers
41 views

Check whether generic SObject is updateable

How do I check whether a generic SObject is updateable before DML operation. For standard and custom objects I know the general pattern is: Schema.sObjectType.Account.isUpdateable() However if I have ...
lhh13's user avatar
  • 41
0 votes
2 answers
141 views

Is DmlException is enough to catch all exceptions once wrapped for DML operation?

If we are using try catch only on DML operation part, where on catch block if only DmlException is used, then would it be enough to handle all possible errors occurs there or we also need to use ...
ItsVicky's user avatar
0 votes
2 answers
132 views

Is each chunk of a batch Apex class transaction gets shared among the trigger which runs before/after each DML of the batch?

If a batch apex is called with size say 200 (default size). And we have a DML operation (say update) in execute method of the batch. So the trigger which is set to run before/after update will share ...
ItsVicky's user avatar
1 vote
0 answers
116 views

How to handle DML exceptions in apex class WITH USER_MODE?

I'm trying to do a DML with user mode in apiVersion 58.0. I got "DML Exception" while inserting records without field permission and I got "SecurityException" while inserting ...
Senthil Kumar's user avatar
0 votes
2 answers
201 views

How do you pass a List of records to a batch apex class to be inserted?

I need to clone +10000 records. Yes,I'm aware of all of the limits and pitfalls associated with tying a trigger to a batch apex class. I'm accounting for it as only 1-2 people will be able to perform ...
Andrew Bloch's user avatar
1 vote
0 answers
35 views

Is there a good strategy to create complex nested SObjects in JavaScript for INSERT in Apex?

I'm implementing frequently Aura Components which must INSERT nested SObjects. As an example imagine you have this simplified data-model, references are lookups: ItemGroup__c Order__c OrderItem__c ...
Uwe Heim's user avatar
  • 28.3k
0 votes
0 answers
43 views

Update an Opportunity from a future callout method

I have a future method that posts data to an API, and IF the response2.getStatusCode() == 200, I would like to update a field on the opportunity. However, I get this error message: System.DmlException:...
potato46's user avatar
0 votes
1 answer
106 views

How to insert related record when DUPLICATES_DETECTED error is thrown from Salesforce Matching Rule?

I have a requirement to insert CampaignMembers whenever a duplicate Lead is identified. The duplicate check for all Leads of all Lead sources is handled via Standard Duplicate rule. This rule needs to ...
Apex Srinivas's user avatar
3 votes
1 answer
166 views

Is the User Mode approach to object and field security acceptable in a security review?

This Enforce User Mode for Database Operations looks by far the cleanest approach to implement the object and field-level security that is required to pass a Salesforce AppExchange Security Review. (...
Keith C's user avatar
  • 135k
-2 votes
1 answer
58 views

Pdf delete apex class [closed]

public class DocumentFileDeletionScheduler implements Schedulable { public void execute(SchedulableContext SC) { deleteOldFiles(); } public void deleteOldFiles() { ...
Csabikaaaa's user avatar
0 votes
0 answers
89 views

Get Update Count in Flow

I am using the Update Record element in a screen flow on the Specify conditions to identify records, and set fields individually setting. Is there a way to get a count of how many fields have been ...
Samantha Catania's user avatar
-1 votes
1 answer
27 views

update DML fails on contact......how to undo the update on Account and opportunity how do you implement that

Let's say in Apex you have multiple DML calls like update opportunity then you update Account and then you update contact, but it fails on contact so you want to undo the update on Account and ...
Jarvis's user avatar
  • 1
0 votes
0 answers
23 views

DML update not executing a large batch

I use a flow action to update Enrolment records. It works for a smaller batch size around 500. But it doesn't work for a larger batch like 1500 records. Debug log doesn't give any errors I broke the ...
Jay Weera's user avatar
  • 367
6 votes
3 answers
872 views

With USER_MODE - do we still need SOQL and DML libs?

As the Security model of Apex was leaky in the past, everybody who took - or as AppExchange Partners had to take - Security seriously was building or using libraries to enforce CRUD/FLS rules. The ...
Robert Sösemann's user avatar
2 votes
1 answer
401 views

Query: FLS Create issue while running checkmarx

I am running multiple classes and have some Query: FLS Create issues while running the checkmarx. I am really not knowing what they mean by this. I feel there is something simple but I cannot discern ...
Rahul Allada's user avatar
0 votes
1 answer
127 views

Is it safe to perform DMLs on related records in a `before delete` trigger?

I have two custom objects: Parent__c and Child__c. Parent__c has a field called ChildId__c which is a lookup on the Child__c object. When a Child__c record is deleted, I need to check if its Id ...
user369137's user avatar
0 votes
1 answer
171 views

Flow: MIXED_DML_OPERATION: DML operation

I am trying to automatically add a User's Default Team to an Account record when a Checkbox field on the Account record is checked to 'True'. I am using a Flow for this but am getting the following ...
sp2's user avatar
  • 67
1 vote
1 answer
233 views

Is List.isEmpty() necessary before a DML? [duplicate]

After working on many different code bases in Salesforce, I noticed that almost all developers check if a list is empty before doing a DML in order to avoid the unnecessary DML statement. Here's an ...
Harout Tatarian's user avatar
2 votes
1 answer
212 views

Cannot understand how the DML works in this code

I'm very new to apex and have just started learning. I was going through soql and came across this code that I'm not able to understand. Opportunity opp = [SELECT Id, Name FROM Opportunity WHERE Id = '...
PriyamSri28's user avatar
0 votes
2 answers
99 views

How to resolve too many SOQL after using Handler

I am using Trigger Handler for my Trigger. But still getting Too many SOQL on updateNoMaterialTool(); & Apex Class public class ProjectTriggerHandler { public Map<Id, Projects__c> ...
apz's user avatar
  • 5
0 votes
0 answers
113 views

Why am I not seeing records that are ostensibly inserted?

We're creating sample data when we spin up a scratch org, and we have just added a new join table between two existing tables, but the records don't seem to be actually inserting, although the code I'...
Chuck's user avatar
  • 877
0 votes
1 answer
33 views

APex code + DML operation works in dev console but doesn't work in scratch org

Was wondering if anyone has come across a similar issue: I'm trying to run some apex code to insert some records. The code doesn't seem to do anything when it's running in my scratch org but ...
srrc's user avatar
  • 5
1 vote
1 answer
152 views

Apex: I'm shoving all the DML into a queued job, but still get "Uncommited work pending"

So, I've heard that you cannot do any Callouts after a DML operation in Apex. So, I've designed my app this way (some pseudo-code follows): String url; List<Object> chunk; for (Integer page=1; ...
pilat's user avatar
  • 113
-2 votes
1 answer
151 views

Mass Contact Merge in Apex

I am trying to implement Mass merge of contacts in apex, Like uploading a CSV of multiple records which has would have details like retainable ID , duplicate contact Id etc., now I need to traverse ...
Kishore's user avatar
2 votes
2 answers
218 views

How can I dynamically upsert data in object

I want to upsert data in SF based on the selected columns by the user. I make HTTP callout to an external service and it returns the data. Then, I want to iterate over the each returned row and create ...
Stojchesky's user avatar
0 votes
1 answer
65 views

What are possible side effects of having fields on User object which should be frequently updated?

For integration purposes I would like to store a few custom fields on User object which should be updated 10-30 times per day. Is it considered a good practice to have such fields on User object? Are ...
Taras Shevchuk's user avatar
9 votes
2 answers
4k views

Any Reason NOT to Use FOR UPDATE?

I'm intrigued by the record locking issues that apex seems to allow so easily, and I've begun using FOR UPDATE where I can to mitigate them, but it seems so infrequently recommended in documentation. ...
number41's user avatar
  • 928
1 vote
1 answer
657 views

Send email and update field via Apex

I have apex class which is sending email and it works perfect, but together with email I want to change Case status and update a custom field. Inside for loop it works, but I don't want to exceed ...
NewToApex's user avatar
1 vote
0 answers
192 views

assigning role to user in apex leading to an error

I am trying to assign role to a user which i created and thats when I am getting this error : First exception on row 0 with id 0051k000008ykexAAA; first error: INVALID_CROSS_REFERENCE_KEY, invalid ...
Donal Shijan's user avatar
0 votes
1 answer
205 views

How to insert a record and input values from the master/parent information

I have a custom object named "Property Booking" where if the status changed to approved I have to create a record for my "Quotation" custom object. The tricky part here for me is I ...
Kejer's user avatar
  • 31
1 vote
0 answers
188 views

Best Data Layer structure in APEX when trying to follow proper SOC?

Backstory: I am currently working in a org that has not implemented proper SOC when it comes to our codebase. WE have some Trigger logic in the trigger files and most of our business logic intertwined ...
hmmm's user avatar
  • 11
0 votes
2 answers
630 views

Cleaner way to filter specific object ids from List <String>?

I am trying to update one of the related objects once the Account merge is completed. Database.MergeResult results = Database.merge(masterAcct, duplicateAcct, false); getUpdatedRelatedIds() method ...
SunnyG's user avatar
  • 421
0 votes
0 answers
177 views

How can I merge two Account custom objects into one without saving it to the database?

I have two saved account objects with the same Name and Email. Use case: I need to display these two objects' data to a user. The user selects one master object System merges whole non-master object ...
Alexander Belenov's user avatar
2 votes
2 answers
989 views

Is it possible to only update one field?

Is it possible to only update one field? List<Account> accountsFromSF = [SELECT Email_3__c from Account LIMIT 50]; for (Account acc : accountsFromSF){ acc.Email_3__c = '[email protected]'; } ...
LatDu's user avatar
  • 49
0 votes
1 answer
73 views

DML, SOQL and DML Sequence

Here is my scenario. Transaction 1: DML to update the Status field from Open to Closed on ABC record. Transaction 2: SOQL is performed to retrieve the ABC record before the above DML and updates the ...
Ram's user avatar
  • 5
0 votes
1 answer
321 views

Trigger not updating records - DML not being called(?)

I created a Trigger on Contact to update the associated Account each time a Contact is added or edited; the Trigger checks that each Contact in the Account has a valid credit card associated with it, ...
ElTttt's user avatar
  • 21
0 votes
2 answers
25 views

Are processes triggered if a field is set to the same value as it held before?

An Apex method is called and updates the StageName field from 'Approved' to 'Documentation.' It completes. A different Apex method is called and 'updates' the StageName field on the same record from '...
parkerbbrown's user avatar
0 votes
1 answer
424 views

Save Parent - Child Hierarchy for same SObject in a single DML

I want to save the lookup relationship for same object in a single DML statement, so basically I want to do something similar like this but for same Sobject, I have found one article here but this is ...
Akash Jain's user avatar
0 votes
0 answers
364 views

CPU Time Limit Exceeded Trying to Email 2000 Contacts

I have a junction object called AccountContactRelation which is linked to both the Contact and Account objects. I am trying to sort through the accounts, and for each one, add all the related ...
Austin Kelly's user avatar
1 vote
2 answers
539 views

CPU Timeout Error When Inserting 2000 Records through Apex

I created an apex class that is activated by a button for a 1 time use insert of about 2000 enrollment records. The code works with small amounts of records but when with the full 2000 I get a ...
Austin Kelly's user avatar
0 votes
1 answer
1k views

Get record field after Error in Database.Upsert

I'm upserting some records using Database.upsert, after that, I'm supposed to get the errors and pass them to a custom logger. The problem is, the way this class works, I'd need to get a field value ...
Julia de Lucca Ribeiro's user avatar
0 votes
0 answers
99 views

Enforce CRUD on single record DML statement

As the title suggests I am trying to enforce CRUD on a DML statement for a single record. I see the stripInaccessible() method takes in a list of sObjects. Is there an equivalent method for a single ...
Rory's user avatar
  • 389
6 votes
1 answer
221 views

Performing DML on empty list in a flow consumes governor limits but doing same in apex does not?

I tried to make a dml call on an empty list in an autolaunched flow and after looking into the debugs, I got to know that governor limits are getting consumed. But the same is not true when we perform ...
HG_'s user avatar
  • 125
0 votes
1 answer
338 views

Apex: Avoid DML when records are unchanged

I have noticed that many of the Apex triggers in my org update records even when there are no substantive changes to those records. For instance, consider a trigger that sets field values on an object ...
Matthew Souther's user avatar

1
2 3 4 5
11