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
6
votes
2answers
410 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
305 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
293 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 ...
0
votes
2answers
996 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
609 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
147 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
4k 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
149 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
222 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
1answer
881 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
100 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
357 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
695 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
274 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
800 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
76 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
201 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
207 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
146 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: []...
11
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
231 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
101 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
573 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
12k 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
110 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
408 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
565 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
83 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
217 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
792 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
126 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
22 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
289 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++){ ...
2
votes
1answer
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
2k views

How to update a record but not overwrite a specific field

I have an Account(Name='Hello') and the following code // First get an Account with its Name field and some other fields Account acc = [SELECT Id, Name, Otherfields FROM Account WHERE Id = ...]; // ...
0
votes
1answer
40 views

Unit Test not Returning Expected Value

In an Apex class, I've got a simple Boolean that sets itself to either true or false depending on whether the field (Picklist) Candidate_Type__c is equal to: Contract/Interim Permanent See below: ...
3
votes
1answer
642 views

Possible causes of UNABLE_TO_LOCK_ROW error during Insert of Tasks?

I have a VF page that has been in production for a few weeks; this error was seen for the first time today. I know that locking errors can be sporadic, and the admin couldn't reproduce (logged in as ...
2
votes
1answer
302 views

Operations That Don't Invoke Triggers - Cascading delete operations

I was going through documentation about Operations That Don't Invoke Triggers and got confused with Cascading delete operations. Records that did not initiate a delete don't cause trigger evaluation ...
0
votes
1answer
265 views

Database Class and DML in a transaction

According to the official document - https://developer.salesforce.com/docs/atlas.en-us.198.0.apexcode.meta/apexcode/apex_transaction.htm I understand that if there is any error in a transaction ...
1
vote
1answer
73 views

UserAccountTeam - Test Class

I have a trigger that basically replicates adding the default team to the account team (it's doing more than just that but for ease of asking this question lets leave it at that case). How would one ...
0
votes
1answer
94 views

Persistent Data On VFP

I have a VFP with a few forms that will pull various reports. I want to be able to pull a report and persist the data so when the user logs out of Salesforce, the data will still be there tomorrow. I ...
0
votes
1answer
432 views

Exception on insert

I have this class: @isTest private class DailyLeadProcessorTest { @testSetup public static void setupMethod(){ List&lt;Lead&gt; l = new List&lt;Lead&gt;(); for(...
3
votes
1answer
637 views

Batch, future and MIXED_DML_OPERATION

One of the requirements for out project is to do some complex logic on both setup and non-setup objects. In short, whenever a field on Account is edited, we should recalculate our custom sharing for ...
1
vote
2answers
533 views

How can I get around Apex CPU time limit error when reassigning lead owner via Apex?

With the following code, I'm getting an Apex CPU time limit exceeded error: List<Lead> untouchedLeads = [SELECT id FROM Lead ...
0
votes
1answer
484 views

Batch Job Error: Too many DML Statements

I'm trying to figure out why I am getting the following error when I try to run a batch job. I thought I coded it correctly (I don't see any queries inside a for loop) but I must have missed something....
0
votes
1answer
18 views

bulkification issue for insert operation of attachment

I am getting bulkification issue on "insert at".Not able to understand why there is bulkification issue.Below is my code. public static Attachment addAttach(Attachment at) { try { ...