Stack Exchange Network

Stack Exchange network consists of 174 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

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.

0
votes
0answers
22 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
28 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
votes
1answer
28 views

Too many DML operations

I am trying to call a managed package method (I am passing a user list as parameters) which calls batch class from finish method of a batch class and it is throwing a error for too many dml rows. Is ...
1
vote
1answer
31 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 ...
3
votes
1answer
74 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
30 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
20 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 ...
0
votes
2answers
27 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
54 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
48 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
57 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
23 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
39 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
22 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
21 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
53 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
55 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
70 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
158 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
41 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
123 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
45 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
37 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
52 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
133 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
97 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
35 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
82 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
89 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 ...
0
votes
1answer
70 views

Order of execution and multiple DML in a single transaction

I have a trigger that has multiple DML operations in a single transaction. I also only want the transaction to run once. With the order of execution I need to put some sort of "first run" logic on it....
1
vote
1answer
44 views

Cross-Object Formula Fields and Performance

I have been unable to find official documentation about this. But I wonder, is there a documented "upper bound" count at which platform performance degradation occurs due to a proliferation of cross-...
0
votes
2answers
55 views

Issue inserting a ContactShare object with Database.SaveResult

I need to insert a new ContactShare object in apex. Here is a sample of the code I have : Map<String, Id> mapUserRole = new Map<String, Id>(); for(UserRole ur : lRoles){ ...
0
votes
1answer
27 views

Schedule Iteration of Webservice Callouts

I have an endpoint I am getting updates from, but the only arguments the end point takes is two date parameters. To keep the heap size down, I am limited to about a date range of three months. I am ...
0
votes
2answers
156 views

Delete related records in trigger before delete

I have installed NPSP in my organisation. I also created a custom object named as "Opportunity Group(OppGroup__c)" that will group my opportunities. What I want is that during deletion of an "...
1
vote
1answer
67 views

How do I mass delete Territory2 records in Apex?

I have a list of Territory2 records. All of them are from the deepest level of my territory hierarchy. When I attempt to save some apex to Salesforce that would delete this list of records, I'm ...
0
votes
1answer
165 views

Why trigger.old cannot be operated on DML statements? [duplicate]

I am new to salesforce so correct me wherever I am wrong. I believe DML statements can work on already saved records so it makes sense that trigger.new cannot be operated with DML statements but ...
0
votes
1answer
44 views

New Record creation on custom object - An internal server error has occurred - Error ID: 1803087759-275934 (-1232085095)

I am trying to create a new record on a custom object which has record types and save the record. I get the below error An internal server error has occurred An error has occurred while ...
0
votes
1answer
21 views

Testing future methods: data scope

I'm trying to test my @future method, in which I'm performing Custom Object update, but when I'm asserting values, updated object field equals null. Could it be a problem with method scope? I'm adding ...
0
votes
1answer
164 views

In test class Topic and Topic assignment creation isnot working

Iam creating dummy records for Topic and its assignment.Topic is creating successfully Topic assignment shows error Below error: Failed to assign topic to null. Please ensure you have permissions ...
3
votes
1answer
61 views

@ReadOnly won't work when using Aggregate SOQL

I've created this function with @ReadOnly in a Visualforce that is Working fine (1.000.000 records limit): @readonly webservice static List<BI_BR_Atendimento_Comercial_e_Carteira__c> ...
0
votes
1answer
150 views

System.ListException: Before Insert or Upsert list must not have two identically equal elements for my DML operation [duplicate]

I have below code where I try to insert an SObject and getting an error as mentioned in subject. I have tried to fetch newly inserted records of say Object1, and putting them in Object2 lookup field ...
2
votes
2answers
130 views

System.calloutException: You have uncommitted work pending. CallOut+Asynchrnous DML + Callout

I went through some questions here like System.CalloutException: You have uncommitted work pending which provide answer where the callout can be split into asynchronous way. Based on the information ...
0
votes
1answer
107 views

Work Order Line Item not being inserted in test class

I have a piece of code in my apex class which queries a work order with the corresponding Case ID. I have written the corresponding test method for this class, as follows: Case c = new Case(); ...
0
votes
1answer
282 views

Edit properties of a Visualforce Email Template in apex so the email sent through Messaging.sendEmail() will have the most recent data in it

I have a visualforce email template that displays the list of Opportunity records that are populated using a visualforce component. I'm using this email template in a schedulable class. The HTML ...
3
votes
1answer
58 views

In a Salesforce Number field, how much performance impact does its length have?

Does a 2,2 field perform noticeably better than a 16,2 if the same value (e.g. 24.45) is stored in the context of Apex DML Formulas whatever I forgot, please add To clarify: This question ...
-2
votes
1answer
116 views

What is the execution time spent in the database for an DML or SOQL or SOSL?

Is it possible to find the execution time for a DML or SOQL or SOSL? What are the factors on which the execution time of these queries depend?
-1
votes
1answer
150 views

Test REQUIRED_FIELD_MISSING even though field is set?

@isTest private class Test_ordinefermo { @isTest static void test_newAttachment(){ test.startTest(); Opportunity op= new Opportunity(); op.Name= 'abc'; ...
7
votes
1answer
33 views

From inside a Salesforce packaging org, how do you query the list of created versions for a managed package?

I have, a Salesforce packaging org, it contains a managed package with a namespace. I need to be able to query the list of created versions for that managed package. I am aware that a user can go ...
1
vote
2answers
284 views

Why does setting DMLOptions in the before event not work?

I need to trigger case assignment rules on update from a lightning page. I referred to this link to do that via trigger. After a little modification, I called the below method in before update event, ...
0
votes
0answers
20 views

Updating a value in the list to be updated before and after the dml operation

Im trying to update child record in parent after trigger, where i need to update this child's boolean (MA_Campaign_Qty_Boolean__c) as part of restricting some validation in child's trigger for this ...