Kaizen 143 Assigning values to different field types using Zoho CRM SDKs

Kaizen 143 Assigning values to different field types using Zoho CRM SDKs


Welcome to another week of our Kaizen series! Today, we will discuss a critical aspect of working with Zoho CRM SDKs across various programming languages: assigning values to fields of different data types. 

Zoho CRM offers a comprehensive suite of SDKs for PHP, Java, Node.js, C#, Python, Ruby, TypeScript, Scala, and JavaScript, streamlining development workflows across various programming languages. Today's discussion will provide you with the knowledge to handle various data types and their assignment across our different SDK languages.  By the end, you will be well-equipped to utilize the sample codes in our GitHub repository and tailor them to your specific CRM needs.

Data Types in Zoho CRM

In Zoho CRM modules, a variety of field types are available, enabling you to collect and manage a broad spectrum of customer data. Here's a quick reference summarizing the common data types:

  • text : Used for short text entries like names, addresses, or short descriptions, the text field is a string type field that can store up to 255 characters, including alphanumeric characters and special characters.
  • textarea (multiline) : Used for longer text entries, the multiline field in Zoho CRM is a string field that supports alphanumeric and special characters up to 32000 characters, making it suitable for storing extensive content such as terms and conditions or detailed descriptions.
  • email : Used to store email addresses, ensuring proper format and validation.
  • phone : Used to store valid phone numbers with up to 30 characters, ensuring proper format and validation.
  • picklist : Lets you choose a value from a set of predefined options, accepting all alphanumeric and special characters
  • multiselectpicklist : Allows you to select multiple valuesfor the field, accepting all alphanumeric and special characters.
  • date :  This field accepts date in yyyy-MM-dd format.
  • datetime : This field accepts both date and time information in yyyy-MM-ddTHH:mm:ss±HH:mm format.
  • integer (number) : This field is a 32-bit signed integer that accepts up to 9 digits.
  • currency : Used for amount fields, this field is stored as a 64 bit signed floating point, and accepts up to 16 digits. Refer here for more details on the available rounding options.
  • double : Used for decimal numbers, useful for number and calculations requiring precision, this field is stored as a 64-bit signed floating-point.
  • percent : Used for percentage values and accepts up to 5 characters, including the sign and decimal point.
  • bigint (long integer) : This field is a 64-bit signed integer, that accepts up to 18 digits.
  • boolean (checkbox) : Used for boolean values, ie, true/false.
  • website (URL) : Accepts valid URLs with alphanumeric characters, up to 450 characters in length.
  • lookup : Used to create a relationship between records. In our APIs, this field will be represented as a JSON Object containing the id and the display label.
  • multiselectlookup : This field allows you to create a many-to-many relationship between two modules in Zoho CRM. When you use a multiselectlookup field, linked records are stored in a separate module with lookup fields that reference the two related modules.
  • userlookup :  Used to establish a lookup to the user module. In our APIs, this field is represented as a JSON Object containing the id and the display label.  The linked records are stored in a separate module, containing lookup fields for the two related modules.
  • ownerlookup : Used to identify and assign the record's ownership to a specific user within the organization.
  • multi_user_lookup : Allows association of multiple users to a module record.
  • subform : A secondary form or table that enables you to add multiple line items to a primary form or record.  A separate module will be automatically created for the subform, with a lookup pointing to the parent module.
  • imageupload : Used to associate images with a record.
  • fileupload : Used to associate files with a record.
  • multi_module_lookup : Used to establish lookup relationships with more than one module.

Leveraging Samples from the Zoho CRM GitHub Repository

To help you get started with the Zoho CRM SDKs, we have provided several sample codes on our GitHub repository. These samples cover various methods available and demonstrate how to access and manage your Zoho CRM data using our SDKs. 
Within the SDK repository, navigate to the Samples directory. Here, you will find a collection of subfolders corresponding to the various Zoho CRM API operations, each containing sample code files that demonstrate how to perform the specific API operation it represents. Consider these files as a launchpad for your development journey. Feel free to adapt them to your specific requirements by making necessary changes. For instance, if your requirement involves creating or updating records, check out the Records subfolder and adjust the code to fit your needs.
In the following sections, we will explain how to assign values to different field types using our SDKs. By combining this information with the sample codes provided in our GitHub repository, you will be able to tailor the solutions to meet your specific requirements.

Assigning Values to Different Field Types using Zoho CRM SDKs

