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
2
votes
1answer
67 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
880 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 ...
2
votes
1answer
592 views

How to merge multiple records outside of a for loop? [duplicate]

I have a list of master accounts that each map to a single duplicate account. I want to merge each master with its corresponding duplicate using the merge DML operation. I'm currently doing this in a ...
3
votes
2answers
64 views

Can the exact type of an Apex list be checked to choose between upsert and insert/update?

I have a utility method that that works on lists of SObjects that are normally of one type: private void oneType() { Contact[] contacts = new Contact[] {}; contacts.add(new Contact(...)); ...
0
votes
1answer
46 views

Test class no inserting object

I have a test class that seems not to be inserting some setup objects I need for the test. My test class is as follows: @isTest(seealldata=false) private class Alertas_The_Influence_isTest{ public ...
2
votes
2answers
394 views

DML Statement vs. Database method with true parameter?

Database methods with a true parameter will work same as DML statements. It won't allow partial DML operation in Apex Why are we still using DML statement, when we can achieve the same functionality ...
0
votes
1answer
192 views

Mixed DML Operation - creating Resource via Flow

I have a Flow where I create a User and a resource, related to that user, the object resource is managed by Field Service Lightning Package from Salesforce. The Flow itself seems to work fine, except ...
0
votes
1answer
128 views

How can I find out what fields made my upsert fail?

I'm trying to upsert some records. I use Database.upsert. If the failure is related to a duplicate value (external ids that have to be unique) I need to know what fields are duplicate and clear (...
1
vote
1answer
27 views

Compile Error on batch class to fetch fields from saveresult

I have below code to fetch field values from records of Database.Saveresult. I am getting error as below. Error Expression of type Database.SaveResult has no member named Territory_Name__c Code ...
0
votes
1answer
357 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 ...
3
votes
0answers
93 views

DML takes long time on custom object with no triggers/WF/PB on it

I've got a code, where on lead insert, I also insert 1 record of custom object Demand_Funnel__c. Demand_Funnel__c has no apex triggers, no WF rules, no Processes tied on it. If it's a first lead ...
0
votes
1answer
38 views

Is CorsWhitelistEntry insertable/updatable through APEX/DML?

CorsWhitelistEntry cors = new CorsWhitelistEntry(); cors.UrlPattern = 'sdfsdf.com'; insert cors; Wherever I try the above (or any other DML operation), I get an error message: DML operation ... ...
0
votes
1answer
130 views

Multiple DML operations in on update trigger

In an update trigger on parent object I need to do insert/update/delete on child object depending on criteria in parent object. insert and update works as required. but when delete error thrown as ...
6
votes
2answers
466 views

Values of SObject map are lost after a DML call

Can anyone explain the comments in this snippet? Map<Account, Contact> m = new Map<Account, Contact>(); m.put(new Account(Name='Test'), new Contact(Lastname='Test')); SObject[] records = ...
0
votes
1answer
362 views

Governor limits involving cascaded deletes?

I'm writing a job to bulk delete records from my database. I've already seen this question: Cascade delete limits? But it does tell me how the deletion limits are affected. The object whose records ...
0
votes
1answer
382 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 ...
1
vote
2answers
1k views

Database.update() is not updating the data, but there are no error message

I am experimenting this to test Database.update() to update data partially in Developer Edition. The issue is that, it is not updating the data and is not throwing any error. I am certain that, there ...
2
votes
3answers
722 views

Partial insert of more than 10000 records

What happens when we use Database.insert to insert more than 10000 records with allOrNone set to False? Are only the first 10000 ones inserted?
0
votes
2answers
158 views

EmailMessage.ToAddress is validated on one sandbox but not the other (INVALID_EMAIL_ADDRESS)

I have two sandboxes both running Summer '17, and the following code works on one but throws INVALID_EMAIL_ADDRESS on the other: Case c = new Case(); insert c; EmailMessage em = new EmailMessage(); ...
4
votes
1answer
5k views

DML requires SObject or SObject list type: List<List<Commission_Line__c>>

How do I insert the values from the map? I want to insert the grandchildren records in variable Commlinesmap, but I get this error: DML requires SObject or SObject list type: List> Error is at ...
2
votes
1answer
150 views

Uncommitted work in tests / Preparing for callouts

I have the following scenario in some unit tests: I need to create some data with inserts I need to invoke a method which performs a callout The test fails with the System.CalloutException: You have ...
1
vote
1answer
253 views

Webservice Callout and DML

I insert object X, do a web call out, and then take the data I get back from the call out to update object X. I found that you can't do DML before a webcallout so I broke this up into two methods and ...
3
votes
2answers
1k views

apex:Param not working with CommandButton component

I try to pass a parameter from Visualforce to the controller via apex:param and then upsert the object in the controller. However, the parameter I passed on, "Field__c" did not get written to the ...
2
votes
2answers
121 views

Trigger NullPointerException Error Before Update

I have a simple Before Update Trigger that I want to run when anything on the Accounting_Instructions__c is updated. I am not sure why my trigger is not working. I either receive a ...
0
votes
1answer
393 views

Need Help writing a Batch Class to change more than 10,000 Records (DML) at a time

I have a database with an object Voter_File_TX with over 15 million records and have over 700,000 contacts. I need to connect records that have the same First Name, Last Name, and Zipcode across these ...
3
votes
2answers
793 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 ...
2
votes
1answer
3k views

How to perform a DML insert after HTTP Callout (save a log of the response)

After reading the information around the issue Call error: System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out I tryed everything, like moving my ...
6
votes
1answer
319 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 ...
1
vote
2answers
868 views

Partial success for insert, update, delete [duplicate]

Not long time ago I decided to use insert, update, delete methods of Database class and its optional 2nd parameter allOrNone with false as value. But I found calling getId from the result does not ...
1
vote
2answers
79 views

update opportunity having error

Can anyone please look into this and help me out Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: [] here is my code : public Class ...
2
votes
1answer
43 views

Is there a way to find the class is a test class?

I am looking for simple solution to find he class is a test class , Other than checking body contains @isTest ? i have checked the below URL but there are no options ? https://developer.salesforce....
4
votes
1answer
205 views

How this actually update where there is no change in record?

Update [Select ID from Account]; //Updates all the record when there is no actual update. I wrote a trigger on account after update in such a way that the account name is not null then populate the ...
2
votes
2answers
215 views

How to implement my de-dupe code into batch apex?

My anonymous de-dupe Account apex code runs successfully until it hits a DML limit on the merge execution. I do not want to reduce the size of my query. How do I implement this in batch apex so that ...
0
votes
0answers
161 views

Updating OpportunityLineItem always results in INVALID_CROSS_REFERENCE_KEY

Exact error that I'm receiving: System.DmlException: Update failed. First exception on row 0 with id 00kO0000006gU4fIAE; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []...
12
votes
1answer
2k views

Is DML not allowed in a Visualforce getter?

Summary I am trying to simplify some code for a page that makes a callout, then logs the request and response. I stumbled across a scenario in which the log record appears to create successfully, but ...
0
votes
2answers
263 views

Batch APEX callout, Related record created, DML update to scope fails?

I have a batch process that I am using to send SMS notifications. In the execute method, I am making the callout, creating a log record and then updating scope. When I try to update scope, the record ...
0
votes
1answer
103 views

insert and updat unittest not covering. adderror why?

Why is my catch not working on the adderror on contentversion see: trigger NoteOnContentversion on ContentVersion (before insert, before update) { for (ContentVersion c : Trigger.new) { ...
0
votes
1answer
661 views

Create child records for parent created on same batch class

I have below code where I am creating parent object records in a batch class. I need to create the child records of the same on same batch class. Can someone please suggest a way out for this? Apex ...
9
votes
4answers
15k views

upsert vs update vs insert

I'm trying to understand when to use insert/update/upsert. As I understand, upsert is a combination of insert and update. I tend to use upsert most often as I do not have to check whether an object is ...
3
votes
2answers
120 views

Does Upsert operation in apex take more time against huge data?

I have a 50 gb data in my org for one object. My triggers will fire and upsert a record on it, does the volume of data show any impact in performing the UPSERT DML operation.
1
vote
2answers
460 views

Is Document Body Blob field value encoded in Base64 when extracted by Dataloader? Can this encoding be used for insert or update?

I want to use Salesforce DataLoader to extract and upload Documents. However, I don't understand in which format Blob Body values are stored, is it Base64 encoded? Looks like yes, but why it is not ...
5
votes
1answer
651 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 ...
4
votes
0answers
85 views

mixed_dml on batch execution on unknown standard object

I'm running a batch that updates several custom objects. Sometimes I get a mixed_dml error but it's not something I can reproduce, It's an intermittent error. The message that is thrown is: ...
0
votes
2answers
275 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 { ...
2
votes
1answer
907 views

Insert Parent and Child Objects of One Type within One DML statement

I want to insert Parent and Child Accounts in one DML statement. I know it can be done for related Contact/Account objects using External Id field, but it doesn't work in my case. Running the ...
1
vote
2answers
140 views

Unit Test data accessability

Today I experienced an error that I have never experienced before. When I go into my developer console on salesforce and run unit tests for, supposedly, all of my code, I get my typical high ...
1
vote
1answer
101 views

Visualforce page view state size limit OR de-reference a null object for transient attachment error

I have the below Visualforce page & controller class for a user to select a design document type & upload a file. Document_Type__c is a picklist and should be required. The code below works ...
1
vote
0answers
23 views

Enforce DML statement to be failed within a batch

I am trying to make a DML statement in a batch to be failed. The reason for this is that I have logic executed in my batch in case the DML failed for some records. I would like to test it and get the ...
0
votes
2answers
21 views

How to edit (and save) record after confirming that it has been inserted/upserted?

This NOT a trigger. This is a VF page controller. I think you should use try-catch blocks but I'm not sure whats the best practice for that. Should I put in all the code in the try block? Like this :...
0
votes
1answer
350 views

How to call Database.DuplicateError inside Database.SaveResult for loop?

I'm using this code to get the error ids List<Database.SaveResult> updateResults; updateResults = Database.upsert(arudate, false); for(Integer i=0;i<updateResults.size();i++){ ...