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.

learn more… | top users | synonyms

1
vote
1answer
38 views

List Exception caused by trigger

I have some code in a trigger that works when tested, and works in my sandbox, when I get it into production every time something happens where the trigger should go off, I get this error: Apex ...
5
votes
2answers
41 views

DML not allowed on ApexClass

I am trying to move around 80 classes and visualforce pages from sandbox to production by using change set but i got an error One or more components failed Version Compatibility Check. This ...
3
votes
3answers
172 views

Can I rollback a Before Insert trigger from an after trigger event?

Scenario: After an object is inserted/updated (can happen after any of the two) - I update an external system with that object's info - Object ID is needed - which is why I need the After Insert. ...
0
votes
2answers
77 views

Got the Workflow Field Update working. What is the equivalent DML?

In the Formula part of a Field Update Workflow I was able to update a custom field in my Activity Assignment record with the email address of the Owner from the parent Sales Opportunity, using: ...
1
vote
1answer
22 views

Changing org-wide sharing settings from Apex

We have an object whose Org-Wide default sharing setting is set to Private. When an Admin changes a Picklist to Full Access, we have to insert CustomObject__Share records for all users, and ...
4
votes
1answer
558 views

Database.SaveResult - how to get the Id of the record where Update failed?

I am using Database.SaveResult and Database.update(..., false) for the very first time and ask myself how to get the Id of the record where a dml has failed. I expected Database.SaveResult.getId()` ...
3
votes
1answer
72 views

Chatter in Apex: is it DML?

So there's times you can't DML (getters, constructors, components without allow DML, etc). Can we use chatter in apex, or is that also considered inserting records?
4
votes
1answer
27 views

Is DML allowed in the current context?

So I can check for isbatch, isfuture, etc... Is there a way to know if the current context allows DML? We've implemented a exception logging object, but if a class is called from a getter or ...
5
votes
1answer
58 views

Do triggers run asynchronously when triggered by DML in apex?

The question is fairly self-explanatory, but to add a little background, here's the scenario that has made me ask. First a (very basic) SSCCE: public void createAttachments(List<Account> ...
3
votes
1answer
68 views

DmlException Question

This question is related to a previously answered question: Trigger won't Fire It looks like my organization has an existing test class that isn't playing nicely with my new Trigger. Could ...
0
votes
1answer
162 views

can't call the custom field on custom visualforce page

i m trying to learn about visualforce page based on my understanding, after reading the material from web and workbooks. I created an C.Object called Book__c and calling custom fields to a visualforce ...
7
votes
1answer
77 views

Avoiding Mixed DML (setup/non-setup) Approach

I need an approach to allow delegated admins (i.e., non-Administators) to add members to Public Groups and Collaboration Groups (the GroupMember and CollaborationGroupMember objects). I added a ...
0
votes
2answers
117 views

How to set reference Object's value before insert?

Object a has many of object b, How can I determine an object reference before insert ? When I determine object b information for example number, name, .. and I want to insert it to an object of ...
1
vote
2answers
97 views

What does the insert statement do?

For instance: Country__c newCountry = new Country\__c(); newCountry.CountryName__c = 'GlobalLogic'; newCountry.IsActive__c = true; insert newCountry; // why we are using insert statement ...
4
votes
2answers
313 views

where do I use Database. Methods?

I m trying to understand where we use following Database.Methods. I know if we want to insert a record to an object we use DML Statement. What i want to know is why/where we use Database. methods. It ...
1
vote
2answers
174 views

failure message system.dmlexception insert failed

//this is my before insert trigger public with sharing class Account_Amount { public Account_Amount(){} public void calAmmount(List<Account> accList){ AccountDiscount__c mc = ...
4
votes
2answers
193 views

How does salesforce calculate DML rows? What is included to DML Rows Count?

Does anyone know how does salesforce calculate DML rows? What is included to DML Rows Count? Consider following code which hits "System.LimitException: Too many DML rows: 10001" ...
8
votes
1answer
172 views

Is upsert properly ACID compliant?

Given an object Table_A with one unique field Unique and two rows: row Unique --- ------ 1 A 2 B And the following class: public class KeySwapDML { public void ...
3
votes
1answer
47 views

How insert operation on SObject having neither triggers nor workflow rules can cause exhausting of SOQL query limit?

Mystery of DML operation: if SObject doesn't have neither triggers nor workflow rules, how insert operation on it can cause exhausting of SOQL query limit? I have faced today again with exhausting of ...
6
votes
1answer
267 views

How do I delete records in the recycle bin?

I understand that when I perform a Database.delete() operation, records will end up in my org's recycle bin. And their presence in the recycle bin is reflected by the IsDeleted field on the object. ...
6
votes
1answer
273 views

Fields missing using getContent call for Visualforce rendered as PDF

I am attempting to get the content of a visualforce page that is rendered as a PDF. I make some changes to the object that the visualforce page is displaying data from, update that object, make the ...
1
vote
2answers
183 views

Changing Account Owner and Type Based on Criteria

I am trying to change Account owner and NewType(custom field on Account) using trigger based on the values of two custom fields OnLeave(check box) and NumberOfDaysOnLeave(Number) created on ...
7
votes
1answer
69 views

Why is DML not allowed on AdditionalNumber?

The following test method will not compile or save from my IDE. It give an error of: "(OIGForceTest) DML not allowed on AdditionalNumber " static testMethod void testGetDirectoryNumbers() { // ...
6
votes
1answer
81 views

Why doesn't SFDC allow MIXED_DML_OPERATIONs anymore?

Okay, I know very well by now that SFDC does not want and often does not allow us simply insert and/or update Setup and/or "Non-setup" sObjects in the same context anymore, something I used to do with ...
2
votes
1answer
299 views

How to perform Callout and DML operation simultaneously?

I'm facing a issue while doing a callout. I have tried from my side, but unable to wave it out. 1) Create a custom setting with name – FolderDetails . //Done 2) Have the custom settings store ...
3
votes
2answers
169 views

( INVALID_FIELD_FOR_INSERT_UPDATE, Attempting to update (as part of an upsert) parent field)Upsert failed

I am using the upsert statement to update the custom object Customer__c with two master-detail fields. The fields reference custom Contact__c and Subject__c objects. Customer__c c = new ...
2
votes
0answers
55 views

DML Statement from @readonly page

I have a page like below <apex:page controller="testcontroller" readonly="true"> ........ </apex:page> For Making query to search data from million records i put @readonly I am sure ...
25
votes
3answers
220 views

Any reason to skip DML on empty lists?

In parts of my code I have DML statements with an if around to only do the DML if the list is not empty: if( !recordsToUpdate.isEmpty() ) { update recordsToUpdate; } Couldn't I just write? ...
10
votes
2answers
194 views

Order of execution for records on DML statements

A list of objects should be inserted in the order it is populated, so lower indexes will be inserted first. This is important when dealing with a List<sObject> where you rely on the order within ...
2
votes
1answer
116 views

How to do a DML upsert/insert loop in custom object after JSON deserialization?

I'm fairly new to Apex and I am completely at a loss at what to do next. So far I was able to grab and deserialize my JSON I grabbed from a Web Service(This does a GET Method for info for ...
6
votes
2answers
421 views

Generic SObject update pattern

Question I know that it is possible to update a generic of List<SObject>, But what is the best approach to generate that list without knowing the SObjectType, only the ids ? Sample: ...
12
votes
1answer
322 views

Proper method to get an Sobject instance from an Id

What is the "proper" way of getting an object from an Id? The method I use at the moment is SOQL, and that feels wrong..... Example: Account account = [SELECT Id FROM Account WHERE ...
2
votes
1answer
445 views

REQUIRED_FIELD_MISSING error when Approval Process set to Manually Select

I have an Approval Process that is programatically created. When the first (and only) approval step Assigned Approver is set to a specific user, or group of users, the process works fine. However, ...
1
vote
3answers
685 views

Invalid conversion from runtime type LIST<ANY> to MAP<String,ANY>

I'm trying to make a webcall to pull data from an external webservice. After that call I would like to insert my data that comes in the form of JSON into my custom object called Company. However I am ...
6
votes
5answers
3k views

System.CalloutException: You have uncommitted work pending. Please commit or rollback

I am sending only a single HTTP Request in Batch but still facing error System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out My test code is ...
3
votes
1answer
278 views

Database.update opt_allOrNone is not working on wrong Id

I'm trying to update a list of records and I need to update the records that pass the validation rules, and get the errors for not updated rows. I'm using this code that works fine for non Id ...
2
votes
1answer
31 views

Losing field level information

I'm having an issue where when I perform a dml operation on a sobject list, I lose field level information when catching the dml exception. Does anyone know a work around for this issue? Here is a ...
1
vote
1answer
422 views

Get Error record on bulk upsert

I'm upserting a list of SObjects using Database.upsert and I need to know which records are not inserted. This is an example: Account[] accts = new List<Account>{ new ...
1
vote
3answers
1k views

How to avoid DML Insert/Update Limit of 10,000 rows when running anonymous apex?

Is there any way to bulkify an insert/update operation performed from anonymous apex? For instance, if I have a script that builds a list of 15,000 records that need to be updated, is there any way ...
0
votes
2answers
85 views

Insert not working

I have this code which does not show any exception and although I see the insert happaning in the developers console the record is not actually being saved. This method is called from a page like ...
2
votes
1answer
146 views

Understanding the concepts of database dml methods

I need to have better understanding on database dml metods.Can anyone give link where i can get many examples to study and understand about it.
3
votes
1answer
132 views

Easy way to find out which field has changed in custom save() in Controller Extension

For some reasons I had to implement a ControllerExtension with a custom save methods which delegates the actual DML to a batch. I only want to fire this batch if any (or specific) fields have been ...
2
votes
1answer
944 views

Updating multi currency rates from Apex

I just looked in the Salesforce.com documentation for a way to update currency rates using Apex, but I have a vague feeling that this is not possible using standard features. I noticed that a couple ...
1
vote
1answer
199 views

Update ConversionRates for CurrencyType from Apex

I'm working on a small application in which I want the user to be able to enter a conversion rate on a VF page. The conversion rate should be saved in the CurrencyType object. I wanted to use ...
5
votes
3answers
590 views

No such column 'lastvieweddate' on entity 'Quote__c

This is a bit odd. Sandbox org created under V27.0 Sandbox org now upgraded to V28.0 a few weeks back VF page at V28.0 that interacts with a controller at V27.0 that updates custom object Quote__c ...
2
votes
1answer
254 views

Prevent upsert from failing

I have a list of Opportunities which I am trying to upsert. Say the list contains 6 Opportunities. Upsert operation of 3rd Opportunity fails. Will the first two Opportunities commit? What happens to ...
5
votes
3answers
148 views

Randomizing User class username

I have the following method: public static User initUser(){ /** * Create a User * Insert User into DB * Return User back into testPage in order to use information **/ User ...
2
votes
1answer
2k views

Getting a System.DMLException:Insert failed error

I"ve created a trigger which is relatively short trigger trig_Opportunity_CreateOppOwner on Opportunity (before update,before insert) { List<id>OppsID = new List<id>(); //List that ...
8
votes
1answer
448 views

What is DML? How different is it from SOQL Actions?

This question is designated as a community wiki, please add your inputs, guides (please try to ignore oustside links, and bring the important skimmed data in here. What is DML? What is Dynamic-DML? ...
1
vote
1answer
170 views

DML inside apex controller

I have a generic question in my mind. Suppose that we have an apex controller that is doing DML operations on a custom object. Now my questions are Does context user's profile affect DML operations? ...