Update records in Accounts from Custom Modules

Business scenario:

Envision a scenario of you running a real estate business. The Accounts module contains records of all the partners associated with your company. For instance, Construction companies. However, you deal two types of real estates that you need a Custom Module for each. Let's say "For Rent" and "For Sale".

The three modules "Accounts", "For Rent" and "For Sale" are interlinked closely. A Construction company can build properties for rent and for sale. Similarly, properties for rent can be built by a lot of different companies. Hence, sync of data between the two makes life easier for all. Have the function executable by setting up a button in the "For Rent" and "For Sale" module records details page.

Through this function, you can update the records in Accounts module with information from records in a custom module. For example: A construction company "XYZ Builders" has 2 properties for rent and 2 for sale. The properties that are for rent and sale are sold 1 each. This particular information would be updated in the custom modules, but shouldn't it also be updated in the Accounts module? After all, it adds to the precision and effectiveness of running your business.


Getting started with the function:

  1. Go to Setup > Customization > Modules and Fields > Select the required module > Links and Buttons > + New Button.
  2. Provide a name for the button. Add a description(optional).
  3. Choose View Page from the drop-down list.
  4. Select Writing Function from the subsequent drop-down.
  5. Provide a name for the function. Add a description(optional).
  6. Copy the code given below.
  7. Click Edit Arguments.
  8. Enter the name as acctId and select the value as Account Id.
  9. Save the changes.
  10. Select the profiles who can see this button.
  11. Click Save.

The Code:

The following code is to roll up the rent amount for a particular apartment (record in 'For Rent' module).

resp = zoho.crm.getRelatedRecords("Rented", "Accounts", input.acctId);
//info resp;
totalsb = 0.0 ;
totalpn = 0.0;
count = 1 ;
firstcount = 1;
pnvalue = 0.0;
sbvalue = 0.0;
datelist = List();
for each order in resp
totalsb = totalsb + ifnull(order.get("SB"),"0.0").toDecimal();
totalpn = totalpn + ifnull(order.get("PN"),"0.0").toDecimal();
if( firstcount == 1)
if( resp.size() == firstcount)
if( count != 1)
sbvalue = sbvalue + ifnull(order.get("SB"),"0.0").toDecimal();
pnvalue = pnvalue + ifnull(order.get("PN"),"0.0").toDecimal();
count = count + 1;
firstcount = firstcount + 1 ;
diff = (days360(datelist.get(1),datelist.get(0))/7).toLong();
lastsn = sbvalue / diff ;
lastpn = pnvalue / diff ;
update = zoho.crm.update("Accounts", acctId, mp);
info mp;
info update;
return "Success";



  • The above code works only for API V2.0 and not the previous version.

Found this useful? Try it out and let us know how it works! If you have questions, do not hesitate to ask! Share this with your team if you find it useful!

Return to Tips