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
204 views

delete multiple records from an object [closed]

I want to delete multiple records of an object...How should I do it. public class del_acc { public List<String> sel_id{get;set;} set<id> sid = new set<id>(); List<...
6
votes
1answer
502 views

DML not allowed on NetworkMemberGroup

I am trying to automate the process whereby all profiles are given access to communities. This section when managing a community: As I understand it, this is the NetworkMemberGroup object. I ...
4
votes
2answers
648 views

Performance issue when deleting Opportunity Line Items

I'm writing APEX REST API that creates OpportunityLineItem, Product2, Quote objects, updates Opportunity etc. based on data in JSON format received from external system. During testing I experienced ...
3
votes
2answers
121 views

Links to Documentation for Database.* DML Method? Gone from APEX Docs

So we've got the usual DML statements insert accts; and we've got the database class dml statements, e.g. Database.insert(accts, false). Had a team member ask me a question about the parameter ...
7
votes
1answer
102 views

Combining DML, Callouts and Triggers gives CalloutException

When running unit tests, I'm currently getting: System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out The issue is that I have a trigger that ...
1
vote
2answers
867 views

scheduled apex+Too many DML rows: 10001

I am getting this error when i look at my apex jobs UI "Scheduler: failed to execute scheduled job: jobId: 7072000002391Am, class: common.apex.async.AsyncApexJobObject, reason: Too many DML ...
0
votes
2answers
388 views

Update a text field from custom object to Notes Related List

I have a requirement in which I have a custom object. I have a text field in that object. When that text field is filled with a value it show create a note in the related list in which i need to map ...
2
votes
1answer
622 views

Database DML Update partial success versus Data Loader

I have a Trigger On OpportunityLineItem when it's get updated, it will update the Opportunity. I need to update OpportunityLineItem in Bulk. For that, Using Dataloader I kept the (batch size =200) of ...
3
votes
2answers
129 views

How to iterate and update a value of a field throughout considerable number of records?

Attempted to set a value to a field of the account object across 70000 records using anonymous apex execution causes below exception; System.LimitException: Apex CPU time limit exceeded This is ...
0
votes
2answers
645 views

How do I Mass update owner in Contact and Account?

In my ORG I have a 20K Accounts and 50K Contacts. I want to update Contact and Account owner where owner is "Jai" to "Mrugesh". How to update all Contact and Account owner?
0
votes
1answer
53 views

Trigger to check for dupes and get data from them - Insert failed - cannot specify Id in an insert call

So I'm receiving some Accounts from an external source. They could be exactly the ones I already have on the org but this external ones also have some custom Ids that I need to assign to the old ones. ...
10
votes
1answer
2k views

How To Cause DmlException - Delete

I thought I would be able to take a User who does not have delete privileges on an object, delete records from that object, and get a DmlException. No dice. Below are the Case permissions for the ...
2
votes
1answer
548 views

How can I show the progress of a chain batch process?

I have an Apex class that is a controller for a Visualforce page. The VF page has a commandButton that calls a function in the controller that executes a batch process that processes some data, then ...
4
votes
1answer
4k views

Can't Insert User in Test Class

I've created a Trigger on the User object and I'm trying to test creation, update, deletion and undeletion of a User. Starting with Insert DML, I've got the following code: Profile p = [SELECT Id ...
0
votes
1answer
259 views

Delete a Record Using Visualforce

I tried this code i m getting error like this "List has no rows for assignment to SObject" public class delrecords { public string cid{get;set;} public list<contact> conlist{get;set;} ...
1
vote
1answer
653 views

Use addError method and make a DML operation

The problem that I am having is that I am using addError method in before insert trigger which actually rollback every DML I make including @future method calls, sending email, queueing batch jobs, or ...
3
votes
1answer
682 views

How many DML statements will be execute?

Given the code below, and assuming there are 500 accounts in the system, how many DML statements will be executed? for (List<Account> accounts : [SELECT Id, Name]) { update Accounts; }
1
vote
0answers
138 views

Large time gap in debug log before ENTERING_MANAGED_PKG

When viewing a debug log where the logging level was set to: APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO I am seeing a large ...
1
vote
1answer
441 views

Modifying data using SOQL?

I'm using SOQL along with the SOAP API in order to pull a certain set of data to my webpage. However, I want to modify this data (two custom fields) and update the records in Salesforce itself. As I ...
1
vote
1answer
1k views

Unable to Assign Owner to Record

We have a custom object called Lead__c for which I'm trying to execute DML on it to insert a record. However, I need to assign the owner to it. I've got the following query to search for an owner: ...
2
votes
1answer
671 views

Http callout test class “uncommitted work pending” error with no clear cause

We have method EnrollmentUtil.createNewEnrollment which contains a http callout on create of custom object Enrolment__c, and a test class to test this method. I'm trying to figure out how this class ...
0
votes
0answers
32 views

Unexpected System.CalloutException in test while using startTest method

@isTest global class xxx_UT implements WebServiceMock { static { Account account = new Account(Name = 'Test Account'); insert account; Qwerty__c q = new Qwerty__c(); insert q; ...
0
votes
1answer
36 views

Edit Account after Update DML statement

Is there a way to continue editing an account after using the update DML statement? I keep getting the error: "attempt to dereference a null object". The reason that I am trying to update the account ...
5
votes
2answers
183 views

Difference between defining these Inserts

Apologies if the title is a little vague here. I was using the following code to attempt a insert DML: for (ts2__Placement__c pla : selectedPlacements) { Timecards__c t = new Timecards__c( t....
4
votes
1answer
207 views

How to put DML operation outside the for loop?

I wrote one for loop and perform insert,update operation inside the for loop, it is working clearly but i need to perform that operation outside the for loop so is the better way to do it ? for(...
0
votes
1answer
63 views

Having error (NullPointerexception : Attemp to de-reference Null)

I am trying my best with this code but don't know why i am getting error System.NullPointerException: Attempt to de-reference a null object can you please tell me that what i have did wrong. ...
0
votes
1answer
61 views

Trigger Governor limits concern [closed]

I have a concern for below triggers, should we hit governor limits for more than 200 records updated at one go? Trigger 1: trigger BatchTrigger on Compliance_Incident_abv__c (after update) { if(...
0
votes
2answers
905 views

Error while doing a DML after a Webservice call

I need to parse a webservice result first to take actions afterwards. "You have uncommitted work pending. Please commit or rollback before calling out" I'm getting now this error, and there are a ...
1
vote
1answer
62 views

writing apex DML and soql using less number of statements [closed]

i recently started working with Force.com. I use SOQL and Apex to do DML a lot. I recently learnt a way to do something i do very frequently with very less number of lines. I would like to know if ...
0
votes
2answers
3k views

Apex - populate field with a value stored in mapping object

I am trying to solve the following problem: There is a text field "Product" on Opportunity object and I need to change the values of that and map it to picklist. There is already data in the system ...
2
votes
1answer
661 views

Apex scope for creating temporary sObjects

I have a trigger that creates child objects on insert/update. The update trigger has logic based on a field on the parent object. Depending on this field, it may create 1 or 2 child objects. When I ...
1
vote
1answer
60 views

Getting trigger's changes after dml statement

I'm trying to use object's fields updated in a trigger in the context where the DML statement is executed, however I'm not being able to get the new values assigned by the trigger. I did the ...
1
vote
2answers
775 views

Apex After Update delete child then create new child

I have a simple trigger where when an opportunity is inserted, it creates a child object. If the opportunity is updated, it deletes all child objects and creates a new one. However, I receive an error ...
1
vote
1answer
218 views

weird behaviour of insert when doing calling before getContent() call?

I am trying to generate multiple documents(which are VF page rendered as Word doc), by iterating over a map. As my first step, i am reading a report, generating a map(where key is a string and value ...
3
votes
2answers
691 views

Exception Handling on child records when parent is updated

Please let me know how to perform exception handling in this scenario? Though we have added error message on child record we couldn't see it on the parent while the parent record is being updated (as ...
1
vote
1answer
143 views

Update standard object fields from custom object

is it possible to update number of fields of standard object from custom object using apex and visualforce. We cannot call the API within the org. But however could we use SOQL for DML transaction ...
1
vote
1answer
145 views

Is there a way to update duplicate leads in an apex list

Hoping you can help.. We receive bulk email marketing data into Salesforce which creates 'events'. These events include things like the date, if any URL was clicked and if so, what the URL was. We ...
2
votes
1answer
165 views

DML not allowed on Network

My requirement needs to change the "from email address" for the welcome mail that is sent from a community after a new user is registered. But this needs to be done dynamically based on some ...
3
votes
2answers
619 views

Is it possible to create the SkillUser object from apex

We are using Live Agents for a service implementation, but due to implementation decisions made, cant use Profiles to assign Skills for the Live Agents, and need to assign individual users to their ...
13
votes
2answers
1k views

DML operation and async Queueable job - which executes first?

I have a trigger after insert on some arbitrary entity: trigger OpportunityTrigger on Opportunity (after insert) { // not bulkified for the sake of simplicity ID jobID = System.enqueueJob(...
0
votes
0answers
593 views

Upsert throws Missing Argument exception. Any thoughts please?

I tried to upsert and my code is below. But i am getting an exception and nothing is inserted or updated. Any thoughts please. if(lstp.size()>0) { Boolean isUpsertfirstTime = true; try { ...
3
votes
1answer
527 views

How to know which Database.SaveResult instance corresponds to my SObject

I am currently trying to Update and Insert to collections of SObjects. I perform the actions(update&insert) separately, obtaining a Database.SaveResult Array as feedback. The problem is that I ...
1
vote
1answer
53 views

Replace original record with another on during After / Before Insert

Imagine the user clicks a standard New button of a custom objects, populates some fields (in a Standard Layout) and then clicks save. He then is redirected to the View page of this new record, but is ...
1
vote
1answer
447 views

Moving DML Operation Outside a for loop

I have the following code and would like to perform the DML operation outside the loop. However, I cannot seem to find any way in doing this at the moment: private void processResult(List<...
0
votes
2answers
2k views

Creating a new Task in Apex?

I am trying to create, and assign a task related to an account whose page the user is on. I am not getting any errors, and I can't make sense of the Debug Log. The snippet of code I am trying to use ...
0
votes
0answers
58 views

Trigger upon change in formula field result

I have standard object - ServiceContract, on which there is a formula field Status__c. Lets assume the formula field does this "StartDate__c>=Today>=EndDate__c, status=Active, else status=Expired" ...
3
votes
2answers
241 views

Better for working with filtered DataSets: SOQL or FOR Loops

I have an Apex class where I have to grab a Dataset of custom objects and then perform some checks on various subsets of that data. I was wondering what would be the most optimized way of handling ...
4
votes
1answer
236 views

Mixed DML in Test Method

I followed the steps to use runAs but it is still giving me a mixed_dml exception. I need to populate the contactId so the user has to have a portal profile. Here's what I have for the test method ...
8
votes
2answers
10k views

MIXED_DML_OPERATION, DML operation on setup object is not permitted [duplicate]

I'm writing a Trigger that After Insert of a new User, I need to create a Contact with that same new User information. I'm getting this error: MIXED_DML_OPERATION DML operation on setup ...
3
votes
2answers
1k views

DML not allowed on User

I created some test users using the following apex code which worked perfectly fine: list<User> abc = new list<user>(); for(integer i=1; i<3;i++) { abc.add( new User( ...