salesforce - 未找到自定义字段
问题描述
我正在尝试自学 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');
}
}
但是“问题”选项卡上有一个问题:
我没有正确设置帐户字段吗?
测试不应该失败吗?它似乎通过了:
解决方案
字段(数据库列)的 API 名称是Total__c
. “总计”只是可见的标签。您的 Salesforce 可能有讲法语/德语/西班牙语的人,他们希望看到它被翻译,但代码应该仍然可以正常运行。
您对 SF 数据库执行的大多数自定义操作都以这个后缀结尾。自定义表格(“对象”)Application__c
,例如自定义字段,如您的Total__c
. 地理定位字段、大对象、外部数据有更多后缀……但这是另一天的战斗;)
推荐阅读
- python - Python - 如何改进编织功能并将功能添加到类
- javascript - 无法访问 Firebase 集合中的特定字段
- linux - 使用 sed 更改 crontab 行的标准输出
- jsp - Wildfly 12 上的会话属性丢失
- java - 让骆驼使用 Map 构建端点 uri
- javascript - 如何使用 React for Switch Buttons 从 React-Bootstrap 在地图中设置 onchange?
- bash - 如何让 cronjob 在重新启动时删除 RHEL 服务器上的一些 pid 文件?
- kubernetes - ArgoCD 漂移检测
- kubernetes - 用脚本 Kubernetes 中的新值替换现有值
- solr - 是否可以在 SOLRJ / SOLR 的过滤器查询中使用多个单词?