You need to sign in to do that
Don't have an account?
Naureen Hameed 39
Need help with a Quote Line Trigger Deployment Error
Hello
I have a Trigger on Quote Line for Products
i)Integration
ii)Integration Bundle
iii) Platform Fee
Upon selection of the above three products, an additional multiselect field on Quote Line should be chosen to give further details on on integrations (field "Platform__c") or Plarform Fees (Custom_Platform_Selection__c).
The values of the additional field should then be stamped on a text field "PlatformText__c". Thats the main function of this Trigger.
trigger QuoteLineItemTrigger on QuoteLineItem (after insert, after update) {
Set<Id> quoteIds = new Set<Id>();
// Collect the Quote Ids
for (QuoteLineItem quoteLine : Trigger.new) {
quoteIds.add(quoteLine.QuoteId);
}
// Query the related Quote Line Items and populate the PlatformText__c field
List<QuoteLineItem> quoteLinesToUpdate = new List<QuoteLineItem>();
// Process the Quote Line Items for Integration products
for (QuoteLineItem quoteLine : [SELECT Id, Product2.Name, Platform__c, Custom_Platform_Selection__c, PlatformText__c
FROM QuoteLineItem
WHERE QuoteId IN :quoteIds
AND (Product2.Name = 'Integration' OR Product2.Name = 'Integration Bundle')
AND Platform__c != null]) {
String platformText = String.join(quoteLine.Platform__c.split(';'), ';');
if (!platformText.equals(quoteLine.PlatformText__c)) {
quoteLine.PlatformText__c = platformText;
quoteLinesToUpdate.add(quoteLine);
}
}
// Process the Quote Line Items for Platform Fee products
for (QuoteLineItem quoteLine : [SELECT Id, Product2.Name, Platform__c, Custom_Platform_Selection__c, PlatformText__c
FROM QuoteLineItem
WHERE QuoteId IN :quoteIds
AND Product2.Name = 'Platform Fee'
AND Custom_Platform_Selection__c != null]) {
String platformText = String.join(quoteLine.Custom_Platform_Selection__c.split(';'), ',');
if (!platformText.equals(quoteLine.PlatformText__c)) {
quoteLine.PlatformText__c = platformText;
quoteLinesToUpdate.add(quoteLine);
}
}
// Update the Quote Line Items
if (!quoteLinesToUpdate.isEmpty()) {
try {
update quoteLinesToUpdate;
} catch (DmlException e) {
// Handle the exception if needed
}
}
}
Test Class:
@isTest
private class QuoteLineItemTriggerTest {
@isTest
static void testTrigger() {
// Ensure the standard pricebook is active
Id pricebookId = Test.getStandardPricebookId();
Pricebook2 standardPricebook = new Pricebook2(
Id = pricebookId,
IsActive = true
);
update standardPricebook;
// Create test data
Quote testQuote = new Quote(
Name = 'Test Quote',
OpportunityId = '0064U00000qZMNmQAO' // Replace with a valid Opportunity Id
);
insert testQuote;
// Create Product2 records
Product2 integrationProduct = new Product2(Name = 'Integration');
insert integrationProduct;
Product2 platformFeeProduct = new Product2(Name = 'Platform Fee');
insert platformFeeProduct;
// Create PricebookEntry records for your products in the standard Pricebook
PricebookEntry integrationStandardPrice = new PricebookEntry(
Pricebook2Id = pricebookId, // Use the retrieved pricebookId
Product2Id = integrationProduct.Id,
UnitPrice = 100.00, // Set an appropriate UnitPrice
IsActive = true
);
insert integrationStandardPrice;
PricebookEntry platformFeeStandardPrice = new PricebookEntry(
Pricebook2Id = pricebookId, // Use the retrieved pricebookId
Product2Id = platformFeeProduct.Id,
UnitPrice = 50.00, // Set an appropriate UnitPrice
IsActive = true
);
insert platformFeeStandardPrice;
// Create a custom pricebook for testing
Pricebook2 customPricebook = new Pricebook2(
Name = 'Custom Pricebook',
IsActive = true
);
insert customPricebook;
// Create PricebookEntry records for your products in the custom pricebook
PricebookEntry integrationPricebookEntry = new PricebookEntry(
Pricebook2Id = customPricebook.Id,
Product2Id = integrationProduct.Id,
UnitPrice = 100.00, // Set an appropriate UnitPrice
IsActive = true
);
insert integrationPricebookEntry;
PricebookEntry platformFeePricebookEntry = new PricebookEntry(
Pricebook2Id = customPricebook.Id,
Product2Id = platformFeeProduct.Id,
UnitPrice = 50.00, // Set an appropriate UnitPrice
IsActive = true
);
insert platformFeePricebookEntry;
// Update the Quote to use the custom pricebook
testQuote.Pricebook2Id = customPricebook.Id;
update testQuote;
// Create QuoteLineItem records using the custom pricebook entries
QuoteLineItem integrationLineItem = new QuoteLineItem(
QuoteId = testQuote.Id,
PricebookEntryId = integrationPricebookEntry.Id,
Quantity = 2,
Platform__c = 'Absolute;Citrix Systems'
);
QuoteLineItem platformFeeLineItem = new QuoteLineItem(
QuoteId = testQuote.Id,
PricebookEntryId = platformFeePricebookEntry.Id,
Quantity = 3,
Custom_Platform_Selection__c = 'Production Environment;CSM'
);
List<QuoteLineItem> quoteLineItems = new List<QuoteLineItem> {
integrationLineItem,
platformFeeLineItem
};
// Test trigger execution
Test.startTest();
insert quoteLineItems;
Test.stopTest();
// Verify results
integrationLineItem = [SELECT PlatformText__c FROM QuoteLineItem WHERE Id = :integrationLineItem.Id];
platformFeeLineItem = [SELECT PlatformText__c FROM QuoteLineItem WHERE Id = :platformFeeLineItem.Id];
System.assertEquals('Absolute;Citrix Systems', integrationLineItem.PlatformText__c);
System.assertEquals('Production Environment;CSM', platformFeeLineItem.PlatformText__c);
}
}
Deploymeny Error:
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [UnitPrice]: [UnitPrice]
Stack Trace: Class.QuoteLineItemTriggerTest.testTrigger: line 86, column 1
The error is looking for Unit Price but the Unit Price is in the test Class.
Please help and thanks in advance.
I have a Trigger on Quote Line for Products
i)Integration
ii)Integration Bundle
iii) Platform Fee
Upon selection of the above three products, an additional multiselect field on Quote Line should be chosen to give further details on on integrations (field "Platform__c") or Plarform Fees (Custom_Platform_Selection__c).
The values of the additional field should then be stamped on a text field "PlatformText__c". Thats the main function of this Trigger.
trigger QuoteLineItemTrigger on QuoteLineItem (after insert, after update) {
Set<Id> quoteIds = new Set<Id>();
// Collect the Quote Ids
for (QuoteLineItem quoteLine : Trigger.new) {
quoteIds.add(quoteLine.QuoteId);
}
// Query the related Quote Line Items and populate the PlatformText__c field
List<QuoteLineItem> quoteLinesToUpdate = new List<QuoteLineItem>();
// Process the Quote Line Items for Integration products
for (QuoteLineItem quoteLine : [SELECT Id, Product2.Name, Platform__c, Custom_Platform_Selection__c, PlatformText__c
FROM QuoteLineItem
WHERE QuoteId IN :quoteIds
AND (Product2.Name = 'Integration' OR Product2.Name = 'Integration Bundle')
AND Platform__c != null]) {
String platformText = String.join(quoteLine.Platform__c.split(';'), ';');
if (!platformText.equals(quoteLine.PlatformText__c)) {
quoteLine.PlatformText__c = platformText;
quoteLinesToUpdate.add(quoteLine);
}
}
// Process the Quote Line Items for Platform Fee products
for (QuoteLineItem quoteLine : [SELECT Id, Product2.Name, Platform__c, Custom_Platform_Selection__c, PlatformText__c
FROM QuoteLineItem
WHERE QuoteId IN :quoteIds
AND Product2.Name = 'Platform Fee'
AND Custom_Platform_Selection__c != null]) {
String platformText = String.join(quoteLine.Custom_Platform_Selection__c.split(';'), ',');
if (!platformText.equals(quoteLine.PlatformText__c)) {
quoteLine.PlatformText__c = platformText;
quoteLinesToUpdate.add(quoteLine);
}
}
// Update the Quote Line Items
if (!quoteLinesToUpdate.isEmpty()) {
try {
update quoteLinesToUpdate;
} catch (DmlException e) {
// Handle the exception if needed
}
}
}
Test Class:
@isTest
private class QuoteLineItemTriggerTest {
@isTest
static void testTrigger() {
// Ensure the standard pricebook is active
Id pricebookId = Test.getStandardPricebookId();
Pricebook2 standardPricebook = new Pricebook2(
Id = pricebookId,
IsActive = true
);
update standardPricebook;
// Create test data
Quote testQuote = new Quote(
Name = 'Test Quote',
OpportunityId = '0064U00000qZMNmQAO' // Replace with a valid Opportunity Id
);
insert testQuote;
// Create Product2 records
Product2 integrationProduct = new Product2(Name = 'Integration');
insert integrationProduct;
Product2 platformFeeProduct = new Product2(Name = 'Platform Fee');
insert platformFeeProduct;
// Create PricebookEntry records for your products in the standard Pricebook
PricebookEntry integrationStandardPrice = new PricebookEntry(
Pricebook2Id = pricebookId, // Use the retrieved pricebookId
Product2Id = integrationProduct.Id,
UnitPrice = 100.00, // Set an appropriate UnitPrice
IsActive = true
);
insert integrationStandardPrice;
PricebookEntry platformFeeStandardPrice = new PricebookEntry(
Pricebook2Id = pricebookId, // Use the retrieved pricebookId
Product2Id = platformFeeProduct.Id,
UnitPrice = 50.00, // Set an appropriate UnitPrice
IsActive = true
);
insert platformFeeStandardPrice;
// Create a custom pricebook for testing
Pricebook2 customPricebook = new Pricebook2(
Name = 'Custom Pricebook',
IsActive = true
);
insert customPricebook;
// Create PricebookEntry records for your products in the custom pricebook
PricebookEntry integrationPricebookEntry = new PricebookEntry(
Pricebook2Id = customPricebook.Id,
Product2Id = integrationProduct.Id,
UnitPrice = 100.00, // Set an appropriate UnitPrice
IsActive = true
);
insert integrationPricebookEntry;
PricebookEntry platformFeePricebookEntry = new PricebookEntry(
Pricebook2Id = customPricebook.Id,
Product2Id = platformFeeProduct.Id,
UnitPrice = 50.00, // Set an appropriate UnitPrice
IsActive = true
);
insert platformFeePricebookEntry;
// Update the Quote to use the custom pricebook
testQuote.Pricebook2Id = customPricebook.Id;
update testQuote;
// Create QuoteLineItem records using the custom pricebook entries
QuoteLineItem integrationLineItem = new QuoteLineItem(
QuoteId = testQuote.Id,
PricebookEntryId = integrationPricebookEntry.Id,
Quantity = 2,
Platform__c = 'Absolute;Citrix Systems'
);
QuoteLineItem platformFeeLineItem = new QuoteLineItem(
QuoteId = testQuote.Id,
PricebookEntryId = platformFeePricebookEntry.Id,
Quantity = 3,
Custom_Platform_Selection__c = 'Production Environment;CSM'
);
List<QuoteLineItem> quoteLineItems = new List<QuoteLineItem> {
integrationLineItem,
platformFeeLineItem
};
// Test trigger execution
Test.startTest();
insert quoteLineItems;
Test.stopTest();
// Verify results
integrationLineItem = [SELECT PlatformText__c FROM QuoteLineItem WHERE Id = :integrationLineItem.Id];
platformFeeLineItem = [SELECT PlatformText__c FROM QuoteLineItem WHERE Id = :platformFeeLineItem.Id];
System.assertEquals('Absolute;Citrix Systems', integrationLineItem.PlatformText__c);
System.assertEquals('Production Environment;CSM', platformFeeLineItem.PlatformText__c);
}
}
Deploymeny Error:
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [UnitPrice]: [UnitPrice]
Stack Trace: Class.QuoteLineItemTriggerTest.testTrigger: line 86, column 1
The error is looking for Unit Price but the Unit Price is in the test Class.
Please help and thanks in advance.