【发布时间】:2019-02-19 17:20:04
【问题描述】:
尝试在使用 APEX 触发器更新产品(如果可能也插入)时将产品的 Cost_Price__c 字段复制到自定义对象中。
我已经很接近了,但我现在遇到的错误是:Illegal assignment from PricebookEntry to String
trigger updateAccount on Account (after update) {
for (Account oAccount : trigger.new) {
//create variable to store product ID
string productId = oAccount.Product__c;
//SQL statement to lookup price of product using productID
PricebookEntry sqlResult = [SELECT Cost_Price__c
FROM PricebookEntry
WHERE Product2Id =: productId];
//save the returned SQL result inside the field of Industry - Illegal assignment from PricebookEntry to String
oAccount.Industry = sqlResult;
}
}
我是否认为这是因为它从 SOQL 调用返回了一组集体结果?我试过使用 sqlResult[0] 似乎仍然不起作用。
【问题讨论】:
标签: triggers salesforce apex soql