2

我有以下要求:

1) 获取其个人资料已更改的所有用户的列表。

2)然后查询FRUP(它是一个自定义对象)以检索与更改个人资料的用户关联的所有记录。(FRUP对象将包含所有用户在所有对象上创建的所有记录的列表说帐户,机会)

3) 更新 FRUP。

为了实现这一点,我编写了一个触发器,通过它我可以获取其个人资料已更改的所有用户的列表,如下所示:

Trigger UserProfileTrigger on User (before update) {

List<User> usr = new List<User>();
Map<String,String> userMap = new Map<String,String>();

   for(User u: Trigger.new){

   //Create an old and new map so that we can compare values
        User oldOpp = Trigger.oldMap.get(u.ID);    
        User newOpp = Trigger.newMap.get(u.ID);

   //Retrieve the old and new profile            
        string oldProfileId = oldOpp.profileId;
        string newProfileId  = newOpp.profileId;

   //If the fields are different, the profile has changed
       if(oldProfileId != newProfileId){
          System.debug('Old:'+oldProfileId);
          System.debug('New :'+newProfileId);
          usr.add(u);
          System.debug('User :'+usr);

       }
   }

}

以下是自定义对象 FRUP 上的字段:1)所有者 2)名称
3)记录 ID
4)文件夹 ID
5)创建者
6)最后修改者

任何帮助/建议?

4

1 回答 1

0

我不确定 FRUP 上的哪个字段引用了与它相关的用户 ID,但您可以使用以下内容遍历 FRUP 对象:

List<FRUP> frupToUpdate = new List<FRUP>();
for (FRUP f : [
    Select
        OwnerId,
        Name, //etc.
        UserId //the field that references the user Id
    from FRUP
    where userId = : usr]) {
//update field on FRUP, e.g. f.Name = 'New Name';
frupToUpdate.add(f);
}

这将选择与具有更改配置文件的用户相关的 FRUP 记录。然后它更新记录上的一个字段并将记录添加到列表中以进行更新。请注意,这应该在您的循环之后for(User u: Trigger.new)。然后更新已更改的 FRUP 记录: update frupToUpdate;

于 2013-11-28T15:50:58.577 回答