While our GitHub repository provides sample code for various methods, you might need more specific guidance on assigning values to different field data types. In this section, we will discuss how to assign values and handle null values for each field data type across all our supported SDK languages.

1. JAVA SDK

For more details on our JAVA SDK, please refer to our GitHub repository for the latest Java SDK . Check out the sample codes here .

Zoho CRM's Java SDK lets you manage both standard and custom fields within records.

Standard Fields:

Standard fields are pre-defined fields available in Zoho CRM modules. To manage standard fields using our JAVA SDK, you should follow these steps:
a. Import the Module Field Class:
import com.zoho.crm.api.record.Field;

b. Assign Values to Standard Fields:
The syntax for assigning values to standard fields uses the setFieldValue method of the Record object:
record.addFieldValue(Field.{module_api_name}.{FIELD_API_NAME},value);

Replace {module_api_name} and {FIELD_API_NAME} with the appropriate values for your specific use case. Please note that the FIELD_API_NAME should always be uppercase.

Assigning values to Standard Fields:

Field Type

JSON Type
Assign Values
Assign Null Values
text (single line)
string 
record.addFieldValue(Field.Leads.LAST_NAME, "Last Name");
record.addFieldValue(Field.Leads.LAST_NAME, null);
textarea (multiline)
string
record.addFieldValue(Field.Leads.DESCRIPTION, "Last Name");
record.addFieldValue(Field.Leads.DESCRIPTION, null);
email
string
record.addFieldValue(Field.Leads.EMAIL, " abc@zoho.com");
record.addFieldValue(Field.Leads.EMAIL, null);
phone
string
record.addFieldValue(Field.Leads.PHONE, "91(987)654321");
record.addFieldValue(Field.Leads.PHONE, null);
picklist
string
record.addFieldValue(Field.Leads.LEAD_STATUS, new Choice<String>("Not Contacted"));
--
date
string
record.addFieldValue(Field.Products.SALES_START_DATE, LocalDate.of(2024, 6, 13));
record.addFieldValue(Field.Products.SALES_START_DATE, null);
integer (number)
integer
record.addFieldValue(Field.Accounts.EMPLOYEES,100);
record.addFieldValue(Field.Accounts.EMPLOYEES,null);
currency (double)
double
record.addFieldValue(Field.Leads.ANNUAL_REVENUE, 10.00);
record.addFieldValue(Field.Leads.ANNUAL_REVENUE, null);
boolean (checkbox)
boolean
record.addFieldValue(Field.Leads.EMAIL_OPT_OUT, true);
--
website (URL)
string
record.addFieldValue(Field.Leads.WEBSITE, " https://www.zoho.com");
record.addFieldValue(Field.Leads.WEBSITE, null);
multi_module_lookup
JSON Object
com.zoho.crm.api.record.Record record1 = new com.zoho.crm.api.record.Record();
record1.setId(3477061000021552002l);
HashMap<String, String> module = new HashMap<String, String>();
module.put("id", "3477061000000002179");
module.put("api_name", "Contacts");
record1.addKeyValue("module", module); record.addFieldValue(Field.Appointments__s.APPOINTMENT_FOR, record1);
--

Custom Fields:

Zoho CRM's flexibility extends to custom fields, allowing you to create additional fields specific to your business needs. Here's how to manage them using the Java SDK:
a. Import the Record Class:
com.zoho.crm.api.record.Record record = new com.zoho.crm.api.record.Record();

b. Assign Values to Custom Fields:
The syntax for assigning values to standard fields uses the addKeyValue method of the Record object:
record.addKeyValue("{field_api_name}", value);
Replace {field_api_name} with the appropriate values for your specific use case. 

Assigning values to Custom Fields:

Field Type

JSON Type
Assign Values
Assign Null Values
text (single line)
string 
record.addKeyValue("Single_Line_Field", "Single Line Text Value");record.addKeyValue("Single_Line_Field", null);
textarea (multiline)
string
record.addKeyValue("Multi_Line_Field", "Text Multi Line 2");record.addKeyValue("Multi_Line_Field", null);
email
string
record.addKeyValue("Email_Field", " abc@zoho.com");record.addKeyValue("Email_Field", null);
phone
string
record.addKeyValue("Phone_Field", "9900000000");record.addKeyValue("Phone_Field", null);
picklist
string
record.addKeyValue("Pick_List_Field", new Choice<String>("Option 1"));
record.addKeyValue("Pick_List_Field", null);
multiselectpicklist
JSON array
record.addKeyValue("Multi_Select_Field", new ArrayList<>(Arrays.asList(new Choice<String>("Option 1"), new Choice<String>("Option 2"))));
 record.addKeyValue("Multi_Select_Field", null);
