You need to sign in to do that
Don't have an account?
THARUN SRIRAM 10
I have a formula field in case object "Remaining_amount__C", I want all the values in this field in the case to be summed up and appear on its parent account record field "Pending_Amount__c". Can anyone please help me? Thanks in advance :)
I have a formula field in case object "Remaining_amount__C", I want all the values in this field in the case to be summed up and appear on its parent account record field "Pending_Amount__c". Can anyone please help me? Thanks in advance :)
however there is an idea https://success.salesforce.com/ideaView?id=0873000000079UUAAY , looks like Salesforce is evaluating it.
If you would like to go with apex, below is a simple trigger that i wrote and tested which could accomplish the ask:)
trigger UpdateFieldValues on Case (before update, before insert) {
Decimal remainingAmountcase;
Decimal remainingAmountcaseOld;
Set<Id>pendingAmountAccount=new Set<Id>();
List<Account> acco=new List<Account>();
if(Trigger.isInsert)
{
for (Case c : Trigger.new) {
if (c.Remaining_amount__c!=null)
pendingAmountAccount.add(c.AccountId);
remainingAmountcase = c.Remaining_amount__c;
}
for(Account acc : [Select Id,Pending_Amount__c From Account Where Id IN :pendingAmountAccount])
{
acco.add(acc);
acc.Pending_Amount__c=acc.Pending_Amount__c+remainingAmountcase;
}
}
else if (Trigger.isUpdate)
{
for (Case c : Trigger.old) {
if (c.Remaining_amount__c!=null)
remainingAmountcaseOld = c.Remaining_amount__c;
}
for (Case c : Trigger.new) {
if (c.Remaining_amount__c!=null)
pendingAmountAccount.add(c.AccountId);
remainingAmountcase = c.Remaining_amount__c;
}
for(Account acc : [Select Id,Pending_Amount__c From Account Where Id IN :pendingAmountAccount])
{
acco.add(acc);
acc.Pending_Amount__c=acc.Pending_Amount__c-remainingAmountcaseOld+remainingAmountcase;
}
}
update acco;
}
trigger:
Class:
Hope this helps.
Thanks.