简体   繁体   English

如何批量更新 Salesforce 中的帐户?

[英]How can i bulk update Accounts in Salesforce?

I am trying to update the Description for over 200 Account entities by matching on Salesforce Id.我正在尝试通过匹配 Salesforce Id 来更新 200 多个帐户实体的描述。 I am using the following trigger,我正在使用以下触发器,

 Trigger MyNew_tr_U on Account (after update) {
 set<ID> ids = Trigger.newMap.keyset(); 
 for(ID id : ids) 
 {
   newChangeTable__c ch = new newChangeTable__c();
   ch.Status__c = 'update'; 
   ch.Url__c = id; 
   ch.Process__c = false; 
   insert ch;
 }

} }

but when i do the data Import of the csv file i get the following error:但是当我对 csv 文件进行数据导入时,出现以下错误:

  CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY:MyNew_tr_U: execution of AfterUpdate
  caused by: System.DmlException: Insert failed. First exception on row 0; first error: 
  STORAGE_LIMIT_EXCEEDED, storage limit exceeded: []

How can i get the trigger to work?我怎样才能让触发器工作?

Further to @eyescream answer below.进一步到下面的@eyescream 答案。 What if I have no filter as in Name, that gives the same error.如果我没有 Name 中的过滤器怎么办,那会产生相同的错误。

Trigger MyNew_tr_U on Account (after update) { List<newChangeTable__c> toInsert = new List<newChangeTable__c>();在帐户上触发 MyNew_tr_U(更新后){ List<newChangeTable__c> toInsert = new List<newChangeTable__c>();

for(Account a : trigger.new){
    Account old = trigger.oldMap.get(a.Id);
    toInsert.add(new newChangeTable__c(
            Status__c = 'update',
            Url__c = a.Id,
            Process__c = false
        ));        
}
insert toInsert;

} }

You're running out of database space.您的数据库空间不足。 Go to Setup -> Storage Usage and have a look. Go 到 Setup -> Storage Usage 看看。 Maybe you can delete something, maybe (if it's production) you can buy more storage from SF (there are "data packs" 10 GB each or you get some more storage with every user license you buy).也许你可以删除一些东西,也许(如果它是生产)你可以从 SF 购买更多的存储空间(有每个 10 GB 的“数据包”,或者你购买的每个用户许可证都会获得更多的存储空间)。 That works only in productions, sandboxes have fixed size though so your only way is to delete some old stuff.这只适用于制作,沙箱有固定的大小,所以你唯一的方法是删除一些旧的东西。

As for the trigger itself...至于触发器本身......

  • you'll want to bulkify it, move the insert statement out of the loop你会想要扩大它,将插入语句移出循环
  • you'll probably want to run it only if some key fields actually changed, not on every edit that doesn't change anything?您可能只想在某些关键字段实际更改时才运行它,而不是在每次没有更改任何内容的编辑时运行它?
  • this can blow your storage space very quickly, consider using standard field history tracking table (optionally with FAT , paid extra) or maybe store the data in "Big Objects" rather than just normal custom object这会很快耗尽你的存储空间,考虑使用标准字段历史记录跟踪表(可选FAT ,额外付费)或者可能将数据存储在“大对象”中,而不仅仅是普通的自定义 object

Something like this, it inserts your thing only if Name changed.像这样,只有当名称改变时它才会插入你的东西。

Trigger MyNew_tr_U on Account (after update) {
    List<newChangeTable__c> toInsert = new List<newChangeTable__c>();

    for(Account a : trigger.new){
        Account old = trigger.oldMap.get(a.Id);
        if(a.Name != old.Name){
            toInsert.add(new newChangeTable__c(
                Status__c = 'update',
                Url__c = a.Id,
                Process__c = false
            ));
        }
    }
    insert toInsert;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM