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
3
votes
1answer
70 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 ...
1
vote
1answer
376 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 ...
0
votes
1answer
562 views

Confused about OrderProducts, OrderItems, and Products when making orders in test class

I'm making a test class that creates 5 orders and upon insert, I get the error that you need to add products to orders. I've got... List<Product2> clothProds = [SELECT Id FROM Product2 WHERE ...
1
vote
1answer
717 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. ...
-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
1answer
585 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 ...
7
votes
3answers
2k views

Can you perform DML operations from visualforce email templates?

Visualforce email templates allow you to include visualforce components with allowDML="true" but there doesn't appear to be any way to actually use DML. From the docs: You can't use data ...
0
votes
2answers
35 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 ...
5
votes
1answer
565 views

How to save large files in Salesforce with synchronous Apex?

I've created a Visualforce page that allows users to drag and drop files and have them uploaded to Salesforce and then displayed in a list immediately. To do so, my VF page sends the file in chunks ...
0
votes
0answers
23 views

Wrong DML process, update old values

I have updated one object records with wrong SOQL, how can I set all values as previous?
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 ...
0
votes
1answer
28 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 ...
2
votes
1answer
101 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
2answers
1k views

Error in apex class : System.LimitException: Too many DML rows: 10001

While I am trying to perform an upsert, I am getting this error : System.LimitException: Too many DML rows: 10001 at the line where the upsert statement is written. Code snippet : public class ...
2
votes
2answers
74 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 ...
0
votes
1answer
63 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
1answer
629 views

Update list values in an input text field

I have below code to update the input text field value for OUTCOME field from the User. My list update is failing to happen without throwing any exception. Please can someone help me here? My ...
3
votes
2answers
3k views

How to create thousands of records using batch apex

I have a scenario where I have to create 30000 contacts and 15,000 accounts (i.e. 2 contacts per account) in an org. I have been trying to do this by using batch apex but I still have error of "First ...
0
votes
0answers
357 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
135 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 ...
3
votes
2answers
563 views

DML Statement from @readonly page

I have a page like below <apex:page controller="testcontroller" readonly="true"> ........ </apex:page> For Making query to search data from million records i put @readonly I am sure it ...
1
vote
1answer
31 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 ...
25
votes
1answer
340 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, ...
0
votes
1answer
65 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: ...
11
votes
2answers
9k views

Generic SObject update pattern

Question I know that it is possible to update a generic of List<SObject>, But what is the best approach to generate that list without knowing the SObjectType, only the ids ? Sample: List<...
2
votes
3answers
202 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
38 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
31 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
38 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
54 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
285 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 ...
1
vote
2answers
51 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
2answers
219 views

Getting a Error on Case Id : Cannot specify id in an insert call

I am Getting an error on case id: cannot specify an id in an insert call, in Production but In the sandbox, it's work fine. could you, please help me. public with sharing class SSRACExtensions { ...
0
votes
3answers
74 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 ...
-3
votes
1answer
97 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 ...
0
votes
1answer
106 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 ...
20
votes
1answer
352 views

Email value is saved without parentheses (label) when using DML

When an email contains a label enclosed in parentheses, the value can be saved as typed in via SF UI. (Note: the email value "as is" is only seen when in Edit mode.) However, when the record is saved ...
4
votes
2answers
648 views

Performance issue when deleting Opportunity Line Items

I'm writing APEX REST API that creates OpportunityLineItem, Product2, Quote objects, updates Opportunity etc. based on data in JSON format received from external system. During testing I experienced ...
3
votes
1answer
144 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
48 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
35 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
98 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
144 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 ...
3
votes
2answers
697 views

DML Merge Fails INVALID_FIELD_FOR_INSERT_UPDATE

Question Is there something special you need to do before merging a record in apex to avoid an INVALID_FIELD_FOR_INSERT_UPDATE DML exceptions? I'm not actually setting these fields, so why does the ...
0
votes
0answers
46 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
76 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
76 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 ...
2
votes
1answer
42 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 ...
5
votes
1answer
453 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 ...
0
votes
1answer
28 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 ...