Getting related records from a custom module in a function

Getting related records from a custom module in a function

Background: I'm trying to put an automatically-calculated field on Account records that totals up all the sales to that account. Sales are kept in a custom module called "Sales Records," because we just get a spreadsheet of orders from our distributor each month, and the Deals/Invoices/Purchase Orders/Products workflow is way more complicated than what we have.

We already have a related list visible on the Accounts records that lists all the individual Sales Records associated with that Account, but I want a "Total Sales" field on the Accounts record -- so I can easily include it in list views of Accounts, for instance.

In order to create that total, I'm trying to create a function that will get all Sales Records associated with an Account, iterate through the records and sum the "Total Sale" fields from all the records, then put that value into a field on the Account.

If there's a better way to calculate an amount by totaling a field in a custom module, please let me know.

But when I try to look up related records based on the custom module ("Sales_Records" is the API name):
  1. sales = zoho.crm.getRelatedRecords("Sales_Records","Accounts",accountId.toLong());
  2. info sales;
I get a response with "INVALID_DATA."

If I try this with a standard Zoho module, like Contacts, I get back an expected response with the appropriate fields.

There's a Zoho CRM Tips post titled "Update records in Accounts from Custom Modules" that describes exactly this method, and the Deluge documentation concurs, so I'm not sure why it's not working.

A few years-old forum posts suggested that it isn't possible to use getRelatedRecords on custom modules -- if that's the case then the documentation I linked to seriously needs to be updated -- and suggested searchRecordsByPDC instead. But trying something like the following ("Total_Sale" is the API name for the field in the custom module):
  1. sales = zoho.crm.searchRecordsByPDC("Sales_Records","Total_Sale",accountId.toLong());
results in the error "Not able to find 'zoho.crm.searchRecordsByPDC'" so...not sure what's up with that. Does that function not actually exist?

I must be missing something really basic. How do I get these related records?