function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Yaroslav ProYaroslav Pro 

System.DmlException: Update failed

Hello 
I cant solve this, maybe someone can help me

System.DmlException: Update failed. First exception on row 0 with id 0066E000004pfWbQAI; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, In the stage Demo, you need to fill in the fields "Scope Test Determined", Testperiod In Salesforce" and Order Task Sent to Salesforce".: []

static testMethod void testClosedWonUpdate_positive_03(){
List<Opportunity> oppList = [SELECT Id, StageName,End_Date_Test_Phase__c FROM Opportunity WHERE Name LIKE 'Test%' LIMIT 1];
Opportunity opp = oppList.get(0);
opp.StageName = 'Test';
Date d = date.today();
opp.End_Date_Test_Phase__c = d.addDays(40);
update opp;
System.debug(' 632 ====> ' + opp);
List<Account> aList = [SELECT Id, Name FROM Account WHERE Name LIKE 'Test%' LIMIT 1];
Account a = aList.get(0);
System.debug(' 636 ====> ' + a);
List<Asset> assets = [SELECT Id, Price_Agreements__c, Price, Status, Product2Id, Test_Asset__c, IsCompetitorProduct
FROM Asset WHERE AccountId = :a.Id];
System.debug(' 640 ====> ' + assets);
System.assertEquals('In test', assets[0].Status);
Test.startTest();
opp.StageName = 'Closed Won';
update opp;
Test.stopTest();
OpportunityLineItem ol = [SELECT OpportunityId FROM OpportunityLineItem WHERE Name LIKE 'Test%'];
List<Asset> assets1 = [SELECT Id, Price_Agreements__c, Price, Product2Id, Test_Asset__c, IsCompetitorProduct
FROM Asset WHERE AccountId = :a.Id];
List<OpportunityLineItem> oliList = [select Id, Asset__c from OpportunityLineItem where Id =: ol.Id LIMIT 1];
System.assertEquals(1, assets1.size());
System.debug(' 657 ====> ' + assets1);
System.assertEquals(false, assets1[0].Test_Asset__c);
System.assertEquals(false, assets1[0].IsCompetitorProduct);
System.assertEquals(oliList[0].Asset__c, assets1[0].Id);
}

Let me know

 
Best Answer chosen by Yaroslav Pro
BODDH PRAKASH 15BODDH PRAKASH 15
Hi Yaroslav 

As your error shows, There is a custom validation rule (FIELD_CUSTOM_VALIDATION_EXCEPTION) written on Opportunity object. you are trying to insert new opportunity stage. Please insert stage name like Closed/Won etc. which are predefined.

I hope it will help you. 

 

All Answers

BODDH PRAKASH 15BODDH PRAKASH 15
Hi Yaroslav 

As your error shows, There is a custom validation rule (FIELD_CUSTOM_VALIDATION_EXCEPTION) written on Opportunity object. you are trying to insert new opportunity stage. Please insert stage name like Closed/Won etc. which are predefined.

I hope it will help you. 

 
This was selected as the best answer
Yaroslav ProYaroslav Pro
Can i get two dml operations in my method?
Niraj Kr SinghNiraj Kr Singh
Hi Yaroslav 

Can you plz check with validation rule written on Opportunity, due to that you are getting Field Custom Validation Exception.
And Update your this line of code:
opp.StageName = 'Test'; // Give here actual "StageName" picklist value like: Prospecting / Qualification ... etc.

Hope it will help you.