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

2
votes
0answers
33 views

How to update the current login user

I have a custom field over my user object. And I want to update this user by the contact id from apex. How can i update the user record in salesforce. Because when I trying to update the field of ...
1
vote
1answer
21 views

call dml insert listofSObject from a controller that is referenced in apex page

Is it possible to call dml operations like insert list_SObject ; inside a controller method that is refrenced in visualforce page not some trigger class? please give some references.
0
votes
2answers
23 views

Trigger is not updating a lookup field

resolved. object sfid wasn't created yet, changed the trigger to after. I've looked at other posts, but for some reason cannot find a solution. Basically, when a new object is inserted into my ...
1
vote
1answer
16 views

Is there a predetermined order that Database.SaveResult is returned?

Let's pretend the scenario below: List<Account> acc = new List<Account>{...}; List<Database.SaveResult> results = Database.insert(acc, false); Will the Lists have associated ...
1
vote
1answer
20 views

Why am I getting SaveError: Variable does not exist: AssigneeId?

I have entered the following code entered in the Force.com IDE: @RestResource(urlMapping='/PermissionSetAssignment2/*') global with sharing class PermissionSetAssignment { @HttpPost global ...
3
votes
2answers
38 views

Why is my locked record editable?

Why is my record locked? The record that the class below creates, when shown in detail view, has the 'locked' icon, and appears to be locked at first view, but- Why can I edit the locked record (Even ...
5
votes
0answers
50 views

Email value is saved without parentheses (label) when using DML

When an email contains a label enclosed in parentheses, the value can be saved as typed in via SF UI. (Note: the email value "as is" is only seen when in Edit mode.) However, when the record is saved ...
1
vote
2answers
55 views

What to use for performing operations on multiple records at once, Apex REST class or Bulk API?

I need to insert/update/delete a variable number of records at a time from a webapp (so from javascript), are there reasons to choose the Salesforce Bulk API over writing a custom Apex REST class to ...
2
votes
1answer
24 views

Can you delete AccountHistory data?

Does anyone know if it's possible to delete AccountHistory data? Bonus points: Is there an easy way to find the total number of AccountHistory records in an org?
-1
votes
1answer
45 views

Realtime scenerios on dml and database class methods [closed]

can anyone provide links or tasks or whatever possibilities on dml operations otherthan force.com developer guide. plz... As i understood concepts on insert,update,upsert,delete and also database ...
2
votes
1answer
64 views

Is it bad to update a a list of a size greater than 200 in DML

I am reading the existing code in the project. In the code: if(aUpdates.size() + aList.size() > 200) { update aUpdates; aUpdates.clear(); aUpdates.addAll(aList); } else { ...
1
vote
3answers
148 views

Changes to trigger.new upon Sobject Event within before update are not sticky

I have a custom object that creates a calendar event via a trigger and it works fine. However, if the user attempts to change calendar event fields from the calendar edit feature, I want the fields to ...
0
votes
1answer
66 views

Apex Error: Too Many SOQL Queries: 101 [duplicate]

I am currently trying to update a set of data, but I am receiving the error "Too Many SOQL Queries: 101". From what I have seen while searching around, this is normally an error that occurs while ...
2
votes
1answer
81 views

DMLOptions 'useDefaultRule' for an account's update - not working

I'm trying to assign DML options to an account's update. It's working with the insert, but not wit an update. Here is the code I'm using: Database.DMLOptions dmlOpts = new Database.DMLOptions(); ...
4
votes
1answer
111 views

New Customer Portal user email even when triggerUserEmail = false

I'm trying to write an Apex web service that can create a customer portal user. After creating the user, there is a separate step which does a password reset for the user and sends them an email. The ...
0
votes
1answer
61 views

Updating a record without DML

I am writing an after update trigger on OpportunityLineItem that will update an opportunity based on values retrieved from it's respective line items. By sheer accident, I forgot to include the ...
1
vote
1answer
93 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 ...
6
votes
2answers
75 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
405 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
93 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
49 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 ...
5
votes
1answer
1k 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
122 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?
5
votes
1answer
37 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
89 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
97 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
404 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
136 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
413 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
129 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
990 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
314 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 = ...
5
votes
2answers
545 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
277 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
64 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 ...
7
votes
2answers
721 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
364 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
400 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
87 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
95 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
2answers
554 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
347 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 ...
3
votes
0answers
73 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 ...
29
votes
3answers
385 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
304 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
172 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 ...
7
votes
2answers
1k 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
473 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
735 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, ...
2
votes
3answers
1k 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 ...