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
14 views

Way to partially filter inserted records in before trigger

Let's say we have bulk DML that is gonna insert a couple of records. In before trigger we want to check all new records and insert only correct (matched) ones. Should we use another DML inside the ...
0
votes
1answer
17 views

Block an insert call or convert it to upsert in trigger

Zapier connects our forms to our Salesforce instance. However, Zapier does not provide an upsert call as a way to insert a record, only insert and update. This means we have to use up more of our ...
-1
votes
1answer
15 views

To check if there is any opportunity present in account. If yes do nothing, else we have to create at least one opportunity under that account

trigger atleastoneopp on Account (before update) { List<Opportunity> oppList = new List<Opportunity>(); Map<id, Account> m = new Map<id, Account>(); // Select query before for ...
0
votes
0answers
24 views

Can't delete accountShare record, even though RowCause is manual

This code here fails: List<AccountShare> existingShares = [SELECT Id FROM AccountShare WHERE RowCause = 'Manual' ...
-1
votes
1answer
15 views

I am updating a child record in a parent record's before update, which directly changes a rollup summary field on parent record of that child record

This causes a SELF_REFERENCE_FROM_TRIGGER error. Is there a workaround for this type of scenario? I have outlined the trigger and object situation below: Object Info: Parent | Fields: RollupStage__c, ...
0
votes
1answer
20 views

Commit updates made in flow from Insert Trigger

I'm having some issues with a trigger which is calling a flow to do some updates to the records being inserted via the trigger. I've set up a flow which takes a collection of leads as an input ...
0
votes
1answer
19 views

is it ok to update a record based on a field even if the said field is not updated with new value?

I have a class that computes tax code for a given account and updates the tax code field with the new calculated value. Now irrespective of whether the tax code generated is different from the ...
0
votes
1answer
26 views

Upsert DML Operation

Consider the below code. I thought the way upsert DML works is that if it sees that there is a new record with matching key (here in this case there is already an account with Name = Acme and ...
0
votes
0answers
36 views

Managed Package Platform Event and DML by unlicensed user

I am working on a managed package which will be licensed per user. The package will include two features: Feature A: Global Apex Class that publishes platform events (also packaged). Trigger on this ...
0
votes
1answer
59 views

Fetch Batch Database.SaveResults from LWC

I'm working on a LWC component which will work as a simple snap-in to do basic data uploads for very non technical users. My issue is that I want to get the SaveResults from a batch, and pass it into ...
1
vote
1answer
77 views

Upsert records after parsing JSON response

I have a requirement to upsert Policy records using JSON response obtained from external system. below is my apex code: HttpRequest req = new HttpRequest(); req.setMethod('GET'); req.setTimeout(...
0
votes
0answers
52 views

Storing large string in Salesforce

I am currently handling an oAuth 2.0 PKCE authentication flow (not supported by Named Credentials). At the end I get an access_token that is around ~1200 chars, this token lasts for about 30 minutes ...
0
votes
1answer
19 views

Class to update Account's active__c not working

I made a class in a trailhead playground to query some opps, then the accounts, and some fields related to them. My objective was to access the Account's Active__c field and change the value from 'yes'...
0
votes
2answers
54 views

i am getting this error System.FinalException: Cannot modify a collection while it is being iterated

//write trigger on contact when we edit contact. the contact name comes along with account name trigger ContactNameWIthAccountName on Contact (before update) { List<Contact> listOfContact = ...
0
votes
0answers
32 views

Api Integration Issue

I have created an api integration in salesforce. From client's website a request will send to Salesforce in form of JSON. This will create record in Salesforce. Sometimes multiple requests are sent ...
0
votes
1answer
40 views

DML in trigger succeeds, but records are not created/available

We have a Trigger Handler which calls on "after update" a method "CreateNewRecords". public without sharing class sObjectTriggerHandler { public static void handleAfterUpdate(...
1
vote
0answers
31 views

How can Product2.StockKeepingUnit already exist in a test? [duplicate]

I'm trying to create some Apex tests. Of course I am NOT using SeeAllData=true. When I try to insert some instances of Product2, even though I've inserted none before, I get: System.DmlException: ...
0
votes
1answer
56 views

How to avoid MIXED dml Exception in update operation? [closed]

I got System.DmlException in update operation. Can anyone please check the below code and help me to resolve the exception. I have tried to solve it for the last two days but I couldn't find a ...
0
votes
1answer
26 views

Update Record Field in callout fired from an AfterUpdate Trigger

So I have a Trigger on Account, on the AfterUpdate event (I've also tried on BeforeUpdate), it launches a SOAP Request to a WebService (via a @future method), and this WebService returns a number that ...
0
votes
1answer
22 views

Ids and List<Account> after insert

In an Apex class method, I want to add several Accounts to a List. After a successful execution of the insert, can I access Ids? Example: List<Account> accounts = new List<Account>(); ...
0
votes
1answer
43 views

INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call While testing my Apex Trigger

I am new to salesforce, and I am getting an error : INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call I am trying to test my Trigger My Trigger trigger invoiceTrigger on ...
0
votes
1answer
26 views

Creating Parent and Child record in the same DML Statement - Illegal assignment from Lead to Id error

Im trying to work out how I can create a parent and child record at the same time. I've tried to base it on the example salesforce have provided https://developer.salesforce.com/docs/atlas.en-us....
0
votes
1answer
45 views

DataLoader on contacts causing System.LimitException: Too many DML statements: 151

I have a trigger on contacts that is causing DML errors and I'm not sure where the problem is as I only have one update on a list. This is occurring when I am using the Data loader to update about 30k ...
0
votes
0answers
21 views

Auth.RegistrationHandler fails when creating Account

lately i am facing wierd issue. I've created SSO for my community and till some point it worked fine. Lately I've found out it is failing when creating Person Account and I have no idea why. Code is ...
0
votes
0answers
37 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 ...
1
vote
1answer
20 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 ...
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
57 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
0answers
26 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 ...... ...
1
vote
1answer
42 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
53 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='...
1
vote
1answer
222 views

Invoking a trigger from another trigger - execution context

For Example there's a trigger on Account (after update ) in it I update the address of 10000 contacts(max for all accounts combined) , now I have an trigger(after update) on contact for each contact i ...
0
votes
1answer
246 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
54 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 ...
0
votes
1answer
84 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 ...
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
49 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
163 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
285 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
53 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
99 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
44 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
415 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
159 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
79 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
123 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
66 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
202 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 ...
1
vote
3answers
246 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 ...

1
2 3 4 5
9