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

0
votes
2answers
36 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
23 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
28 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
30 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 ...
0
votes
1answer
23 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 ...
0
votes
0answers
27 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 ...
0
votes
0answers
10 views

Email trigger on timer basis [duplicate]

Could we write workflow to trigger email in case object without having DML record created or modified perhaps timer basis?
1
vote
1answer
22 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
77 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 ...
2
votes
1answer
33 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 ...
7
votes
2answers
112 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 = ...
0
votes
0answers
38 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
66 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
29 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
59 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 ...
0
votes
1answer
35 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
34 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
89 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 ...
0
votes
0answers
40 views

Site.createPortalUser error: DML operation on setup object is not permitted

A simple call to createPortalUser is failing: public pageReference registerUser() { try{ // values come from a VF page String username = email; String communityNickname = ...
3
votes
1answer
58 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 ...
0
votes
2answers
318 views

MIXED_DML_OPERATION, DML operation on setup object is not permitted

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 object is not ...
3
votes
1answer
90 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( ...
0
votes
0answers
23 views

How could I test a BusinessHours class functionality with unit tests

I am trying to write a unit test for the following method, public static DateTime addBusinessDays(DateTime startDate, Integer numberOfDays, String businessHoursName){ Integer ...
15
votes
0answers
180 views

How to write the superduper (=proper and stable) Custom Save method

Custom Save actions in Apex are tricky! Here are my requirements which I was unable to fulfill without harming the stability of my code: Save for New and Edit (works with record with and without ...
0
votes
1answer
47 views

Map of attachment insertion

I have a map with String value and list of attachments. I am getting those by inputfile but not being able to insert those. Please find my snippet as below. Can someone please help? Apex page: ...
3
votes
1answer
60 views

How can I create over 10,000 records with information from Visualforce?

I have an inventory input page that I am working on and I am running into an issue where I need to create more than 10k records. The problem here is that all the information needed is not stored in an ...
1
vote
0answers
68 views

Mass/Bulk Update Campaign Member Status Over 200

I am looking to update all of the related Campaign Members' Statuses from a Campaign based on the execution of a JavaScript button and an APEX Class. The button below works to update the status from ...
1
vote
1answer
112 views

View state size limit & de-reference null for transient

I have below code to allow multiple file attachments to be inserted against a parent record id. But this results in either View state size limit exceeded (not all the time) or dereferencing null ...
2
votes
1answer
121 views

Retreiving the value causing a DUPLICATE_VALUE DML Exception

I have an inventory management system I am working on and I have the need to let users input values to be created into inventory. These values consist of numbers that are used as the name for the ...
1
vote
2answers
89 views

DML in the loop followed by break

We all know that there is nothing worse than have a DML operation in the loop. Recently I've found a line of code in our project with a DML in the loop BUT followed by break; operator: for(Object__c ...
0
votes
1answer
52 views

Database DML throwing exceptions

According to SF if we use the Database class to issue a DML command: instead of exceptions, a result object array (or one result object if only one sObject was passed in) is returned containing ...
2
votes
1answer
159 views

Is upsert the right thing to save new or existing records?

In many of my Controller extensions I have save action methods that work for NEW and EDIT scenarios. I simply use upsert record instead of update / insert record in such cases. But now I am running ...
3
votes
2answers
170 views

Lead Trigger to prevent duplicates

I'm trying to create some code to prevent the creation of duplicate leads when there is already an existing contact in the database with the same email address. Not only this, but, if a matching ...
0
votes
1answer
106 views

Standard Case Notification when Owner is Changed via Visualforce page not working?

Currently we have a setup wherein when the owner of a case is updated via a Visualforce page. The problem is the Standard Case Notiifcation when the owner is changed is not being sent out when the ...
0
votes
1answer
56 views

Can I update data without updating the LastModifiedDate for a particular transaction?

I am migrating over legacy fields within a Salesforce org, but not performing any actual data updates (just moving some fields around). For this reason, I'd like to preserve the existing ...
0
votes
0answers
241 views

Too many DML statements: 151 - no DML in a for loop (that I can see)

I'm trying to build a newsletter manager that allows users to easily update and clear newsletter campaign members based on their subscription and region without having to run multiple reports. I've ...
4
votes
1answer
132 views

Database class commit

Why does Database class not provide commit method so that we can commit explicitly as well while in a transaction as we can do a rollback.
1
vote
2answers
599 views

MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object

I've written a trigger that will add users to a public group but can't seem to get my test class to work. I have 100% code coverage but the test keeps failing with the Mixed DML Operation error. ...
1
vote
1answer
53 views

How to update Latitude/Longitude in salesforce Organization object?

I got DML not allowed on Organization error when I try to update the object in apex code. I checked the documentation. It looks like Organization object can be updated. Does anyone know why the ...
1
vote
2answers
39 views

How can I add a role and use apex managed sharing all at once?

Question is in the title. For context, when a certain record is added, we would like to create a role (named after that record) and share it with that newly created role. Because of that, the flow ...
0
votes
0answers
52 views

Update DML statement with Regular Expression match between characters

I'd really appreciate some help on this trigger please - here's what I'm trying to do and the code so far. Thanks in advance for your help. Custom Object: NVMStatsSF__NVM_Call_Summary__c Field: ...
1
vote
1answer
249 views

error in Test Class System.DmlException: NVALID_CROSS_REFERENCE_KEY

Getting this error in Test Class System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, only portal users can be associated to a contact: [] ...
0
votes
1answer
50 views

Database.rollback() risks and alternative

I've inherited some complex logic that does several different DML actions within the same (fairly long) method and if there are failures I need to revert everything that's been previously done. The ...
0
votes
1answer
42 views

Current transaction identification

I'm working with webservice callouts and DML's at the same time. Is it possible to identify the current transaction like getting its ID ?
2
votes
1answer
86 views

Update based on csv data

I have a requirement to update records of custom object Incident_abv__c if the value of it's Name field in present in csv. I have below class and page to do the same. But when I click the Read csv ...
3
votes
1answer
51 views

Compiled successfully, update not happenning

I have below batch class that is not doing DML update operation also no error in debug log. Can someone please help me here? Batch class: global class AckCallUpdatenew implements ...
0
votes
2answers
508 views

Too many DML rows: 10001 issue

I have a trigger that works perfectly in my sandbox. When I try to deploy, I get the following error message: receiving_Tests.receiving_Trigger_Tests(), Details: System.LimitException: Too many ...
6
votes
1answer
733 views

Too many if statments?

So the Apex docs say you have to set the value of the master record if you want to retain the discarded account field values before the merge operation. Is there a better way to do validation for a ...
-2
votes
2answers
137 views

Continue not working properly

I have below code where I do a check if a list value is contained in a set then jump to next iteration without executing the next statement that is update. Here I am using 'continue;' statement in ...
1
vote
0answers
30 views

Update fails without error

I have below class where update on mycallsInc not happening. Can someone please help me? public void Publish() { List<Incident_abv__c> selIncs = ...