Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

1
vote
1answer
32 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
34 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
126 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
46 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
24 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
34 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: ...
24
votes
1answer
281 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
193 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
33 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
27 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
33 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
40 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
43 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
43 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
57 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
69 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
95 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
95 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
43 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
34 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
52 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
100 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
41 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
62 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
57 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
271 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
39 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
26 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
118 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
151 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
71 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
278 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
89 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
80 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 ...
2
votes
0answers
31 views

Apex sharing insert

We are now investigating some performance issues for the client and trying to speed up their processes. One of the time consuming parts is apex sharing that we have there. I am pretty sure that some ...
2
votes
1answer
28 views

Query related to DML Example for AccountWrapper

I am trying to implement below example shown in screenshot :- I want to check that for records where checkbox is selected, name field should not be null, then only insertion should happen, but name ...
2
votes
2answers
126 views

DML Insert List of Child Records and Junction Records in a single DML Statement

I've 3 Custom Objects (List) : List <C1> (Child) fields : Id, Name List <C2> (Child) fields : Id, Name List <C3> (Junction) fields : IdC1, IdC2, Name I was able to get C1 IDS ...
3
votes
1answer
60 views

Is it possible to grab the external Ids of the records that failed in database.insert

We are trying to insert some records into database by using Database.SaveResult. It is dynamically typed Sobjects as in the following code: List<SObject> castInsertRecords = (List<...
5
votes
0answers
96 views

No DML_END Issue

Yet another "what gives" question. I have a custom object that is updated upon a button click on a VisualForce Page. I can see in my debug logs that the object has been updated. But when I refresh ...
2
votes
2answers
211 views

Delete an SObject by knowing only Id

Is it possible to delete an SObject by knowing only Id? Here is what I found: Id del = '003S00000099999'; // whatever ID you are deleting Contact ct = new Contact(Id = del); delete ct; So, is it ...
0
votes
1answer
117 views

How to create a Record on Junction Object Using Apex?

Could anyone please tell me apex code for server side contoller about how to create a record on Junction Object(Detail side of Master Detail Relationship). Say There are two objects Products__c and ...
0
votes
0answers
356 views

How to Add Records From a Lightning Datatable To a Group

I have two Objects PDCN and PDCN Group. I have created a junction Object PDCNJunc also with Master-Detail Relationship to both PDCN and PDCN Group. There is a lightning datatable which shows list of ...
0
votes
3answers
97 views

Insert 2 objects (parent and child) at a time (over 200 records)

I have over 200 records, and I need to insert 2 lists. Work's records are created too fast and can't take a customField from still not inserted Case. If insert 1 per time - Error: Too many DML ...
0
votes
1answer
39 views

DML exception on unrelated object [duplicate]

Situation is I have simple mechanism, which sends messages from apex trigger to our processing server. My trigger framework creates object for every change and save it to the WorkflowQueue__c. There ...
0
votes
1answer
162 views

DML Not Allowed

I am getting an error when trying to kick off an approval flow programatically. I have seen others run into a similar issue with the DML not allowed. Why is DML not allowed in Constructor? I tried ...
0
votes
0answers
468 views

Error creating CPQ - SBQQ__QuoteLine__c Object

I am trying to test a controller that I have written which queries SBQQ__QuoteLine__c objects. I am running into an error which is preventing me from inserting the object during the @TestSetup method. ...
1
vote
1answer
111 views

move all child records from one account to another efficiently

I did a bit of searching and didn't come up with anything so apologies if this is a duplicate, but - Situation: I am looking for a way to migrate all related object records from one (bad) account ...
0
votes
1answer
36 views

Convert Objecttype for DML update

Trying to update a child object from a parent object using the Objecttype returned form a getReferenceTo() but getting errors as Method does not exist or incorrect signature: How can I convert the ...
1
vote
2answers
175 views

Does an update called in an @future method count as being in the same transaction as the method that called it?

I am on occasion seeing a "You have uncommitted work pending. Please commit or rollback before calling out" error during a sequence of callouts that are part of the same transaction. So basically the ...
0
votes
1answer
204 views

DML requires SObject or SObject list type: String (line 31)

For the below code I got this error on line 31 i.e upsert z; global class updatezone implements Database.Batchable < sObject > , Database.stateful { string query; string z; //Start ...