- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我编写了一个 Apex Scheduler,可以在员工生日前 2 天向经理发送电子邮件通知。
我已经在沙箱中对其进行了测试,我已准备好投入生产。但是,我无法通过我的测试方法获得代码覆盖率。
我的 Apex 调度程序类使用 SOQL 语句来识别帐户名称为“我们的公司”并且在 2 天内过生日的联系人。
我已经在我的测试方法中创建了一个帐户和联系人记录。
我需要将我的帐户和联系人记录链接/关联在一起。 (contact是我创建的account的,我知道跟ID有关系,accountId不能写。
我想我需要创建一个帐户变量并将其分配给 contactID...我已经尝试过代码示例,但它们不起作用。 Salesforce 认为我正在尝试写入您无法执行的联系人 ID。具体来说:
Contact testContact = new Contact();
testContact.firstName='Jack';
testContact.lastName='Dell';
AccountID = testAccount.id;
如何创建帐户变量?
另一个问题是调用我的 sendBirthdayEmail();
方法。
编写 testContact.sendBirthdayEmail();不调用我的电子邮件方法。相反,我收到一条错误消息“错误:编译错误:SObject 联系人的无效字段 ContactID”。
为什么我的测试方法不能识别我的 sendBirthdayEmail 方法?测试方法是否不理解我类(class)中的其他方法?
global class BirthdayName implements Schedulable{
global void execute (SchedulableContext ctx)
{
sendBirthdayEmail();
}
public void sendBirthdayEmail()
{
for(Contact con : [SELECT name, Id, Birthdate FROM Contact WHERE Next_Birthday__c = : system.Today().addDays(2) AND Account.Name = 'Our Company'])
{
String conId = con.Id;
String conName = con.name;
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTargetObjectId('005J0000000JWYx');
mail.setsubject('Birthday Reminder');
mail.setHtmlBody('This is a scheduler-generated email to notify you that the birthday of Name: <b> ' + con.name + ' </b> is in two days. Birthdate of: ' + con.Birthdate + '. Please wish them a happy Birthday.');
mail.setSaveAsActivity(false);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail });
}
}
static testMethod void myTestBirthday() {
//create the required test data needed for the test scenario
//In this case, I need to create a new contact, with the account name of Our Company and has a birthday 2 days away
Account testAccount = new Account(name='Our Company');
insert testAccount;
// creating new contact
Contact testContact = new Contact();
testContact.firstName='Jack';
testContact.lastName='Dell';
// TRYING to make this contact associated with the account by setting the account id of the account I just created to the contact
AccountID = testAccount.id;
// inserting test contact
insert testContact;
testContact.birthdate=system.Today().addDays(2);
update testContact;
testContact.sendBirthdayEmail();
}
}
请帮助我,我已经阅读了文档并搜索了留言板,但我仍然卡住了。感谢您的帮助!
最佳答案
尝试将 testAccount.Id 分配给 testContact.Account:
testContact.account = testAccount.Id;
代替 AccountID = testAccount.Id;
希望这对您有所帮助!
阿努普
关于java - Salesforce:调用方法并将联系人与 apex 测试方法的帐户相关联?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11764979/
我从下面的代码行收到错误“错误错误:AddIMRConroller 编译错误:字段表达式的初始术语必须是具体的 SObject:第 21 行第 23 列的列表”。 string[] str1 = im
Salesforce 支持不同的沙箱。 例如“部分”或“开发”沙箱。 有没有办法检测我的脚本连接到哪种沙箱? 我使用 Python 和 simple_salesforce。 最佳答案 我的 Pytho
下面一行在 salesforce 中给出了“FIELD_INTEGRITY_EXCEPTION”。请为此提供替代方案。 imr.Assigned_DTM__c = DateTime.valueOfGm
下面一行在 salesforce 中给出了“FIELD_INTEGRITY_EXCEPTION”。请为此提供替代方案。 imr.Assigned_DTM__c = DateTime.valueOfGm
我正在尝试实现批处理。我需要一些关于如何测试的帮助/指导。我在这里所做的只是在调试日志中显示机会名称。但是当我在 Apex 测试执行中运行 scheduleBatchable 类时,它也有测试类。未显
我在 salesforce 中创建了一个包,它将使用用户的电子邮件 ID 发出 http 标注请求以获取该电子邮件的数据并将数据添加到某个自定义对象。但是当我尝试使用 UserInfo.getUser
我正在尝试将 Salesforce 数据加载到 Python 数据框中,以便我们可以在那里进行所有操作。 simple_salesforce 处理了我们达到 2,000 限制的警告: from sim
我在 Salesforce 托管包中编写了一个 Apex 类,它使用 apex-lang 的托管版本。库包: global class MySorter implements al.Objectcom
我已经开始使用现有的应用程序,并且代码的唯一副本在 SalesForce 中。我如何备份(导出)它,以便在我弄得一团糟时可以回滚到这个原始代码? 最佳答案 有几个选项可以备份或添加版本控制到您的 Sa
Salesforce 向我抛出了一条新的错误消息,到目前为止我还没有在文档中找到任何有用的信息。我试图在 Controller 扩展中保存一个对象,它实际上保存了记录,但它没有返回到我指示的页面,而是
我需要防止输入重复名称。需要使用触发器来施加此限制。我想知道如何限制 DML 操作的发生。不确定 .addError 在批量代码中的用法。 Set Seta= new Set(); for(oj_
我正在尝试通过创建一个触发器来解决基于“邮箱已满”的邮件退回问题,该触发器在邮件包含“邮箱已满”时重新发送邮件。 我面临的问题是我需要将重新发送的次数限制为 3 次。 一旦收到退回的电子邮件,我现在就
salesforce.com 中单个自定义对象中的最大记录数是多少? https://login.salesforce.com/help/doc/en/limits.htm 中似乎没有指出限制 当然,
是否可以为具有配置文件的用户使用共享规则。如果用户有配置文件,它们有什么用吗?或者配置文件是否完全覆盖了记录访问权限,这样我就可以忘记共享规则? 我的情况是我的所有用户都有个人资料。我想做的是将某些记
自从我不得不进行 S2S 集成以来,已经发布了几个版本,但我遇到了一个意想不到的问题,希望有人能更有效地解决这个问题。 我有两个组织,通过 S2S 共享联系人。 每个组织中的联系人都具有相同的架构,即
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 去年关闭。 社区在 3 个月前审查了是否重新
我正在查看SOQL文档,但找不到查询来获取实体的所有字段数据,例如Account,例如 select * from Account [ SQL syntax ] SOQL中是否有类似上面的语法来提取a
我正在尝试通过允许指定无效电子邮件地址的其他服务将电子邮件地址存储在 Salesforce.com 中。如果这些错误的无效电子邮件地址之一通过其 Web 服务 API 发送到 Salesforce.c
我想获取安装在 salesforce 组织中的所有包的命名空间前缀。我该怎么做? 最佳答案 一种相当简单的方法是查询 ApexClass 对象并获取不同的 NamespacePrefix 值。 Sel
你好, 好吧,我很困惑。我的任务是更新一个 PHP 脚本,该脚本使用 BulkAPI 将一些数据 upsert 到 Opportunity 实体中。 这一切都很顺利,只是 Bulk API 为一些明确
我是一名优秀的程序员,十分优秀!