零 Apex 经验,我只是遵循此文档: https://help.salesforce.com/s/articleView?id=sf.cpq_enable_aa.htm&type=5
它指出您可以对其他对象设置高级批准,问题是我选择了一个与报价(报价行)具有主从关系的对象。在第 19 行(其中 testRecall 中有一个“插入引号”)我添加了一个引号,但我需要在此之前为引号添加值,或者至少这是 SF 支持人员告诉我的。
有人知道怎么做吗?
@isTest
private class QuoteLineExtControllerTests {
testMethod static void testSubmit() {
SBQQ__QuoteLine__c quoteLine = new SBQQ__QuoteLine__c();
insert quoteLine;
Test.startTest();
QuoteLineExtController con = new QuoteLineExtController(new ApexPages.StandardController(quoteLine));
con.onSubmit();
quoteLine = [SELECT ApprovalStatus__c FROM SBQQ__QuoteLine__c WHERE Id = :quoteLine.Id LIMIT 1];
Test.stopTest();
System.assertEquals('Approved', quoteLine.ApprovalStatus__c);
}
testMethod static void testRecall() {
SBQQ__QuoteLine__c quoteLine = new SBQQ__QuoteLine__c();
insert quoteLine;
Test.startTest();
QuoteLineExtController con = new QuoteLineExtController(new ApexPages.StandardController(quoteLine));
con.onRecall();
quoteLine = [SELECT ApprovalStatus__c FROM SBQQ__QuoteLine__c WHERE Id = :quoteLine.Id LIMIT 1];
Test.stopTest();
System.assertEquals('Recalled', quoteLine.ApprovalStatus__c);
}
}
相关课程
public with sharing class QuoteLineExtController {
private Id quoteLineId;
public QuoteLineExtController(ApexPages.StandardController stdController) {
quoteLineId = stdController.getId();
}
public PageReference onSubmit() {
if (quoteLineId != null) {
SBAA.ApprovalAPI.submit(quoteLineId, SBAA__Approval__c.Quote_Line__c);
}
return new PageReference('/' + quoteLineId);
}
public PageReference onRecall() {
if (quoteLineId != null) {
SBAA.ApprovalAPI.recall(quoteLineId, SBAA__Approval__c.Quote_Line__c);
}
return new PageReference('/' + quoteLineId);
}
}
尝试遵循本文档: https://help.salesforce.com/s/articleView?id=sf.cpq_enable_aa.htm&type=5
用我的组织自定义对象 SBQQ_QuoteLine_c 替换了 Quote
要修复该测试,请创建一个
Quote
记录作为父记录,并在 QuoteLine
上设置必填字段。这是更新后的代码:
@isTest
private class QuoteLineExtControllerTests {
testMethod static void testSubmit() {
SBQQ__Quote__c quote = new SBQQ__Quote__c(Name = 'Test Quote');
insert quote;
SBQQ__QuoteLine__c quoteLine = new SBQQ__QuoteLine__c(
SBQQ__Quote__c = quote.Id,
Name = 'Test Quote Line' // Add other required fields here
);
insert quoteLine;
Test.startTest();
QuoteLineExtController con = new QuoteLineExtController(new ApexPages.StandardController(quoteLine));
con.onSubmit();
quoteLine = [SELECT ApprovalStatus__c FROM SBQQ__QuoteLine__c WHERE Id = :quoteLine.Id LIMIT 1];
Test.stopTest();
System.assertEquals('Approved', quoteLine.ApprovalStatus__c);
}
testMethod static void testRecall() {
SBQQ__Quote__c quote = new SBQQ__Quote__c(Name = 'Test Quote');
insert quote;
SBQQ__QuoteLine__c quoteLine = new SBQQ__QuoteLine__c(
SBQQ__Quote__c = quote.Id,
Name = 'Test Quote Line' // Add other required fields here
);
insert quoteLine;
Test.startTest();
QuoteLineExtController con = new QuoteLineExtController(new ApexPages.StandardController(quoteLine));
con.onRecall();
quoteLine = [SELECT ApprovalStatus__c FROM SBQQ__QuoteLine__c WHERE Id = :quoteLine.Id LIMIT 1];
Test.stopTest();
System.assertEquals('Recalled', quoteLine.ApprovalStatus__c);
}
}