【发布时间】:2015-02-09 02:46:27
【问题描述】:
我对 Apex 还很陌生.. 进入了一天,对我的幼稚感到抱歉。我要做的是返回我的帐户列表,然后查看帐户的合同日期(Contract_Expiration__c)。根据该日期,它应该更新客户字段( update_active_status_text__c) 为 null、Active 或 Void。
我没有收到任何错误,但我没有收到任何代码覆盖率。任何帮助都会大有帮助。
提前致谢
Apex 类
public class update_active_status {
public static VOID update_active_statustest(){
list<Account> myaccount = [SELECT Id, Contract_Expiration__c, update_active_status_text__c FROM Account WHERE CMS_Customer_Type__c = 'Enterprise' or CMS_Customer_Type__c = 'cloud'];
for(Account a: myaccount){
if (a.Contract_Expiration__c == null ){
a.update_active_status_text__c = null;
update a;
} else if (a.Contract_Expiration__c >= Date.today().addDays(-60)) {
a.update_active_status_text__c = 'Active';
update a;
} else if (a.Contract_Expiration__c < Date.today().addDays(-60)) {
a.update_active_status_text__c = 'Void';
update a;
} else {
a.update_active_status_text__c = 'Void';
update a;
}
}
}
}
测试类
@isTest
public class testupdate_active_status {
static testMethod void myupdate_active_statusTest() {
Account acc = new Account(Name = 'Test Account');
insert(acc);
Date d = Date.today();
acc.Contract_Expiration__c = d;
update(acc);
acc.update_active_status_text__c = 'Active';
update(acc);
acc = [Select update_active_status_text__c From Account Where Id = : acc.Id];
System.assertEquals('Active', acc.update_active_status_text__c);
}
static testMethod void setToNull() {
Account acc = new Account(Name = 'Test Account');
insert(acc);
Date d = Date.today();
acc.Contract_Expiration__c = d;
update(acc);
acc.Contract_Expiration__c = null;
update(acc);
acc = [Select update_active_status_text__c From Account Where Id = : acc.Id];
System.assertEquals(null, acc.update_active_status_text__c);
}
static testMethod void createWithDate() {
Date d = Date.today().addDays(-70);
Account acc = new Account(Name = 'Test Account', Contract_Expiration__c = d);
insert(acc);
acc.update_active_status_text__c = 'Void';
update(acc);
acc = [Select update_active_status_text__c From Account Where Id = : acc.Id];
System.assertEquals('Void', acc.update_active_status_text__c);
}
}
【问题讨论】:
标签: salesforce apex