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.
396
questions
0
votes
2answers
159 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
189 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
39 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
30 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
200 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
68 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
133 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
399 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
259 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
623 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
267 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
42 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
258 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 ...
1
vote
2answers
967 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
119 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
37 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
376 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
308 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
212 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
123 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
201 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
106 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
682 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
170 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
444 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
66 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
39 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 ...
2
votes
1answer
480 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
85 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
407 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
241 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
263 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
745 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 ...
4
votes
1answer
66 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
292 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
427 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
77 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
880 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
21 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 ...
0
votes
1answer
52 views
Query returning value from database and not test class
I'm having trouble with my code coverage and have a couple of hypothesis why this could be.
My class:
public class Tareas_Ordenador {
public static void Ordenar(){
User Usuario = [Select Id ...
0
votes
1answer
200 views
UserTeamMember Apex DML
I'm trying to insert some UserTeamMembers in an Apex test class but i'm getting the "DML operation Insert not allowed on UserTeamMember" error.
Looking at the documentation (https://developer....
6
votes
0answers
137 views
How many child records can a parent cascade delete (documented limit)?
I have a CustomObject__c which has childrens 2 level deep. Together a single parent object can have many 10.000 child records.
Would it work to auto-delete the thousands ob child records just using a ...
1
vote
0answers
33 views
Updating event restores event relations I just deleted?
I have need to programmatically delete an event relation for an event, then add a new one, then do some updating of the event information, then update the event.
I have ran into some roadblocks:
If ...
0
votes
1answer
38 views
Allow the insert of Custom Records even if some of them fail as duplicates
I want to ignore a bunch of records (Custom settings in fact) and want the transaction to ignore Duplicate errors. All other errors should make the insert fail. If a duplicate exists simply skip the ...
-3
votes
1answer
948 views
Unable to insert opportunitylineItem in apex code?
public class NewMedicineBillVF1_Ctrl{
public Boolean displayPopup {get;set;}
public List<ProWrapper> pwrlist{get;set;}
private List<OpportunityLineItem> olilist;
public Product2 pro{get;...
1
vote
1answer
82 views
Apex Approval Process Locks on DML Statements
I have a custom button on a record which is designed to update the record's status. There is a separate process within a different class, which is locking the record.
I need my pageRef to unlock the ...
0
votes
2answers
823 views
How exactly do you update/insert documents in apex?
I have a very simple update here:
Document emailDoc = emailLogoDoc[0];
emailDoc.Body = newLogoData.emailLogo;
emailDoc.Url = Url.getSalesforceBaseUrl().getProtocol() + '://'+System.Url....
2
votes
1answer
122 views
DML external Id relationship throwing Internal Salesforce.com error in sandboxes with Winter 18 release
I'm facing an issue with one of my batch process when trying to relate records through an external Id.
I have a csv file with info about the record to upsert, and a external id of the account that i ...
2
votes
1answer
66 views
AppExchange ISV Security Review CRUD/FLS Puzzler
Who knows the answer to this puzzler?
Q: If a Visualforce Page is using a standard controller with a custom controller extension and the controller extension is declared "with sharing", do we need ...
0
votes
1answer
867 views
Check for empty list not working
I have this method where I want to call another method from based on a check if a List is not empty. I get the error:
System.QueryException: List has no rows for assignment to SObject
Error is in ...