0

Suppose I have "SUB_ACCOUNT__c" object and I've created it as a child object of "Account". Now "SUB_ACCOUNT__c" has a field "value__c" which is number in type. I also created a custom field for "Account" which is "totalSubAccountValue__c". Now what I need is, to get the data from "SUB_ACCOUNT__c.value__c" that belongs to a certain Account and add all its data and put the total to the custom field "Account.totalSubAccountValue__c". The same concept applied when I will create or update "SUB_ACCOUNT__c". My question is, What is the best thing to do this? Apex? Can I do it using the process builder or Flow? Are there any other methods?

1 Answer 1

1

If you've created a master-detail relationship from the child object to the account (if not, change the lookup to master-detail), then you could use Roll Up Summary Fields to automatically calculate the value.

Read this part of the documentation for more info.

You could certainly use an Apex Trigger too or other methods, though this will be your quickest, cleanest and best practice method.

5
  • The problem is that I can't change my lookup to master-detail because the related field is not required. There are "SUB_ACCOUNT__c" data that is not related to account.
    – Hope
    Sep 8, 2015 at 3:15
  • Would've been good to state that in the original question :). In that case I suggest you to use a trigger. Have a look at this - salesforce.stackexchange.com/questions/33650/… and bachovski.com/2015/03/roll-up-summary-trigger-for-lookup.html Sep 8, 2015 at 3:19
  • Personally I haven't done it by it looks like you can also use a flow: salesforceweek.ly/2015/02/… Sep 8, 2015 at 3:36
  • Does not seem to make sense why you would have a "Sub Account" without a main account.....May just be a terminology thing...but SUB generally leads one to believe that there should be a main or parent account
    – Eric
    Sep 8, 2015 at 4:04
  • 1
    @Eric actually its not a real name. I just use it as an example.
    – Hope
    Sep 8, 2015 at 6:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .