下面这个是同时更新和插入数据,主要的是upsert这条语句
Account[] acctsList = [SELECT Id, Name, BillingCity
FROM Account WHERE BillingCity = ‘Bombay’];
for (Account a : acctsList) {
a.BillingCity = ‘Mumbai’;
}
Account newAcct = new Account(Name = ‘Acmefasdfas’, BillingCity = ‘San Francisco’);
acctsList.add(newAcct);
try {
upsert acctsList;
} catch (DmlException e) {
// Process exception here
}
Upserting Records(插入和更新数据)
最新推荐文章于 2023-04-21 16:53:02 发布