Invocablemethod 不在 Apex 中创建记录 Class
Invocablemethod Not Creating Records in Apex Class
我是编写 Apex 的新手,但当我拆分下面创建的 class 时,一切似乎确实 运行 在可执行文件 window 中顺利地分开,但是当我从流程中 运行ning 时,它似乎根本没有创建记录。删除记录的方法似乎有效,但创建记录的方法似乎都无效。
非常感谢任何帮助或指导!
public without sharing class CreateQuoteProducts_NewOrRenewal{
@invocableMethod
public static void DeleteQuoteProductsMRF(List<Id> OrderId){
List<Quote_Product_MRF__c> QuoteProductsMRF = [SELECT id from Quote_Product_MRF__c WHERE Order__c in : OrderId];
if(!QuoteProductsMRF.isEmpty()){
delete QuoteProductsMRF;
}
}
public static void DeleteQuoteProductsOTF(List<Id> OrderId){
List<Quote_Product__c> QuoteProductsOTF = [SELECT id from Quote_Product__c WHERE Order__c in : OrderId];
if(!QuoteProductsOTF.isEmpty()){
delete QuoteProductsOTF;
}
}
/* ---START--- Create Quote Products MRF ---START--- */
public static void CreateQuoteProductsMRF(List<Id> OrderId){
List<AggregateResult> nrqpmrfOP = [
SELECT
count(Id) ct,
Order__c ord,
sum(Total_Monthly_Recurring_Fees__c) stmr,
sum(Monthly_Recurring_Fees__c) mr,
sum(Discount_MRF__c) dmr
FROM Order_Location_Package__c
WHERE Order__c in : OrderId AND Package__r.Monthly_Recurring_Price__c != null
GROUP BY Package__c, Order__c];
List<Quote_Product_MRF__c> nrqpmrf = New List<Quote_Product_MRF__c>();
for(AggregateResult ar : nrqpmrfOP){
Quote_Product_MRF__c QuoteProductMRF = New Quote_Product_MRF__c();
QuoteProductMRF.Quantity__c = (Decimal)ar.get('ct');
QuoteProductMRF.Order__c = (String)ar.get('ord');
QuoteProductMRF.Total_Monthly_Recurring_Fees__c = (Decimal)ar.get('stmr');
QuoteProductMRF.Monthly_Recurring_Fees__c = (Decimal)ar.get('mr');
QuoteProductMRF.Discount_MRF__c = (Decimal)ar.get('dmr');
QuoteProductMRF.Product_Type__c = 'Package';
nrqpmrf.add(QuoteProductMRF);
}
Insert nrqpmrf;
}
/* ---END--- Create Quote Products MRF ---END--- */
/* ---START--- Create Quote Products OTF ---START--- */
public static void CreateQuoteProductsOTF(List<Id> OrderId){
List<AggregateResult> nrqpmrfOP = [
SELECT
count(Id) ct,
Order__c ord,
sum(Total_One_Time_Fees__c) stmr,
sum(One_Time_Fees__c) mr,
sum(Discount_OTF__c) dmr
FROM Order_Location_Package__c
WHERE Order__c in : OrderId AND Package__r.One_Time_Price__c != null
GROUP BY Package__c, Order__c];
List<Quote_Product__c> nrqpotf = New List<Quote_Product__c>();
for(AggregateResult ar : nrqpmrfOP){
Quote_Product__c QuoteProductOTF = New Quote_Product__c();
QuoteProductOTF.Quantity__c = (Decimal)ar.get('ct');
QuoteProductOTF.Order__c = (String)ar.get('ord');
QuoteProductOTF.Total_One_Time_Fees__c = (Decimal)ar.get('stmr');
QuoteProductOTF.One_Time_Fees__c = (Decimal)ar.get('mr');
QuoteProductOTF.Discount_OTF__c = (Decimal)ar.get('dmr');
QuoteProductOTF.Product_Type__c = 'Package';
nrqpotf.add(QuoteProductOTF);
}
Insert nrqpotf;
}
/* ---END--- Create Quote Products ORD ---END--- */
}
测试Class低于
@isTest
private class CreateQuoteProducts_NewOrRenewalTest {
private static testMethod void doTest() {
Account testAcc = new Account ();
testAcc.Name = 'Test Account';
testAcc.Primary_Vertical__c = 'Multifamily Housing';
testAcc.Total_Locations_Owned_Managed__c = 1;
insert testAcc;
Opportunity testOpp = new Opportunity ();
testOpp.Name = 'Test Opportunity';
testOpp.AccountId = testAcc.Id;
testOpp.Opportunity_Source__c = 'Sales Generated';
testOpp.Type = 'New';
testOpp.StageName = 'Contract';
testOpp.Number_of_locations_for_opportunity__c = 1;
testOpp.Amount = 0;
testOpp.Implementation__c = 0;
testOpp.CloseDate = System.today() + 5;
testOpp.Deal_Confidence__c = 100;
insert testOpp;
Package__c testPackage = new Package__c ();
testPackage.Name = 'Test Package';
testPackage.Package_Type__c = 'Website Package';
testPackage.Status__c = 'Active';
testPackage.One_Time_Price__c = String.ValueOf(200);
testPackage.Monthly_Recurring_Price__c = String.ValueOf(100);
insert testPackage;
Order_Sheet__c testOrder = new Order_Sheet__c ();
testOrder.Opportunity__c = testOpp.id;
insert testOrder;
Order_New_Location__c testOrderLocation = new Order_New_Location__c ();
testOrderLocation.Order_Sheet__c = testOrder.id;
testOrderLocation.Name = 'Test Location';
insert testOrderLocation;
Order_Location_Package__c testOrderPackage = new Order_Location_Package__c ();
testOrderPackage.Order__c = testOrder.Id;
testOrderPackage.New_Location_Name__c = testOrderLocation.Id;
testOrderPackage.Package__c = testPackage.Id;
insert testOrderPackage;
/* --- Delete Quote Product MRF Test --- */
Test.startTest();
/* --- Create Quote Product MRF--- */
Quote_Product_MRF__c testQPMRF = new Quote_Product_MRF__c ();
testQPMRF.Order__c = testOrder.id;
insert testQPMRF;
/* --- Run Delete Method--- */
CreateQuoteProducts_NewOrRenewal.DeleteQuoteProductsMRF(new List<Id>{testOrder.id});
/* --- Query for QP OTF--- */
list<Quote_Product_MRF__c>queriedQPMRF = [Select Id FROM Quote_Product_MRF__c WHERE Order__c = :testOrder.id];
/* --- Checks for 0 records --- */
system.assertEquals(0, queriedQPMRF.size());
/* --- Delete Quote Product OTF Test --- */
/* --- Create Quote Product OTF--- */
Quote_Product__c testQPOTF = new Quote_Product__c ();
testQPOTF.Order__c = testOrder.id;
insert testQPOTF;
/* --- Run Delete Method--- */
CreateQuoteProducts_NewOrRenewal.DeleteQuoteProductsOTF(new List<Id>{testOrder.id});
/* --- Query for QP OTF--- */
list<Quote_Product__c>queriedQPOTF = [Select Id FROM Quote_Product__c WHERE Order__c = :testOrder.id];
/* --- Checks for 0 records --- */
system.assertEquals(0, queriedQPOTF.size());
/* --- Create Quote Product MRF Test --- */
/* --- Run Create Method--- */
CreateQuoteProducts_NewOrRenewal.CreateQuoteProductsMRF(new List<Id>{testOrder.id});
/* --- Query for QP OTF--- */
list<Quote_Product_MRF__c>queriedQPMRFCreated = [Select Id FROM Quote_Product_MRF__c WHERE Order__c = :testOrder.id];
/* --- Checks for 1 record --- */
system.assertEquals(1, queriedQPMRFCreated.size());
/* --- Create Quote Product OTF Test --- */
/* --- Run Create Method--- */
CreateQuoteProducts_NewOrRenewal.CreateQuoteProductsOTF(new List<Id>{testOrder.id});
/* --- Query for QP OTF--- */
list<Quote_Product__c>queriedQPOTFCreated = [Select Id FROM Quote_Product__c WHERE Order__c = :testOrder.id];
/* --- Checks for 1 record --- */
system.assertEquals(1, queriedQPOTFCreated.size());
Test.stopTest();
}
}
如上所述,如果我 运行 可执行文件 window 中的以下顶点并将 ID 替换为实际订单 ID,它会成功创建记录,只是当我 运行 完整的 class 来自 flow.
List<AggregateResult> nrqpmrfOP = [
SELECT
count(Id) ct,
Order__c ord,
sum(Total_Monthly_Recurring_Fees__c) stmr,
sum(Monthly_Recurring_Fees__c) mr,
sum(Discount_MRF__c) dmr
FROM Order_Location_Package__c
WHERE Order__c in : OrderId AND Package__r.Monthly_Recurring_Price__c != null
GROUP BY Package__c, Order__c];
List<Quote_Product_MRF__c> nrqpmrf = New List<Quote_Product_MRF__c>();
for(AggregateResult ar : nrqpmrfOP){
Quote_Product_MRF__c QuoteProductMRF = New Quote_Product_MRF__c();
QuoteProductMRF.Quantity__c = (Decimal)ar.get('ct');
QuoteProductMRF.Order__c = (String)ar.get('ord');
QuoteProductMRF.Total_Monthly_Recurring_Fees__c = (Decimal)ar.get('stmr');
QuoteProductMRF.Monthly_Recurring_Fees__c = (Decimal)ar.get('mr');
QuoteProductMRF.Discount_MRF__c = (Decimal)ar.get('dmr');
QuoteProductMRF.Product_Type__c = 'Package';
nrqpmrf.add(QuoteProductMRF);
}
Insert nrqpmrf;
如文档中所述(developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…),class 只能有 1 个 InvocableMethod。这意味着您的流程只调用第一个 delete 方法,而不调用其他方法。如果你需要调用每个方法,那么你需要为每个方法做一个class。也许流程的屏幕截图可能会有所帮助。 – 巴瑟利维
我是编写 Apex 的新手,但当我拆分下面创建的 class 时,一切似乎确实 运行 在可执行文件 window 中顺利地分开,但是当我从流程中 运行ning 时,它似乎根本没有创建记录。删除记录的方法似乎有效,但创建记录的方法似乎都无效。
非常感谢任何帮助或指导!
public without sharing class CreateQuoteProducts_NewOrRenewal{
@invocableMethod
public static void DeleteQuoteProductsMRF(List<Id> OrderId){
List<Quote_Product_MRF__c> QuoteProductsMRF = [SELECT id from Quote_Product_MRF__c WHERE Order__c in : OrderId];
if(!QuoteProductsMRF.isEmpty()){
delete QuoteProductsMRF;
}
}
public static void DeleteQuoteProductsOTF(List<Id> OrderId){
List<Quote_Product__c> QuoteProductsOTF = [SELECT id from Quote_Product__c WHERE Order__c in : OrderId];
if(!QuoteProductsOTF.isEmpty()){
delete QuoteProductsOTF;
}
}
/* ---START--- Create Quote Products MRF ---START--- */
public static void CreateQuoteProductsMRF(List<Id> OrderId){
List<AggregateResult> nrqpmrfOP = [
SELECT
count(Id) ct,
Order__c ord,
sum(Total_Monthly_Recurring_Fees__c) stmr,
sum(Monthly_Recurring_Fees__c) mr,
sum(Discount_MRF__c) dmr
FROM Order_Location_Package__c
WHERE Order__c in : OrderId AND Package__r.Monthly_Recurring_Price__c != null
GROUP BY Package__c, Order__c];
List<Quote_Product_MRF__c> nrqpmrf = New List<Quote_Product_MRF__c>();
for(AggregateResult ar : nrqpmrfOP){
Quote_Product_MRF__c QuoteProductMRF = New Quote_Product_MRF__c();
QuoteProductMRF.Quantity__c = (Decimal)ar.get('ct');
QuoteProductMRF.Order__c = (String)ar.get('ord');
QuoteProductMRF.Total_Monthly_Recurring_Fees__c = (Decimal)ar.get('stmr');
QuoteProductMRF.Monthly_Recurring_Fees__c = (Decimal)ar.get('mr');
QuoteProductMRF.Discount_MRF__c = (Decimal)ar.get('dmr');
QuoteProductMRF.Product_Type__c = 'Package';
nrqpmrf.add(QuoteProductMRF);
}
Insert nrqpmrf;
}
/* ---END--- Create Quote Products MRF ---END--- */
/* ---START--- Create Quote Products OTF ---START--- */
public static void CreateQuoteProductsOTF(List<Id> OrderId){
List<AggregateResult> nrqpmrfOP = [
SELECT
count(Id) ct,
Order__c ord,
sum(Total_One_Time_Fees__c) stmr,
sum(One_Time_Fees__c) mr,
sum(Discount_OTF__c) dmr
FROM Order_Location_Package__c
WHERE Order__c in : OrderId AND Package__r.One_Time_Price__c != null
GROUP BY Package__c, Order__c];
List<Quote_Product__c> nrqpotf = New List<Quote_Product__c>();
for(AggregateResult ar : nrqpmrfOP){
Quote_Product__c QuoteProductOTF = New Quote_Product__c();
QuoteProductOTF.Quantity__c = (Decimal)ar.get('ct');
QuoteProductOTF.Order__c = (String)ar.get('ord');
QuoteProductOTF.Total_One_Time_Fees__c = (Decimal)ar.get('stmr');
QuoteProductOTF.One_Time_Fees__c = (Decimal)ar.get('mr');
QuoteProductOTF.Discount_OTF__c = (Decimal)ar.get('dmr');
QuoteProductOTF.Product_Type__c = 'Package';
nrqpotf.add(QuoteProductOTF);
}
Insert nrqpotf;
}
/* ---END--- Create Quote Products ORD ---END--- */
}
测试Class低于
@isTest
private class CreateQuoteProducts_NewOrRenewalTest {
private static testMethod void doTest() {
Account testAcc = new Account ();
testAcc.Name = 'Test Account';
testAcc.Primary_Vertical__c = 'Multifamily Housing';
testAcc.Total_Locations_Owned_Managed__c = 1;
insert testAcc;
Opportunity testOpp = new Opportunity ();
testOpp.Name = 'Test Opportunity';
testOpp.AccountId = testAcc.Id;
testOpp.Opportunity_Source__c = 'Sales Generated';
testOpp.Type = 'New';
testOpp.StageName = 'Contract';
testOpp.Number_of_locations_for_opportunity__c = 1;
testOpp.Amount = 0;
testOpp.Implementation__c = 0;
testOpp.CloseDate = System.today() + 5;
testOpp.Deal_Confidence__c = 100;
insert testOpp;
Package__c testPackage = new Package__c ();
testPackage.Name = 'Test Package';
testPackage.Package_Type__c = 'Website Package';
testPackage.Status__c = 'Active';
testPackage.One_Time_Price__c = String.ValueOf(200);
testPackage.Monthly_Recurring_Price__c = String.ValueOf(100);
insert testPackage;
Order_Sheet__c testOrder = new Order_Sheet__c ();
testOrder.Opportunity__c = testOpp.id;
insert testOrder;
Order_New_Location__c testOrderLocation = new Order_New_Location__c ();
testOrderLocation.Order_Sheet__c = testOrder.id;
testOrderLocation.Name = 'Test Location';
insert testOrderLocation;
Order_Location_Package__c testOrderPackage = new Order_Location_Package__c ();
testOrderPackage.Order__c = testOrder.Id;
testOrderPackage.New_Location_Name__c = testOrderLocation.Id;
testOrderPackage.Package__c = testPackage.Id;
insert testOrderPackage;
/* --- Delete Quote Product MRF Test --- */
Test.startTest();
/* --- Create Quote Product MRF--- */
Quote_Product_MRF__c testQPMRF = new Quote_Product_MRF__c ();
testQPMRF.Order__c = testOrder.id;
insert testQPMRF;
/* --- Run Delete Method--- */
CreateQuoteProducts_NewOrRenewal.DeleteQuoteProductsMRF(new List<Id>{testOrder.id});
/* --- Query for QP OTF--- */
list<Quote_Product_MRF__c>queriedQPMRF = [Select Id FROM Quote_Product_MRF__c WHERE Order__c = :testOrder.id];
/* --- Checks for 0 records --- */
system.assertEquals(0, queriedQPMRF.size());
/* --- Delete Quote Product OTF Test --- */
/* --- Create Quote Product OTF--- */
Quote_Product__c testQPOTF = new Quote_Product__c ();
testQPOTF.Order__c = testOrder.id;
insert testQPOTF;
/* --- Run Delete Method--- */
CreateQuoteProducts_NewOrRenewal.DeleteQuoteProductsOTF(new List<Id>{testOrder.id});
/* --- Query for QP OTF--- */
list<Quote_Product__c>queriedQPOTF = [Select Id FROM Quote_Product__c WHERE Order__c = :testOrder.id];
/* --- Checks for 0 records --- */
system.assertEquals(0, queriedQPOTF.size());
/* --- Create Quote Product MRF Test --- */
/* --- Run Create Method--- */
CreateQuoteProducts_NewOrRenewal.CreateQuoteProductsMRF(new List<Id>{testOrder.id});
/* --- Query for QP OTF--- */
list<Quote_Product_MRF__c>queriedQPMRFCreated = [Select Id FROM Quote_Product_MRF__c WHERE Order__c = :testOrder.id];
/* --- Checks for 1 record --- */
system.assertEquals(1, queriedQPMRFCreated.size());
/* --- Create Quote Product OTF Test --- */
/* --- Run Create Method--- */
CreateQuoteProducts_NewOrRenewal.CreateQuoteProductsOTF(new List<Id>{testOrder.id});
/* --- Query for QP OTF--- */
list<Quote_Product__c>queriedQPOTFCreated = [Select Id FROM Quote_Product__c WHERE Order__c = :testOrder.id];
/* --- Checks for 1 record --- */
system.assertEquals(1, queriedQPOTFCreated.size());
Test.stopTest();
}
}
如上所述,如果我 运行 可执行文件 window 中的以下顶点并将 ID 替换为实际订单 ID,它会成功创建记录,只是当我 运行 完整的 class 来自 flow.
List<AggregateResult> nrqpmrfOP = [
SELECT
count(Id) ct,
Order__c ord,
sum(Total_Monthly_Recurring_Fees__c) stmr,
sum(Monthly_Recurring_Fees__c) mr,
sum(Discount_MRF__c) dmr
FROM Order_Location_Package__c
WHERE Order__c in : OrderId AND Package__r.Monthly_Recurring_Price__c != null
GROUP BY Package__c, Order__c];
List<Quote_Product_MRF__c> nrqpmrf = New List<Quote_Product_MRF__c>();
for(AggregateResult ar : nrqpmrfOP){
Quote_Product_MRF__c QuoteProductMRF = New Quote_Product_MRF__c();
QuoteProductMRF.Quantity__c = (Decimal)ar.get('ct');
QuoteProductMRF.Order__c = (String)ar.get('ord');
QuoteProductMRF.Total_Monthly_Recurring_Fees__c = (Decimal)ar.get('stmr');
QuoteProductMRF.Monthly_Recurring_Fees__c = (Decimal)ar.get('mr');
QuoteProductMRF.Discount_MRF__c = (Decimal)ar.get('dmr');
QuoteProductMRF.Product_Type__c = 'Package';
nrqpmrf.add(QuoteProductMRF);
}
Insert nrqpmrf;
如文档中所述(developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…),class 只能有 1 个 InvocableMethod。这意味着您的流程只调用第一个 delete 方法,而不调用其他方法。如果你需要调用每个方法,那么你需要为每个方法做一个class。也许流程的屏幕截图可能会有所帮助。 – 巴瑟利维