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
13 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
33 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
51 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
32 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
25 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
38 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
60 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
149 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
28 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
44 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(); ...
2
votes
2answers
66 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
36 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
59 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<...
1
vote
3answers
84 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
42 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
51 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
181 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
23 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
24 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
473 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
49 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
41 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
38 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
200 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
35 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
45 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
45 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
408 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
154 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
679 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
462 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 ...
2
votes
1answer
70 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
123 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
510 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
265 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
41 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
38 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
48 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
106 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 ...
3
votes
1answer
171 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
62 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
271 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
183 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
108 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
178 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
57 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
43 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 ...

1
2 3 4 5
9