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
0
votes
0answers
33 views

How to solve error: you have uncommitted work pending. please commit or rollback before calling out [duplicate]

I am receiving this error: you have uncommitted work pending. please commit or rollback before calling out. What do I need to change in below code to resolve this? The error is on bold line in code ...
2
votes
2answers
2k 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
668 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 ...
8
votes
4answers
23k views

How to avoid DML Insert/Update Limit of 10,000 rows when running anonymous apex?

Is there any way to bulkify an insert/update operation performed from anonymous apex? For instance, if I have a script that builds a list of 15,000 records that need to be updated, is there any way ...
0
votes
1answer
477 views

Deleting all public groups from Org

We have an utility which imports all data from one org to another, this results in creating public groups every time import operation is carried out. Is there any way we can perform delete operation ...
1
vote
1answer
15 views

Is “Transfer Record” necessary to update OwnerId?

Under the hood, transferring a record is just updating the value of OwnerId. Transfer Record is necessary to do this through the layout. But is it necessary for DML? That is, if we run the following ...
22
votes
1answer
428 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 ...
0
votes
1answer
986 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 ...
116
votes
2answers
6k views

Any reason to skip DML on empty lists?

In parts of my code I have DML statements with an if around to only do the DML if the list is not empty: if( !recordsToUpdate.isEmpty() ) { update recordsToUpdate; } Couldn't I just write? ...
0
votes
0answers
12 views

Scope of SavePoint variable

I am trying to upsert parent records in a class as well as it calls another class which inserts child records. I am trying to add Savepoint to rollback the transaction and prevent parent record from ...
1
vote
1answer
49 views

Does creating a record type worsen DML performance on the object?

If you have an object with no records types versus one with a couple, is performance affected in terms of DML insertion? I experienced a change in DML performance after creating multiple record types ...
0
votes
1answer
1k 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 ...
0
votes
0answers
23 views

Created User unable to update opportunity stage due to error: insufficient_access_on_cross_reference_entity

I am writing a test class in which I have created user with profile =finance and role =finance.I used System.runAs(createdUser) to update opportunity stage.But getting following error ...... ...
21
votes
4answers
25k views

Database.SaveResult - how to get the Id of the record where Update failed?

