You need to sign in to do that
Don't have an account?
Shruthi Narsi
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [OpportunityId__c]: [OpportunityId__c]
I have written test class to sync quote. Test class failed. Below is the error
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [OpportunityId__c]: [OpportunityId__c]
@isTest
public class QuoteLineItemTestClass {
@TestSetup private static void setUpData(){
Quotes__c a = New Quotes__c(Name='Test');
insert a;
Opportunities__c o = New Opportunities__c(Stage__c = 'prospecting',Close_Date__c = date.today(),Name = 'test');
insert o;
//....Create Products, pricebookentries, etc needed for the QLI and the OLI
OpportunityLineItem__c oli = New OpportunityLineItem__c();
insert oli;
Quotes__c q = New Quotes__c();
insert q;
QuoteLineitem__c qli = New QuoteLineitem__c();
insert qli;
}
static testMethod void basicTest() {
QuoteLineitem__c qli = [Select Id,Name,QuotesId__c From QuoteLineitem__c]; //We know we created one and only one
qli.QuotesId__c = 'Test2'; //This is what your code looks to compare if it should run;
update qli; //This should fire your code
//Query for OLI and assert the field was updated appropriatly
OpportunityLineItem__c oli = [Select Name,OpportunityId__c From OpportunityLineItem__c];
system.assertEquals('check',oli.Product2Id__c, 'The field was not updated when it should have been');
}
static testMethod void basicTest_NoProductMatch() {
//Negative Use case
//Create a QLI that does not have a corresponding OLI with same product
QuoteLineitem__c qli = New QuoteLineitem__c();
insert qli;
qli.QuotesId__c = 'Test2'; //This is what your code looks to compare if it should run;
update qli; //This should fire your code
//Query for OLI and assert the field was NOT updated since Product match was not found (quoery requirement in your code)
OpportunityLineItem__c oli = [Select Name,OpportunityId__c From OpportunityLineItem__c];
system.assertNotEquals('True',oli.Name,'The field was updated when the product did not match the updated QLI');
}
}
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [OpportunityId__c]: [OpportunityId__c]
@isTest
public class QuoteLineItemTestClass {
@TestSetup private static void setUpData(){
Quotes__c a = New Quotes__c(Name='Test');
insert a;
Opportunities__c o = New Opportunities__c(Stage__c = 'prospecting',Close_Date__c = date.today(),Name = 'test');
insert o;
//....Create Products, pricebookentries, etc needed for the QLI and the OLI
OpportunityLineItem__c oli = New OpportunityLineItem__c();
insert oli;
Quotes__c q = New Quotes__c();
insert q;
QuoteLineitem__c qli = New QuoteLineitem__c();
insert qli;
}
static testMethod void basicTest() {
QuoteLineitem__c qli = [Select Id,Name,QuotesId__c From QuoteLineitem__c]; //We know we created one and only one
qli.QuotesId__c = 'Test2'; //This is what your code looks to compare if it should run;
update qli; //This should fire your code
//Query for OLI and assert the field was updated appropriatly
OpportunityLineItem__c oli = [Select Name,OpportunityId__c From OpportunityLineItem__c];
system.assertEquals('check',oli.Product2Id__c, 'The field was not updated when it should have been');
}
static testMethod void basicTest_NoProductMatch() {
//Negative Use case
//Create a QLI that does not have a corresponding OLI with same product
QuoteLineitem__c qli = New QuoteLineitem__c();
insert qli;
qli.QuotesId__c = 'Test2'; //This is what your code looks to compare if it should run;
update qli; //This should fire your code
//Query for OLI and assert the field was NOT updated since Product match was not found (quoery requirement in your code)
OpportunityLineItem__c oli = [Select Name,OpportunityId__c From OpportunityLineItem__c];
system.assertNotEquals('True',oli.Name,'The field was updated when the product did not match the updated QLI');
}
}
oli.OpportunityId__c = o.Id;
Please above line before OpportunityLineItem__c insert.
Thanks,
Foram Rana
public class QuoteLineItemTestClass {
@TestSetup private static void setUpData(){
Quotes__c a = New Quotes__c(Name='Test');
insert a;
Opportunities__c o = New Opportunities__c(Stage__c = 'prospecting',Close_Date__c = date.today(),Name = 'test');
insert o;
//....Create Products, pricebookentries, etc needed for the QLI and the OLI
OpportunityLineItem__c oli = New OpportunityLineItem__c();
oli.OpportunityId__c = o.Id;
insert oli;
Quotes__c q = New Quotes__c();
insert q;
QuoteLineitem__c qli = New QuoteLineitem__c();
insert qli;
}
static testMethod void basicTest() {
QuoteLineitem__c qli = [Select Id,Name,QuotesId__c From QuoteLineitem__c]; //We know we created one and only one
qli.QuotesId__c = 'Test2'; //This is what your code looks to compare if it should run;
update qli; //This should fire your code
//Query for OLI and assert the field was updated appropriatly
OpportunityLineItem__c oli = [Select Name,OpportunityId__c From OpportunityLineItem__c];
system.assertEquals('check',oli.Product2Id__c, 'The field was not updated when it should have been');
}
static testMethod void basicTest_NoProductMatch() {
//Negative Use case
//Create a QLI that does not have a corresponding OLI with same product
QuoteLineitem__c qli = New QuoteLineitem__c();
insert qli;
qli.QuotesId__c = 'Test2'; //This is what your code looks to compare if it should run;
update qli; //This should fire your code
//Query for OLI and assert the field was NOT updated since Product match was not found (quoery requirement in your code)
OpportunityLineItem__c oli = [Select Name,OpportunityId__c From OpportunityLineItem__c];
system.assertNotEquals('True',oli.Name,'The field was updated when the product did not match the updated QLI');
}
}
@isTest
public class QuoteLineItemTestClass {
@TestSetup private static void setUpData(){
Quotes__c a = New Quotes__c(Name='Test');
insert a;
Opportunities__c o = New Opportunities__c(Stage__c = 'prospecting',Close_Date__c = date.today(),Name = 'test');
insert o;
//....Create Products, pricebookentries, etc needed for the QLI and the OLI
OpportunityLineItem__c oli = New OpportunityLineItem__c();
oli.Name = 'Test';
oli.OpportunityId__c = o.Id;
insert oli;
Quotes__c q = New Quotes__c();
q.Name = 'Test';
insert q;
QuoteLineitem__c qli = New QuoteLineitem__c();
qli.Name ='Test';
qli.QuotesId__c = q.Id;
insert qli;
}
static testMethod void basicTest() {
Quotes__c quo = New Quotes__c();
quo.Name = 'Test';
insert quo;
QuoteLineitem__c qli = [Select Id,Name,QuotesId__c From QuoteLineitem__c]; //We know we created one and only one
qli.QuotesId__c = quo.Id; //This is what your code looks to compare if it should run;
update qli; //This should fire your code
//Query for OLI and assert the field was updated appropriatly
OpportunityLineItem__c oli = [Select Name,OpportunityId__c From OpportunityLineItem__c];
}
static testMethod void basicTest_NoProductMatch() {
Quotes__c quo1 = New Quotes__c();
quo1.Name = 'Test';
insert quo1;
//Negative Use case
//Create a QLI that does not have a corresponding OLI with same product
QuoteLineitem__c qli = New QuoteLineitem__c();
qli.Name = 'test';
insert qli;
qli.QuotesId__c = qou1.Id; //This is what your code looks to compare if it should run;
update qli; //This should fire your code
//Query for OLI and assert the field was NOT updated since Product match was not found (quoery requirement in your code)
OpportunityLineItem__c oli = [Select Name,OpportunityId__c From OpportunityLineItem__c];
}
}
mark it as best answer if you resolve the issue.
Thanks,
Foram rana
@isTest
public class QuoteLineItemTestClass {
@TestSetup private static void setUpData(){
Opportunities__c o = New Opportunities__c(Stage__c = 'prospecting',Close_Date__c = date.today(),Name = 'test');
insert o;
Quotes__c a = New Quotes__c(Name='Test');
insert a;
OpportunityLineItem__c oli = New OpportunityLineItem__c();
oli.Name = 'Test';
oli.OpportunityId__c = o.Id;
insert oli;
//....Create Products, pricebookentries, etc needed for the QLI and the OLI
Quotes__c q = New Quotes__c();
q.Name = 'Test';
insert q;
QuoteLineitem__c qli = New QuoteLineitem__c();
qli.QuotesId__c = q.Id;
insert qli;
}
static testMethod void basicTest() {
Quotes__c quo = New Quotes__c();
quo.Name = 'Test';
insert quo;
Opportunities__c o1 = New Opportunities__c(Stage__c = 'prospecting',Close_Date__c = date.today(),Name = 'test');
insert o1;
QuoteLineitem__c qli = [Select Id,Name,QuotesId__c From QuoteLineitem__c]; //We know we created one and only one
qli.QuotesId__c = quo.Id; //This is what your code looks to compare if it should run;
update qli; //This should fire your code
//Query for OLI and assert the field was updated appropriatly
OpportunityLineItem__c oli = [Select Name,OpportunityId__c From OpportunityLineItem__c];
}
static testMethod void basicTest_NoProductMatch() {
Quotes__c quo1 = New Quotes__c();
quo1.Name = 'Test';
insert quo1;
Opportunities__c o1 = New Opportunities__c(Stage__c = 'prospecting',Close_Date__c = date.today(),Name = 'test');
insert o1;
//Negative Use case
//Create a QLI that does not have a corresponding OLI with same product
QuoteLineitem__c qli = New QuoteLineitem__c();
qli.QuotesId__c = quo1.Id;
insert qli;
qli.QuotesId__c = quo1.Id; //This is what your code looks to compare if it should run;
update qli; //This should fire your code
//Query for OLI and assert the field was NOT updated since Product match was not found (quoery requirement in your code)
OpportunityLineItem__c oli = [Select Name,OpportunityId__c From OpportunityLineItem__c];
}
}