date
string
record.addKeyValue("Date_Field", LocalDate.of(2024, 6, 13));record.addKeyValue("Date_Field", null);
datetime
string
record.addKeyValue("Date_Time_Field", OffsetDateTime.of(2024, 06, 20, 10, 00, 01, 00, ZoneOffset.of("+05:30")));
record.addKeyValue("Date_Time_Field", null);
integer (number)
integer
record.addKeyValue("Number_Field", 12);record.addKeyValue("Number_Field", null);
currency (double)
double
record.addKeyValue("Currency_Field", 10.25);record.addKeyValue("Currency_Field", null);
double
double
record.addKeyValue("Decimal_Field", 12.25);
record.addKeyValue("Decimal_Field", null);
percent 
double
record.addKeyValue("Percent_Field", 12.25);
record.addKeyValue("Percent_Field", null);
bigint (long integer)
string
record.addKeyValue("Long_Integer_Field", 12345678l);
record.addKeyValue("Long_Integer_Field", null);
boolean (checkbox)
boolean
record.addKeyValue("Checkbox_Field", true);
--
website (URL)
string
record.addKeyValue("URL_Field", " https://www.zoho.com");record.addKeyValue("URL_Field", " https://www.zoho.com");
lookup
JSON Object
com.zoho.crm.api.record.Record account = new com.zoho.crm.api.record.Record();
account.setId(3477061000023362051l);
record1.addKeyValue("Lookup_Field", account);
--
multiselectlookup
JSON Object
List<com.zoho.crm.api.record.Record> multirecords = new ArrayList<>();
com.zoho.crm.api.record.Record record1 = new com.zoho.crm.api.record.Record();
com.zoho.crm.api.record.Record linkingRecord = new com.zoho.crm.api.record.Record();
record1.addKeyValue("id", 3477061000023362051L);
linkingRecord.addKeyValue("Multi_Select_Lookup_Field", record1);
multirecords.add(linkingRecord);
record.addKeyValue("Multi_Select_Lookup_Field", multirecords);
List<com.zoho.crm.api.record.Record> multirecords = new ArrayList<>();
com.zoho.crm.api.record.Record linkingRecord = new com.zoho.crm.api.record.Record();
linkingRecord.addKeyValue("_delete", true);
linkingRecord.addKeyValue("id", 3477061000023479001l);
multirecords.add(linkingRecord);
record.addKeyValue("Multi_Select_Lookup_Field", multirecords);
userlookup
JSON object
com.zoho.crm.api.users.MinifiedUser user = new com.zoho.crm.api.users.MinifiedUser();
user.setId(3477061000005791024l);
record.addKeyValue("User_Field", user);
record.addKeyValue("User_Field", null);
multiuserlookup
JSON array
List<com.zoho.crm.api.record.Record> multiuser = new ArrayList<>();
com.zoho.crm.api.record.Record record1 = new com.zoho.crm.api.record.Record();
com.zoho.crm.api.users.MinifiedUser linkingRecord = new com.zoho.crm.api.users.MinifiedUser();
linkingRecord.setId(3477061000005791024l);
record1.addKeyValue("MultiUser", linkingRecord);
multiuser.add(record1);
record.addKeyValue("MultiUser", multiuser);
List<com.zoho.crm.api.record.Record> multiuser = new ArrayList<>();
com.zoho.crm.api.record.Record record1 = new com.zoho.crm.api.record.Record();
record1.addKeyValue("_delete", true);
record1.setId(3477061000023490004l);
multiuser.add(record1);
record.addKeyValue("MultiUser", multiuser);
subform
JSON array
List<com.zoho.crm.api.record.Record> subformList = new ArrayList<com.zoho.crm.api.record.Record>();
com.zoho.crm.api.record.Record subform = new com.zoho.crm.api.record.Record();
subform.addKeyValue("Name", "SDK");
com.zoho.crm.api.users.MinifiedUser user1 = new com.zoho.crm.api.users.MinifiedUser();
user1.setId(3477061000018959001l);
subform.addKeyValue("User_Field", user1);
subformList.add(subform);
record.addKeyValue("Subform_Field", subformList);
List<com.zoho.crm.api.record.Record> subformList = new ArrayList<com.zoho.crm.api.record.Record>();
com.zoho.crm.api.record.Record subform = new com.zoho.crm.api.record.Record();
subform.addKeyValue("_delete", true);
subform.setId(3477061000023502001l);
subformList.add(subform);
record.addKeyValue("Subform_Field", subformList);
imageupload
JSON array
List<ImageUpload> imageUploads = new ArrayList<ImageUpload>();
ImageUpload imageUpload = new ImageUpload();
imageUpload.setFileIdS("18aed780ff77c8698406d1befdb1341435");
imageUploads.add(imageUpload);
record.addKeyValue("Image_Upload", imageUploads);
List<ImageUpload> imageUploads = new ArrayList<ImageUpload>();
ImageUpload imageUpload = new ImageUpload();
imageUpload.setDelete(null);
imageUpload.setId("3477061000023502009");
imageUploads.add(imageUpload);
record.addKeyValue("Image_Upload", imageUploads);
fileupload
JSON array
List<FileDetails> fileDetails = new ArrayList<FileDetails>();
FileDetails fileDetail1 = new FileDetails(); fileDetail1.setFileIdS("ed69c3580d797bc");
fileDetails.add(fileDetail1);
record.addKeyValue("File_Upload", fileDetails);
List<FileDetails> fileDetails = new ArrayList<FileDetails>();
FileDetails fileDetail1 = new FileDetails();
fileDetail1.setDelete(null);
fileDetail1.setId("3477061000023499013");
fileDetails.add(fileDetail1);
record.addKeyValue("File_Upload", fileDetails);
multi_module_lookup
JSON Object
com.zoho.crm.api.record.Record record1 = new com.zoho.crm.api.record.Record();
record1.setId(3477061000021552002l);
HashMap<String, String> module = new HashMap<String, String>();
module.put("id", "3477061000000002179");
module.put("api_name", "Contacts");
record1.addKeyValue("module", module);
record.addKeyValue("Appointment_For", record1);
--

