You need to sign in to do that
Don't have an account?
Ruby Kandah
Using Flow or Apex Trigger to Update Account Field from Case Field
Hey Everyone!
I want fields (picklist and text fields) in my Case Object to be linked to similar fields in the Account Object. I am trying to use Flow Designer + Process Builder to accomplish this, but I can't seem to get it to trigger. Can anyone help me out with this?
Thanks!
I want fields (picklist and text fields) in my Case Object to be linked to similar fields in the Account Object. I am trying to use Flow Designer + Process Builder to accomplish this, but I can't seem to get it to trigger. Can anyone help me out with this?
Thanks!
trigger UpdateField on Case (before insert,before update)
{
List<Case> cons = new List<Case>();
System.debug('trigger.newMap.keySet()'+trigger.newMap.keySet());
Set<Id> accountIdSet = new Set<Id>();
for(Case c : Trigger.New)
accountIdSet.add(c.AccountId);
//List<Account> acc = [Select id,DescriptionNew__c,City__c from Account];
Map<id,Account> idToAccountMap = new Map<id,Account>([Select id,DescriptionNew__c,City__c from Account
where id in : accountIdSet]);
System.debug('idToAccountMap'+idToAccountMap);
//Case cons = new Case();
For(Case c: trigger.new)
{
c.DescriptionNew__c = idToAccountMap.get(c.AccountID).DescriptionNew__c;
c.City__c = idToAccountMap.get(c.AccountID).City__c;
}
//update cons;
}
Instead of DescriptionNew__c,City__c you can put your own fields.If this helps then please let me know.
Regards,
Sailee
All Answers
trigger UpdateField on Case (before insert,before update)
{
List<Case> cons = new List<Case>();
System.debug('trigger.newMap.keySet()'+trigger.newMap.keySet());
Set<Id> accountIdSet = new Set<Id>();
for(Case c : Trigger.New)
accountIdSet.add(c.AccountId);
//List<Account> acc = [Select id,DescriptionNew__c,City__c from Account];
Map<id,Account> idToAccountMap = new Map<id,Account>([Select id,DescriptionNew__c,City__c from Account
where id in : accountIdSet]);
System.debug('idToAccountMap'+idToAccountMap);
//Case cons = new Case();
For(Case c: trigger.new)
{
c.DescriptionNew__c = idToAccountMap.get(c.AccountID).DescriptionNew__c;
c.City__c = idToAccountMap.get(c.AccountID).City__c;
}
//update cons;
}
Instead of DescriptionNew__c,City__c you can put your own fields.If this helps then please let me know.
Regards,
Sailee
Thanks so much for your answer! I actually wanted to update fields on the account when a case field was updated, so should I just switch over the case and the account call objects in your code?
Let me know!
Thanks!
Ruby
Yes you can switch it.If it works then let me know.
Regards,
Sailee
Thanks,