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
0
votes
1answer
438 views

Exception on insert

I have this class: @isTest private class DailyLeadProcessorTest { @testSetup public static void setupMethod(){ List<Lead> l = new List<Lead>(); for(...
3
votes
1answer
668 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
545 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
493 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 { ...
5
votes
2answers
5k views

Insert multiple sObjects in single DML call

I have 3 objects. Account, Contact and AccountContact(custom). When I try to insert account and contact using one insert statement as follows, it works perfectly Account a = new Account(...
0
votes
2answers
361 views

Need help on converting person Account to Business Account

For person accounts, when i am trying to change their record type to business account record type, it is not allowing me to do so using Apex.Below is the code snippet I am trying(for testing purpose ...
1
vote
1answer
3k views

Inserting a Content Note

The ContentNote represents a Note in Salesforce so I'm trying to insert one into a specific opportunity but I don't understand how to specify the right opportunity id. https://developer.salesforce....
0
votes
2answers
244 views

Invalid id on record type update

A trigger to update an opportunity record type, sends to @future method. I get this error: 15:24:49.22 (45149525)|FATAL_ERROR|System.StringException: Invalid id: rt.id Debug shows it does call a ...
2
votes
0answers
17 views

Is there a parent class/interface for DML Result classes? [duplicate]

I have a generic method that performs DML operations. I want it to return a result list, and I am wondering if there is a parent class/interface that DML Result classes derive from. All DML Result ...
1
vote
1answer
410 views

Copying data and updating ParentId (Attachment)

I have Custom object and Attachment and I need a way to copy all the data and update the Attachment.ParentId = Custom_object__c.Id with newly created record in the Custom_object__c.... I think I'm ...
2
votes
2answers
1k views

Binary fields cannot be selected in join queries

I am getting the following error when I execute the below code: Binary fields cannot be selected in join queries I Understand that the Body returns binary data but I need to fetch the body of the ...
5
votes
2answers
1k views

Remove Id from sObject

I have the following code: myObject__c customObj =[Select Name,Account__c from myObject__c where id='a06R0000002fMqY']; insert customObj; The issue is: I'm not querying the Id field, the customObj ...
0
votes
3answers
352 views

How to get detail (Opportunity) records via master (Account) ID (preferrably without DML)

I've got to update a custom field on Account. This field is the number of Opportunities of that Account that are "Prospecting". I've written a trigger for this. The problem is, I've solved it using ...
3
votes
1answer
519 views

System.runas throwing insert failed error in test class

The error is: System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_USERNAME, Duplicate Username.The username already exists in this or another Salesforce ...
1
vote
2answers
4k views

How to bypass ENTITY_IS_DELETED?

I have some apex as follows 1: List<Culture_TCH__c> oldCultures = [SELECT Id FROM Culture_TCH__c WHERE Assessment_TCH__c = :oldAssessment.Id]; 2: delete oldCultures; Simple enough, but this ...
5
votes
3answers
3k views

Insert List of Parent and Child Records in One DML Statement

I saw an example how to insert Parent and Child Record in one DML Statement from Developer Guide and It's Working Fine no issue in that. Here In my case I would like insert List Of Both Parent and ...
0
votes
1answer
588 views

Confused about OrderProducts, OrderItems, and Products when making orders in test class

I'm making a test class that creates 5 orders and upon insert, I get the error that you need to add products to orders. I've got... List<Product2> clothProds = [SELECT Id FROM Product2 WHERE ...
0
votes
1answer
54 views

Field value without any errors not getting updated when used Database.update with “AllOrNone” false

I am having a "global with sharing" class which has a method(which is webservice static) that is called from Javascript. This javascript is defined on click of a button on opportunity object.I am ...
14
votes
1answer
888 views

Set Relationship Via Name Pointing Field?

One of the most startling things I ever learned from @BobBuzzard is that you can update a lookup by using the name pointing field. At least, I thought that's what I learned, until a recent debate cast ...
0
votes
1answer
583 views

Checked required fields, still getting an error that a required field is missing on Insert

I have the following and get an error on the insert: Order o1 = new Order(Name ='anOrder', Account = test, Status = 'Activated', EffectiveDate = date.today(), Program__c = clothing.id); ...
3
votes
1answer
892 views

Cannot specify any additional fields when marrying or separating a Person-Account: []

We're undertaking a process in which we are trying to convert Business Accounts/Contacts to Person Accounts. When I run my code I am getting the following error: INVALID_FIELD_FOR_INSERT_UPDATE, ...
2
votes
1answer
563 views

How to create trigger for DatedConversionRate object

We're using multicurrency in our project. DatedConversionRate has been updating every day by external process. The requirenment is to update CurrencyType records with most relevant rates. At the ...
1
vote
1answer
426 views

VisualForce - Dynamically Update Contact Records based on selections made in Multi-Select style Data Table (Using Wrapper Class)

(Problem / Question listed at the bottom, below explanation content) Background: I've created a relatively simple VisualForce page with the intention of allowing our customers to update data ...
0
votes
0answers
57 views

Trigger is working fine for inserting records but not working on update of records

I have written a trigger to update one lookup field of invoice with salesquota object id.This triggers work fine when i am inserting records.But when i try to update records with few changes it is not ...
0
votes
1answer
368 views

Variable does not exist error on custom field name

I have an object XYZ having custom fields AssigneeId and PermissionSetID. Now I have a list insAssignmentList of the object XYZ. I try to add values to the list by below line inside a for loop and ...
0
votes
1answer
574 views

Update External Id in Before Trigger Not Working

I'm creating some prep apex to run when we receive an account .csv that we've automated daily to push into salesforce. The idea is that some of these fields we want them to update our primary fields ...
3
votes
1answer
338 views

Test coverage for a user trigger: How to prevent “DML not allowed on User” in test-class?

I want to deploy a trigger on user. Therefore I need > 1% coverage on the trigger. To invoke the trigger in my test class, I've tried this: @isTest public class elfTriggerFrameworkTest { public ...
1
vote
1answer
147 views

All-or-none before insert - is it possible to maintain record changes between trigger attempts?

According to Bulk DML Exception Handling : Apex triggers are fired for the first save attempt, and if errors are encountered for some records and subsequent attempts are made to save the subset of ...
1
vote
1answer
625 views

Prevent record from being inserted in before trigger without adding errors

Is it possible to prevent single record from being inserted in before trigger without addError()? I'd like to be able to insert just a subset of inserted records without throwing any errors.
1
vote
1answer
33 views

Removing a cell in a row in Apex

Im jut wondering what is the best way to remove a single cell/column (I dont know what the word in Apex is) from a row. So I have a bunch of reports and I want to remove the deal from them. I was ...
2
votes
2answers
2k views

Getting Issues while creating User

I am trying to create an User but I am getting error as follows: 18:46:26:307 FATAL_ERROR System.DmlException: Insert failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, portal ...
1
vote
2answers
443 views

Creating records using Remote objects

Can we create multiple records at a time using remote object create() call? If yes what is the syntax? I tried passing a list of objects to create call but it didn't work.
7
votes
1answer
385 views

DML “10 chunks exception” and weird pattern

I am aware of System.TypeException: Cannot have more than 10 chunks in a single operation exception and it seems to be a known bug. I am also aware, that there are some other ways one can encounter ...
0
votes
3answers
49 views

Does list element get removed after deletion of that record from database?

Updated my question: Scenario:I am making certain changes in an opportunity record and clicking save. This causes trigger to execute and this trigger is executed recursively 3-4 times. Now say I have ...
2
votes
1answer
625 views

Get the inserted record id in a upsert call?

I am using below code to get the id of all record id whether it is update of inserted. upsert custmerList Name; for(customer__c afterUpsert : custmerList){ system.debug('*** Id = ' + afterUpsert....
0
votes
1answer
137 views

Unit testing: Assigning a Custom Obj Auto-Number to String Variable?

I have been trying to successfully compile a Test Class for triggers that auto-insert a DML_Log__c upon a specific sObject type being deleted, and an error keeps getting thrown: Expression cannot ...
1
vote
1answer
198 views

System logging: How to get.SobJRecordType() Record Type Name

Related to my latest flurry of questions, I am trying to write the Record Type Name as a String data type into a text DML Log custom object field. You will likely be able to tell by my code that I ...
1
vote
1answer
69 views

Why is get.sobject('Id') method appending a 3-char string? [duplicate]

I am creating a custom DML Log in our Salesforce sandbox, and I created a Class & method that fires based on an Apex Trigger Here's the class: public class Util { public static void ...
4
votes
1answer
2k views

DML update in @future callout not updating sObject

I've got a Apex class that takes the data from an Account object and uses it to create an account in my company's database by hitting an API. The API accepts JSON then inserts all the appropriate ...
0
votes
1answer
165 views

Insert Operation using Map Instead of List

How can I implement insert operation using map collection instead of list? I've created a conference scheduling app wherein upon selecting a certain student from a picklist, a table containing ...
0
votes
2answers
5k views

DML Statement in ‘after trigger’ and not in ‘before trigger’?

Why we need to use DML Statement in ‘after trigger’ and not in ‘before trigger’? Thanks KS Kumar
6
votes
2answers
585 views

Why have database rows not been inserted when the debug log says they have?

I have code that creates CaseShare records for the case based on some criteria from another class. The code that creates the CaseShare is called both on update and creation of the case. It works ...
6
votes
1answer
2k views

Can a parent and child record both be inserted in single DML statement?

I have a requirement to insert both a parent and a child record, in a single DML statement. Is this possible to do?
3
votes
2answers
3k views

How to create thousands of records using batch apex

I have a scenario where I have to create 30000 contacts and 15,000 accounts (i.e. 2 contacts per account) in an org. I have been trying to do this by using batch apex but I still have error of "First ...
2
votes
4answers
171 views

DmlException: Update Failed. Maximum Trigger Depth Exceeded

I have below trigger code getting - DML Exception 'Maximum Trigger Depth Exceeded'. Can someone help me please? Apex Trigger trigger updateAoC on Contract_vod__c(after update) { List<...
4
votes
1answer
1k views

Mixed DML Operation Error when Trying to Insert Contact

The basic premise of this code, for those of you who have not seen my 600+ other posts about it, is that it creates a Contact whenever someone creates a User. Certain fields of the contact are then ...
2
votes
1answer
1k views

Upsert with External ID: DUPLICATE_VALUE Error

I'm trying up upsert Asset records with an external Id and am getting the DUPLICATE_VALUE error which makes no sense to me: I want it to UPDATE the record if it finds a duplicate, that's what UPSERT ...
1
vote
2answers
2k views

null values of some fields on inserting data in test class

I have 2 custom object namely ServiceContract & ServiceRole and 1 standard object Account.In service role object,Account is Master-detail relationship to Account and ServiceContract is also Master-...
-2
votes
1answer
2k views

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing

Can any one help me out with this error : System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [OpportunityId]: [...