我正在尝试自学 Salesforce 并希望将自定义字段添加到客户。
为了实现这一点,我做了以下事情:
我已将 Total 自定义字段添加到 Account:
这是触发器:
trigger AccountTotalTrigger on Account (before insert) {
List<String> accountNames = new List<String>{};
//Loop through all records in the Trigger.new collection
for(Account a: Trigger.new){
//Concatenate the Name and billingState into the Description field
a.Description = a.Name + ':' + a.BillingState;
}
}
和伴随的测试:
@IsTest
private with sharing class AccountsTest {
@IsTest
static void testAccountTriggerViaDML()
{
// This example is simple, illustrates how to invoke the trigger code via DML (required),
// but can become complex and detract from TDD and more granularly testing of the Accounts class
Account testAccount = new Account( Name = 'Test Account' , Total = 100 );
insert testAccount;
testAccount = [select Id, Name from Account where Id = :testAccount.Id];
System.assertEquals(testAccount.Name, 'Test Account');
}
}
但是“问题”选项卡上有一个问题:
我没有正确设置帐户字段吗?
测试不应该失败吗?它似乎通过了: