运行 查询 table 并返回私钥中的值
Running a query on a lookup table and returning the value in the private key
我有一个触发器,每次订单从草稿变为有效时都会触发,反之亦然。我的触发器中有一个条件 运行s 查询并将输出保存到 Map 中。当我在地图上进行系统调试时,返回的值似乎是外键。
trigger OrderActive on Order (after insert, after update){
for(Order ord : Trigger.New)
{
If(ord.Status == 'Activated')
{
Map<String, Order> m = new Map<String, Order>(
[select Account.Name from Order WHERE Id IN :Trigger.new]);
System.debug(m);
}
}
}
我不断得到上图中的输出
USER_DEBUG [12]|DEBUG|{8018A0000002fJYQAY=订单:{AccountId=0018A00000KvRm8QAF,Id=8018A0000002fJYQAY}}
当我 运行 在查询编辑器中执行相同的查询时,我得到的是帐户的实际名称,而不是 0019A00000KvRm9QBF。如何在我的触发器中获取我的查询以抽出名称而不是外键?触发器中的查询会影响其查询的输出吗?
如您所述,在 Map 构造函数中传递查询将只使用 Id 作为映射键:
Map<String, Account> accountMap = new Map<String, Account>([Select Name From Account Limit 1]);
System.debug(accountMap.keySet());
会产生这个:
15:48:48:011 USER_DEBUG [2]|DEBUG|{0012300000QaI0tAAF}
您将不得不使用自定义值作为键手动填充地图:
if(ord.Status == 'Activated') {
Map<String, Order> m = new Map<String, Order>();
for(Order o : [select Account.Name from Order WHERE Id IN :Trigger.new]) {
m.put(o.Account.Name, o);
}
System.debug(m);
}
例如:
Map<String, Account> accountMap = new Map<String, Account>();
for(Account a : [Select Name From Account Limit 1]) {
accountMap.put(a.Name, a);
}
System.debug(accountMap);
将产生:
15:53:56:034 USER_DEBUG [7]|DEBUG|{A-12910879=Account:{Name=A-12910879, Id=0012300000QaI0tAAF, RecordTypeId=012G0000000zoT7IAI, CurrencyIsoCode=USD}}
请注意地图中的 "key" 现在是预期的帐户名称。
我有一个触发器,每次订单从草稿变为有效时都会触发,反之亦然。我的触发器中有一个条件 运行s 查询并将输出保存到 Map 中。当我在地图上进行系统调试时,返回的值似乎是外键。
trigger OrderActive on Order (after insert, after update){
for(Order ord : Trigger.New)
{
If(ord.Status == 'Activated')
{
Map<String, Order> m = new Map<String, Order>(
[select Account.Name from Order WHERE Id IN :Trigger.new]);
System.debug(m);
}
}
}
我不断得到上图中的输出
USER_DEBUG [12]|DEBUG|{8018A0000002fJYQAY=订单:{AccountId=0018A00000KvRm8QAF,Id=8018A0000002fJYQAY}}
当我 运行 在查询编辑器中执行相同的查询时,我得到的是帐户的实际名称,而不是 0019A00000KvRm9QBF。如何在我的触发器中获取我的查询以抽出名称而不是外键?触发器中的查询会影响其查询的输出吗?
如您所述,在 Map 构造函数中传递查询将只使用 Id 作为映射键:
Map<String, Account> accountMap = new Map<String, Account>([Select Name From Account Limit 1]);
System.debug(accountMap.keySet());
会产生这个:
15:48:48:011 USER_DEBUG [2]|DEBUG|{0012300000QaI0tAAF}
您将不得不使用自定义值作为键手动填充地图:
if(ord.Status == 'Activated') {
Map<String, Order> m = new Map<String, Order>();
for(Order o : [select Account.Name from Order WHERE Id IN :Trigger.new]) {
m.put(o.Account.Name, o);
}
System.debug(m);
}
例如:
Map<String, Account> accountMap = new Map<String, Account>();
for(Account a : [Select Name From Account Limit 1]) {
accountMap.put(a.Name, a);
}
System.debug(accountMap);
将产生:
15:53:56:034 USER_DEBUG [7]|DEBUG|{A-12910879=Account:{Name=A-12910879, Id=0012300000QaI0tAAF, RecordTypeId=012G0000000zoT7IAI, CurrencyIsoCode=USD}}
请注意地图中的 "key" 现在是预期的帐户名称。