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
1
vote
3answers
34 views

How to cover Catch block in ApexUnitTest class when using DML statement in try body

I have some apex code, where I try to upsert a list of records: try { upsert recordList Accounts; } catch (DmlException e) { //do a loooot of stuff in order to provide a proper ...
0
votes
1answer
34 views

Insert JSON to salesforce

I have a JSON which I got from An outer System to Salesforce and I should eventually insert it to SF. { "AFTR0": [ { "AFTR1":"U", "AFTR2": "3dcda8f9213ad43aafe456ae489a158b", "...
0
votes
1answer
30 views

When method called 2 times: Uncommitted work pending. please commit or rollback before calling out

I have a method: public static CreateUpdateAPI (Account acc) { //do WS callout //perform DML } When i call it from Anonymous console with one Account it runs properly. But when i call the ...
0
votes
1answer
28 views

Visual Flow and Callout

I have a small problem with visual flow. I try to execute callout in flow through @InvocableMethod but before this callout, I do update a record(standard update action in Visual flow not in apex code(...
0
votes
0answers
21 views

Test.setMock working in Scratch org but not in sandbox Org

We have batch class used to make an API callout and doing Opportunity upsert DML operation in the Start method. Based on the opportunity's return value, we are making another API callout and doing ...
0
votes
1answer
18 views

Delete Scheduled Jobs using Apex in one go

I have More than 2500 Scheduled Jobs and i want to delete them but the issue is when i try system.abortJobId(jobId); on a list of job id which i fetched using soql it says not more than 150 DML ...
2
votes
1answer
45 views

Calling Apex method (to insert a record) imperatively from LWC JS

I want to insert a record (Log) whenever I open a record from a custom object. I want to know if it is possible to call an Apex method in LWC JS without @wire? I have a function in my Apex class to ...
0
votes
2answers
41 views

Illegal assignment from Sobject to Id : update a custom field

I have the following code Map<Id,SICo_VoucherConso__c> mVoucherConso = new Map<Id,SICo_VoucherConso__c>([SELECT Id, OwnerId FROM SICo_VoucherConso__c WHERE Id ='XXXXX' ]); Lead aLead = ...
0
votes
1answer
38 views

Apex page failing DML transaction

Let's have a very simple apex page: <apex:page controller="EventInsert" > <apex:form> <p>Event insertion test</p> <p>{!processParams}</p> <apex:...
0
votes
1answer
35 views

Two inserts in one trigger casues the second insert to fail

I have a triggerHandler on the Opportunity object which inserts other objects on afterInsert if it meets the criteria (Opportunity Line Item and Payment). The objects are added to a list before ...
3
votes
1answer
105 views

Test Class - System.CalloutException: You have uncommitted work pending - Platform Event

I am using platform events and in one of the after triggers I am calling a method in a class where the method is annotated with @Future(Callout=true) In my test method below I am doing some DML to ...
-3
votes
1answer
34 views

How to delete a table with code?

I want to delete a custom table using a code (not UI). Something like DELETE My_Object__c returns exception. Can I do that ?
0
votes
2answers
36 views

How to insert more than one record from visualforce page to custom object?

I want to insert the records in a custom object. The code is working fine when I insert one record at a time but when I am trying to insert more than one record on a same run one at a time than it is ...
0
votes
0answers
24 views

Wrong DML process, update old values

I have updated one object records with wrong SOQL, how can I set all values as previous?
0
votes
1answer
29 views

Cannot delete record using ID. Error: DML statement found null SObject at position 0

I am trying to delete a record using the recordID: final Boolean doNotAllowPartialSuccess = true; database.delete(recordId, doNotAllowPartialSuccess); I am getting this error: DML statement ...
4
votes
0answers
44 views

Should I be concerned about thousands of write operations per minute?

I am setting up a POC which would create a junction between User and Case (using Lookup relationships only). We would have 10k+ users each touching several records per hour, so we might expect this ...
2
votes
1answer
172 views

Getting 'FATAL_ERROR System.TypeException: DML operation INSERT not allowed on Group' on Apex Trigger

I am getting: "FATAL_ERROR|System.TypeException: DML operation INSERT not allowed on Group" error on an apex trigger (line 43) when I am logging in as any other user except System Admin. I am ...
0
votes
1answer
80 views

Multiple DML operation in the same try and catch block

I wanted to ask if there a problem doing upsert and delete in the same try-catch block, or maybe it better to separate them. for example : try { Schema.SObjectField oCode = Opportunity.Fields....
0
votes
0answers
417 views

NO_APPLICABLE_PROCESS, No applicable approval process was found, yet the criteria is met, no code change in years

Having an odd issue in our prod org recently. Code and approval items haven't changed, yet for some reason after our last monthly release we've been getting the no_applicable_process error here. The ...
0
votes
1answer
283 views

Insert & Update (Upsert) Multiple Records of Same SObject Type in Single Transaction

I have a scenario wherein I have two custom object records of the same type, ObjectX__c. I need to update object A (which exists) with a lookup to object B (which doesn't yet exist and is being ...
1
vote
1answer
38 views

Prevent parallel executions of flow element

I have a screen flow that is included in a lightning record page. At some point it executes a callout to an external system. The scenario that I would need to avoid is to have multiple users open the ...
0
votes
1answer
80 views

Unable to merge contacts (fails to update field)

I use the native merge functionality to glue two duplicate contacts together programmatically: merge target source; Yet this invokes the following error: 12:06:49:251 USER_DEBUG [46]|DEBUG|DML_e: ...
25
votes
1answer
364 views

Why am I double charged on DML limits in a process builder?

This question is a follow-up from another question where the accepted answer states that for each Update Records action in a process, following limits are consumed: As you can therefore conclude, ...
2
votes
3answers
212 views

What does it mean when an external ID field follows a DML Statement?

Today I was working on some Apex code that was delivered to us by a third party contractor to our organization, and ran into a line of code that I have never seen before: upsert certsToUpsert.values()...
0
votes
1answer
39 views

DML update Task whatID

we use taskMatch to find the records needed to be updated, how can we update them? //dml below List<Account> allaccounts = [SELECT phone from Account WHERE Status_Reason__c = 'Active - ...
1
vote
1answer
34 views

Visual Force DML Not allowed

I am getting a DML not allowed error from my visual force page. The error is caused by an update and insert call in a method which seems to be the constructor. Can someone give me a solution to how ...
0
votes
0answers
41 views

Test Classes: MIXED_DML_OPERATION

Via Process Builder, Is there anything I can do in my process that could stop this from occurring? Error Message: System.EmailException: SendEmail failed. First exception on row 0; first error: ...
0
votes
1answer
66 views

Anonymous Execution: System.LimitException: Too Many DML Statements: 151

I am trying to run the following piece of code to update all Accounts without a primary contact. This method will look through all contacts of an account and assign the first contact it reads to be ...
2
votes
2answers
97 views

How do I assign Delegated Administration via DML or query it via SOQL?

I would like to assign power-users to be admins of Delegated Administration groups a bit easier than the click-through manual process. Is there a way I can query admins via SOQL or assign admins via ...
1
vote
2answers
54 views

Cover Error Handling on Test Class

I am having an issue where I have a trigger that rolls up data from contacts to an account. This was working fine with no issues until we added a managed package app that is constantly checking and ...
0
votes
3answers
99 views

Choose which records to insert/update in Apex Trigger

I have a trigger that is triggered before update or before insert for(CustomerProfile__c cp : listCustomerProfiles){ if(...){ cp.addError('A Customer Profile record has ...
0
votes
1answer
128 views

Difference between lock row and Record Currently Unavailable

Good day everyone, Last time,I encounter this error saying : UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record. I try to search a possible fix and I found that adding 'For ...
-3
votes
1answer
101 views

Anyone can optimized this code for better explanation and easy to understand? [closed]

The function of this apex code is when Account has no Contacts the first contact created become the primary contact and when there is existing primary contact it cannot assign a other primary contact ...
3
votes
1answer
158 views

Uncommitted Work Pending - Working around DML then WebService

I am working with Salesforce Connect and I am storing my token and expiration times in an encrypted custom setting. My connection is through the client credentials Oauth 2 flow. When a user queries ...
0
votes
1answer
52 views

UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record during Insert

Good day Everyone, I know there are lots of questions which is similar with my question. But I still post this because I did not find any case which is similar with mine. I am working with some ...
3
votes
2answers
38 views

Why does default Profile based default record types not work in DML Upserts?

I have an integration which inserts Person Account records into my Salesforce org. Sometimes the integration doesn't include a LastName (if the user hasn't provided one) which causes the integration ...
0
votes
1answer
132 views

Org Data Update just after the sandbox refresh in FullCopy Sandbox

Our requirement is to update customer's email ID and Phone# to an invalid value in FullCopy sandbox during the sandbox refresh. Using PostSandbox refresh apex class we are updating the User email and ...
3
votes
0answers
169 views

INSUFFICIENT_ACCESS_OR_READONLY - Cannot Delete QuoteLineItem

17 QuoteLineItem records were loaded into the org via Dataloader with the incorrect product2id listed. When trying to delete the records in the GUI while logged in as a System Administrator, the ...
0
votes
0answers
52 views

Is it possible to do two DML operations in a single trigger?

I have a custom object called Junction__c with lookups to Custom__c, and Case. In the data model, Custom__c is also a child of Case. There is a validation rule to ensure that any Custom__c record ...
0
votes
1answer
91 views

Mixed_DML_Operation for one User Update method, but not another. Unclear why

I have a Contact Trigger Handler that, after update, checks to see if some fields (Email or Team) were changed, and if they were, it updates the fields on the Contact's Community User record. These ...
1
vote
1answer
85 views

First error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY

Use-case: Trying to update a text field after an insert. Also trying to get the Record Name field(text field) to a specific format using another auto generated field and a picklist field. Simple ...
5
votes
1answer
536 views

Exceptions and DML

It was to my understanding that when you throw an exception all previous operations are rolled back. When an exception occurs, code execution halts and any DML operations that were processed ...
2
votes
1answer
43 views

Failure setting lookups in triggers when upserting multiple records of different types very quickly

I have an integration app that polls records of different types from an internal database every few seconds and upserts them into Salesforce. I have two pollers that run independently from one another ...
0
votes
1answer
29 views

DML result refresh

When I click button, method's setToApprove() action is beginning. But first lines of method when terf_mr_status='approved' and terf_mr_approveddate=TODAY_VALUE doesn't appears inside of generated pdf ...
1
vote
2answers
224 views

Does Database.SaveResult, Database.DeleteResult, etc. implement a public interface?

The various DML operations (insert, update, delete, etc.) all return results with very similar methods and properties. It is not uncommon, as a developer, that I should want to handle these results ...
0
votes
1answer
227 views

Saving data from HTTP response in a 'for' loop

Background: We're building an app, that will be periodically calling out to external web service to retrieve data in XML which we need to parse and save to Salesforce. So far: We have an Apex Job ...
-2
votes
2answers
122 views

How to insert Lookup field value in a Trigger?

I am trying to build a after insert trigger on Contract object. Whenever user will create a Contract record trigger will generate/insert record of other object called Dim2. Dim2 have a lookup with ...
0
votes
2answers
445 views

Trigger error - Too many DML rows: 10001

I have tried to optimize the code, but still it throws the error: Too many DML rows: 10001 Below is my code: if(setAccID != null && !setAccID.isEmpty()) { list<Custom__c&...
0
votes
2answers
144 views

How many times a database.rollback executes?

Below is the code I am executing. Account a = new Account(Name = 'xxx'); insert a; System.assertEquals(null, [SELECT AccountNumber FROM Account WHERE Id = :a.Id]. ...
0
votes
3answers
165 views

DML vs REST API call to create a record

This question came to my mind out of curiosity. I have an apex class in which I want to create a record. I can use a simple insert DML operation to create it. Although I know that REST API services ...