All Zoho CRM entities are modelled as classes having members and methods applicable to that particular entity.
- ZCRMRestClient is the base class of the SDK.
- This class has, methods to get instances of various other Zoho CRM entities.
- The class relations and hierarchy of the SDK follows the entity hierarchy inside Zoho CRM.
- Each
class entity has functions to fetch its own properties and to fetch
data of its immediate child entities through an API call.
- For example, a Zoho CRM module (ZCRMModule) object will have member functions to get a module’s properties like display name, module Id, etc, and will also have functions to fetch all its child objects (like ZCRMLayout).
The class hierarchy of various Zoho CRM entities is depicted as:
Instance Objects
It
is not always effective to follow the complete class hierarchy from the
top to fetch the data of an entity at some lower level, since this
would involve API calls at every level. In order to handle this, every
entity class will have a getInstance() method to get its own dummy object and methods to get dummy objects of its child entities.
Note
- getInstance()
methods would not have any of its properties filled since it would not
fire an API call. This would just return a dummy object that shall be
only used to access the non-static methods of the class.
Summing it up,
- ZCRMRestClient.getModule("Contacts") would return the actual Contacts module, that has all the properties of the Contacts module filled through an API call.
- ZCRMRestClient.getModuleInstance("Contacts")
would return a dummy ZCRMModule object that would refer to the
Contacts module, with no properties filled, since this doesn’t make an
API call.
Hence, to get records from a module, there's no need to start from ZCRMRestClient. Instead, you could get a ZCRMModule instance with ZCRMModule.getInstance() and then invoke its non-static getRecords()
method from the created instance. This would avoid the API call that
would otherwise have been triggered to populate the ZCRMModule object.
Accessing record properties
Since record properties are dynamic across modules, we have only given the common fields like createdTime, createdBy, owner etc, as ZCRMRecord’s default members. All other record properties are available as a map in ZCRMRecord object.
To access the individual field values of a record, use the getter and setter methods available. These methods only support API names.
- To get a field value, use record.getFieldValue(field_api_name);
- To set a field value, use record.setFieldValue(field_api_name, new_value);
API Names
The keys of the record properties map are the API names of the module’s fields. They are available in your CRM,
Setup → Developer Space → APIs → CRM API → API Names.