2022 Developer Survey is open! Take survey.

Questions tagged [dmlexception]

Any problem with a DML statement, such as an insert statement missing a required field on a record.

Filter by
Sorted by
Tagged with
-1 votes
1 answer
26 views

I am unable to insert 10000 records. Getting Too man query rows error

public class CreateBulkAccounts { @future Public static void method1() { List<Account> acList = new List<Account>(); for(integer i=0; i<10000; i++) ...
user avatar
0 votes
0 answers
34 views

Insert JournalType DUPLICATE_VALUE exception in Loyalty cloud test class

We are working with Salesforce Loyalty cloud. In one of our test classes, we are setting up data, where we try to insert some records of the JournalType standard object coming with Loyalty cloud. ...
user avatar
0 votes
1 answer
23 views

Metadata cannot be deployed from within a test [duplicate]

When trying to insert a custom metadata record within the test it gives me the following error @IsTest public class Object_1TriggerTest { @IsTest public static void Load_field_1_from_metadata()...
user avatar
1 vote
1 answer
39 views

LIMIT_EXCEEDED, limit exceeded: [] when creating Community User

Suddenly getting the following error: System.DmlException: Insert failed. First exception on row 0; first error: LIMIT_EXCEEDED, limit exceeded: [] when trying to insert a Community User via apex ...
user avatar
  • 91
0 votes
1 answer
46 views

Too many DML statements: 1

im working with LWC, creating a button to upload files. but, when i click submit button console shows that error: "Too many DML statements: 1" <template> <lightning-card title=&...
user avatar
0 votes
2 answers
119 views

Handling FIELD_INTEGRITY_EXCEPTION with try catch and logging errors

I have got an apex trigger that sometimes errors with System.DmlException: Update failed. First exception on row 0 with id 00Q0800000fhnM2EAI; first error: FIELD_INTEGRITY_EXCEPTION The reasons for ...
user avatar
  • 103
0 votes
0 answers
14 views

Unable to Create Test User : MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object [duplicate]

I am trying to write an unit test to create a test user. I get the above error upon insert. Any ideas, workarounds or suggestions. Following is a sample of the test method. This only seems to happen ...
user avatar
0 votes
1 answer
28 views

Create an account every time a contact is created (and the account is not existing in the Org)

I have a requirement to create a new account(if the entered account doesn't exist already) every time a contact is created/edited from ETL (The ETL profile user) public static void createAutoVendor(...
user avatar
2 votes
1 answer
140 views

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY error thrown in random places

Recently I've started getting error message: System.DmlException: Upsert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, Access to entity 'AIInsightValue'...
user avatar
0 votes
0 answers
29 views

Restrict user deactivation if Account is owned by the user and send an Email with details

please help. I am new to SFDC please help. Requirement: Restrict user deactivation if Account is owned by the user and send an Email with details. Trigger on user object: trigger userTrigger on ...
user avatar
1 vote
1 answer
114 views

DmlException Creating CMS Library/Folders

I have some Apex code written to create a new Account, and then create a new Library (ContentWorkspace) and new Folder (ContentFolder) within that Library to house assets for that Account. It appears ...
user avatar
0 votes
1 answer
32 views

when running test class, encountering runAs() issues with user having insufficient access to upload resume

I am encountering an issue with running my test class as a made-up user. It seems like I have insufficient access to uploading files onto the org, anyone would be able to point me in the right ...
user avatar
0 votes
1 answer
98 views

how to Unit Test a failure to deactivate a user (DML failure)

/** * Restful resource Patch (update record) request passes user federation Identifier * @param emailId */ @HttpPatch global static List<ResponseWrapper> DeactivateUser_Restful_Ctl(string ...
user avatar
  • 464
1 vote
0 answers
179 views

Updating Opportunity Splits in Apex field integrity exception

I'm trying to automate Opportunity Splits and I'm running into the following when trying to upsert them for a given split type: System.DmlException: Upsert failed. First exception on row 0 with id ...
user avatar
  • 1,007
0 votes
1 answer
197 views

Throw an exception in Apex if attachment is null

I have a Visualforce form that takes attachments of which I need to make required in order for the user to proceed to the next screen. Since the record doesn't get inserted until the end of the multi-...
user avatar
0 votes
1 answer
87 views

How to get the inner exception?

So I catch a DMLException which is caused by a custom exception from a managed package, now how can I get that custom exception? Here is the log: 18:33:24.391 EXECUTION_STARTED ... 18:33:25.710 ...
user avatar
1 vote
1 answer
141 views

ContentDistribution FIELD_INTEGRITY_EXCEPTION

I'm trying to insert a record to ContentDistribution object using the following: Here is the doc says: https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/...
user avatar
  • 6,559
0 votes
1 answer
56 views

Writing efficient code

I would like to understand the difference between snippet 1 and snippet 2. In snippet 1 I get a DML rows limit exception whereas in snippet 2, I don't get any exception. What makes snippet 2 not throw ...
user avatar
0 votes
0 answers
29 views

DmlExecutionException: Update failed.first error: DUPLICATE_VALUE, duplicate value found

I understand DUPLICATE_VALUE DML Exception on insert of a record which is already existing However, I am observing this issue for an update on the existing record. When I find an existing contact ...
user avatar
  • 1
0 votes
1 answer
208 views

How to avoid MIXED dml Exception in update operation? [closed]

I got System.DmlException in update operation. Can anyone please check the below code and help me to resolve the exception. I have tried to solve it for the last two days but I couldn't find a ...
user avatar
  • 1
1 vote
1 answer
181 views

MIXED_DML_OPERATION : Can not insert a user record from account trigger even when User Role is null

I am trying to create a community user in an after update trigger of account. I am setting the UserRoleId = null but still am getting MIXED_DML_OPERATION exception. As per documentation: You can ...
user avatar
  • 2,450
0 votes
1 answer
93 views

DataLoader on contacts causing System.LimitException: Too many DML statements: 151

I have a trigger on contacts that is causing DML errors and I'm not sure where the problem is as I only have one update on a list. This is occurring when I am using the Data loader to update about 30k ...
user avatar
1 vote
1 answer
53 views

How do I take out the DML statements out of the loop? [duplicate]

I am new to apex, I've achieved the basic working code of what I had to, in java. But now I am told that I cant do DML statements or queries inside loops. Any help/explanation as to how I could I do ...
user avatar
  • 95
0 votes
0 answers
448 views

Database.convertLead() - when validation exception fires, it is not possible to catch it

I've got implemented code where I do automatic Lead conversion. The conversion works fine, but there are some custom validation rules in the org. When these validation rules fire, an ugly message is ...
user avatar
  • 1
0 votes
1 answer
39 views

UNABLE_TO_LOCK_ROW while running two or more tests

I'm trying to run two different test classes, but every time I do this, one of them shows error on the setup method, right in the line where I'm going to insert a new user. Is there a way to fix this? ...
user avatar
0 votes
1 answer
862 views

Getting the following error INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY for a site guest user

So I know similar questions has been asked before, but I couldn't find a solution using the following links: Link1, Link2, Link3 (and more) The situation is as follows. So I have a form (a visualforce ...
user avatar
  • 103
1 vote
1 answer
30 views

I'm trying to insert new record but it gives error as Line: 7, Column: 1 System.StringException: Invalid id: objcus.id

Apex_Customer__c objcus=new Apex_Customer__c(); objcus.Name='Test ABC'; insert objcus;//it will creat new customer records Apex_Invoice__c objnewinvoice=new Apex_Invoice__c(); objnewinvoice....
user avatar
2 votes
1 answer
163 views

Dynamically Insert parent child records in a single DML

I'm trying to insert contact and account records in a single DML. In my case I don't want to use the . operator Instead, I'm using the put operator to insert records. Account acc=new Account(Name='...
user avatar
0 votes
2 answers
2k views

MIXED_DML_OPERATION, DML operation on setup object is not permitted Contact User

Hi i have a problem cuz I'm trying do sth like below: this method has adnotation AuraEnabled Contact contact = getContact((Id)contactId); contact.Inactive__c = true; User user = getUserByContactId(...
user avatar
  • 35
0 votes
1 answer
3k views

Apex Superbadge Automation Test Failure - System.DmlException: INSERT FAILED and UPDATE FAILED

Working on the Apex superbadge challenges and got stuck on Challenge 4 - "Test automation logic". I am getting the following error: Although the test coverage is 100% and is working without any ...
user avatar
0 votes
0 answers
263 views

Self Lookup restriction not respected for a lookup field

I have 2 lookup fields to Opportunity in Opportunity Object. Parent Opportunity and Ultimate Parent Opportunity. I cannot update the parent to itself, which gives the expected error below You ...
user avatar
  • 718
-1 votes
2 answers
47 views

Can't cover DMLException with my test

I'm trying to cover my Exceptionm But I don't know. how to do this. When I try to insert a record without Required fields, I get the System.DmlException: Insert failed. First exception on row 0; first ...
user avatar
  • 45
0 votes
2 answers
2k views

Getting CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY error when testing Apex

I'm re-writing unit tests for the Apex Specialist superbadge (yes, re-writing, I successfully completed the superbadge a couple of days ago, and found a few bugs while playing around today, decided to ...
user avatar
  • 1
0 votes
1 answer
122 views

How to get the root cause of an unhandled trigger error?

If I have some code doing DML which runs a trigger, and then that trigger throws an unhandled exception, how can I get the real cause of the problem? For example, suppose I have a really dumb trigger:...
user avatar
  • 12.7k
1 vote
3 answers
824 views

How to cover Catch block in ApexUnitTest class when using DML statement in try body

I have some apex code, where I try to upsert a list of records: try { upsert recordList Accounts; } catch (DmlException e) { //do a loooot of stuff in order to provide a proper ...
user avatar
4 votes
2 answers
411 views

Scratch Org: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>: []

I and my whole team encounter this error while inserting some data into a new Scratch Org. DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>: ...
user avatar
  • 320
0 votes
1 answer
37 views

Delete Scheduled Jobs using Apex in one go

I have More than 2500 Scheduled Jobs and i want to delete them but the issue is when i try system.abortJobId(jobId); on a list of job id which i fetched using soql it says not more than 150 DML ...
user avatar
2 votes
1 answer
4k views

INSUFFICIENT_ACCESS_OR_READONLY when editing an Order

When editing an Order (either through the UI or via an Apex program that does DML), I get First exception on row 0 with id 801.... INSUFFICIENT_ACCESS_OR_READONLY insufficient access rights on ...
user avatar
  • 61.4k
0 votes
2 answers
1k views

Update failed. First exception on row 0 with id ******; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, LeadTrigger: maximum trigger depth exceeded

Error on Line 154: Update failed. First exception on row 0 with id ******; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, LeadTrigger: maximum trigger depth exceeded public class ...
user avatar
0 votes
1 answer
341 views

Alternatives to add error

I've been using addError() to prevent dml insertions of records that don't accomplish with the validation rule. The problem is that using that, if i insert a list of 100 records and one fails, the ...
user avatar
1 vote
1 answer
376 views

Test Class Failing : DML Exception

I'm having trouble getting my test class to pass tests. Getting: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Select from Add ...
user avatar
  • 1,095
0 votes
2 answers
177 views

How to cater opportunity insertion in my TEST class

I have a method in APEX class that does variety of checks via If else conditions with some SOQL statements. I created test data(Accounts, custom object records) to test the SOQL statements and it ...
user avatar
  • 555
2 votes
1 answer
1k views

Getting 'FATAL_ERROR System.TypeException: DML operation INSERT not allowed on Group' on Apex Trigger

I am getting: "FATAL_ERROR|System.TypeException: DML operation INSERT not allowed on Group" error on an apex trigger (line 43) when I am logging in as any other user except System Admin. I am ...
user avatar
  • 35
5 votes
1 answer
3k views

System.DmlException: Insert failed. STRING_TOO_LONG, Body: data value too large

I have a string which has a length of 89308 which represents a PDF document. I want to store this data into a ContentVersion like this: ContentVersion contentVersion = new ContentVersion( ...
user avatar
  • 8,223
8 votes
3 answers
1k views

How to Aura Handle multiple DmlExceptions

How should I handle multiple DmlException messages when using AuraHandledException inside an Apex Controller. If I do this: try { upsert value; } catch(DmlException e) { throw new ...
user avatar
  • 8,223
0 votes
1 answer
170 views

List.clear() not emptying my List

The project that I am working on has an API endpoint that is meant to upload a large number of records into three different tables: Careers, Degrees, and CareerDegreeRelationships. The endpoint is ...
user avatar
  • 1,000
0 votes
1 answer
437 views

Unable to merge contacts (fails to update field)

I use the native merge functionality to glue two duplicate contacts together programmatically: merge target source; Yet this invokes the following error: 12:06:49:251 USER_DEBUG [46]|DEBUG|DML_e: ...
user avatar
  • 95
0 votes
1 answer
1k views

Need help with this strange error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>: []

I have an apex code which identifies users who have subscribed to an Account( basically followed an Account for any chatter posts ).The code then subscribes these users to the related Opportunities of ...
user avatar
  • 640
0 votes
1 answer
57 views

How can I allow a user with the 'Partner: Executive Full License' to edit their own contact?

I have a use case where some Apex code will need to run as a user with this profile. I am updating some fields in this code and then performing an update on the contact that's associated with this ...
user avatar
  • 410
1 vote
1 answer
841 views

How to process more than 10K records from batch in one Transaction?

we have a functionality as following: on VF page we define some criteria say e.g Account Name = Nachiket and some other configurations. configuration details we store in custom object say Custom ...
user avatar