I am using Database.SaveResult and Database.update(..., false) for the very first time and ask myself how to get the Id of the record where a dml has failed. I expected Database.SaveResult.getId()` ...
1
vote
1answer
27 views

DML in loop in a batch process

I was working on something entirely different, wrote a test code and found a gap in my knowledge. Hoping someone can point out where and why my understanding is wrong. I have a batch job, it queries ...
2
votes
1answer
41 views

Dynamically Insert parent child records in a single DML

I'm trying to insert contact and account records in a single DML. In my case I don't want to use the . operator Instead, I'm using the put operator to insert records. Account acc=new Account(Name='...
0
votes
1answer
550 views

I want send email alert to a public group every week with a html email template in apex class

but the time of setting template in my apex target object id is required and this block accept only 15 digit id so how can i retive ever member user id global class EmailSenderfriday implements ...
5
votes
1answer
938 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 ...
8
votes
2answers
490 views

GroupMember locking

For out project we need to put users into correct public groups. This happens in a trigger when a user's contact is updated, depending on some of the fields there we decided where to put a user. The ...
0
votes
1answer
48 views

ApeX multiple related sObjects Insert in single DML call

I have a bach Apex process Which will Insert in 3 object with related fields. Account, Contact, and Program (Custom Object) Acccount is related to Muliple Contact and a Contact is related to ...
0
votes
2answers
33 views

Without Sharing class failed on validation rule

Custom apex trigger initiates a change on opportunity(from within a without sharing static class). Which than apply DML update operation. Validation rule fails on opportunity. The validation rule ...
2
votes
2answers
239 views

How to update Latitude/Longitude in salesforce Organization object?

I got DML not allowed on Organization error when I try to update the object in apex code. I checked the documentation. It looks like Organization object can be updated. Does anyone know why the ...
0
votes
1answer
50 views

Code to update related records using External Id and Database class in Apex by ignoring wrongly specified external ids?

I have the following code below Data_Source__c datasource=new Data_Source__c(External_Id__c='SQLServer'); Table__c table=new Table__c(External_Id__c='Employee'); Column__c column =new ...
2
votes
2answers
4k views

Deployment failure: bad value for restricted picklist field

I am facing a weird issue during production deployment. I have created a picklist field (which is not exist in Production) Lead_Assignment_Status__c which is by-default restricted and values are New ...
-2
votes
2answers
401 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
21 views

Return fields not specified while inserting a record

I have a simple insert method in a test data factory class. However, I noticed that in the returning record, only the Id and Name are returned. I'm assuming the name is returned because I have ...
0
votes
0answers
37 views

need to update Auth provider from apex class

I have requirement where i need to update authProvider Execute as User from Apex code. I have wirtten a code but i am facing below error on update **DML operation Update not allowed on AuthProvider** ...
0
votes
1answer
75 views

You have uncommitted work pending. Please commit or rollback before calling out even if we put DML in future method

I know as per documentation, we cannot perform DML and then callouts from apex class. In my scenario, I have a callout then I am performing a DML which is placed inside a future method and again ...
1
vote
1answer
175 views

savepoints and rollbacks with future methods - does it rollback changes from other transactions

According to salesforce docs on savepoints and rollbacks: Apex gives you the ability to generate a savepoint , that is, a point in the request that specifies the state of the database at that time. ...
0
votes
1answer
46 views

How can I find problematic records in a dml action?

Let's assume I have a list of 100 new records that I want to insert, 10 of these records are missing information which will result in DML exception. Is there a way for me to create a list and include ...
1
vote
0answers
64 views

Process Builder - Record Update & Number of DML

In a process builder, if you have a node with multiple "immediate actions" for updating records, do those all get processed as one dml on that record in question or do they each count as distinct ...
0
votes
1answer
43 views

DML in @Future called from Trigger in Batch

I have a after insert trigger on an object that calls a @future method to do a callout to an external system. If the callout fails I want it to update the original object. I am batching up 100 at a ...
1
vote
0answers
199 views

Possible Workaround to perform DML when cacheable is true

According to documentation, it is recommended to make wired apex calls from LWC cached, by adding the following annotation to the controller's method: @AuraEnabled(cacheable=true) However, adding ...
0
votes
1answer
151 views

Creating Utility Classes - Batching sObject list

My goal is to create a reusable and scalable utility class that can perform different DML operations. I'm aware of the 10,000 DML processed records limit so I'd like to check if the list is greater ...
1
vote
1answer
29 views

Persisting Logs in Managed Packages

What is the best practice to persist logs from apex classes, batch jobs, and controllers? We are still in the development stage so we haven't considered LMA. We tried to store it in a custom object. ...
1
vote
3answers
56 views

APEX Transaction's count

Let's we have some class public class FooTest { public void goAhead() { someOne(); } private void someOne() { /// awesome DML for(integer i = 0 ; i < 10; i++) { anotherOne(); ...
4
votes
4answers
20k views

Invalid conversion from runtime type LIST<ANY> to MAP<String,ANY>

I'm trying to make a webcall to pull data from an external webservice. After that call I would like to insert my data that comes in the form of JSON into my custom object called Company. However I am ...
2
votes
2answers
100 views

Can we delete authProvider from APEX

I am trying to delete an authProvider from APEX. authProvider provider = [SELECT Id FROM authProvider WHERE DeveloperName = 'a_known_string']; delete provider; I get an error that states DML ...
2
votes
1answer
50 views

Does Test.testSandboxPostCopyScript Actually Run DML?

I have a SandboxPostCopy class where I am updating some User fields (example: changing the email to remove the '.invalid' and setting Profiles) where the Users to be updated are controlled by Custom ...
0
votes
1answer
134 views

Pagination REST API, Multiple request, DML End problem

I was share 1 more question before in my profile, and i changed my apex code, My old question. Now i wrote my callout function in batch apex class, My problem is when i want to send second request ...
0
votes
0answers
36 views

DML operation inside a loop

I need to make an apex class that needs to upsert hierarchically three times the same object. Currently, the only way I found to do this was this way: private void upsertLevels() { for(List<...
2
votes
2answers
2k views

Getting Issues while creating User

I am trying to create an User but I am getting error as follows: 18:46:26:307 FATAL_ERROR System.DmlException: Insert failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, portal ...
2
votes
1answer
767 views

How to create trigger for DatedConversionRate object

We're using multicurrency in our project. DatedConversionRate has been updating every day by external process. The requirenment is to update CurrencyType records with most relevant rates. At the ...
1
vote
3answers
158 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
45 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
60 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
214 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
34 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
25 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 ...
3
votes
1answer
811 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 ...

1
2 3 4 5
9