In the next week Kaizen, we will discuss how to handle field data types for the remaining SDKs.

We hope this guide has provided valuable insights into managing different field data types using Zoho CRM SDKs. By combining the information shared in this post with the sample codes provided in our GitHub repository, you will be well-equipped to tailor solutions to meet your specific requirements. 

Do you have any specific topics that you'd like us to address in our Kaizen series? We are here to help! Feel free to share your suggestions in the comments below or reach out to our support team directly at support@zohocrm.com

Thank you for joining us this week. Happy Coding!!


Recommended Reads:



Previous Post : How to navigate to another page using Client Script | Kaizen Collection : Home

Join us for our upcoming Zoho CRM Developer Series: Zoho CRM APIs, where you can explore more about Zoho CRM APIs. Register Now!

    Access your files securely from anywhere

        Zoho Developer Community




                                  Zoho Desk Resources

                                  • Desk Community Learning Series


                                  • Digest


                                  • Functions


                                  • Meetups


                                  • Kbase


                                  • Resources


                                  • Glossary


                                  • Desk Marketplace


                                  • MVP Corner


                                  • Word of the Day



                                      Zoho Marketing Automation


                                              Manage your brands on social media



                                                    Zoho TeamInbox Resources

                                                      Zoho DataPrep Resources



                                                        Zoho CRM Plus Resources

                                                          Zoho Books Resources


                                                            Zoho Subscriptions Resources

                                                              Zoho Projects Resources


                                                                Zoho Sprints Resources


                                                                  Qntrl Resources


                                                                    Zoho Creator Resources



                                                                        Zoho Campaigns Resources


                                                                          Zoho CRM Resources

                                                                          • CRM Community Learning Series

                                                                            CRM Community Learning Series


                                                                          • Kaizen

                                                                            Kaizen

                                                                          • Functions

                                                                            Functions

                                                                          • Meetups

                                                                            Meetups

                                                                          • Kbase

                                                                            Kbase

                                                                          • Resources

                                                                            Resources

                                                                          • Digest

                                                                            Digest

                                                                          • CRM Marketplace

                                                                            CRM Marketplace

                                                                          • MVP Corner

                                                                            MVP Corner





                                                                              Design. Discuss. Deliver.

                                                                              Create visually engaging stories with Zoho Show.

                                                                              Get Started Now