Java - Integration Tasks

Integration tasks in Java are a set of functions that allow a user to perform some of the most basic tasks such as creating a record, updating a record, etc,. These integration tasks in Java use v2 APIs and you can use them as-is in your code.

Using Java Integration Tasks, you can

Points to Remember

  • You must use only field API names in the input.

  • The class name in your code and the name of your .java file must be the same. For example, in create a record task, createRecord is the class name. Hence, the file name must be createRecord.java.

  • You must pass the record ids as string in the input. For example: "5674531764900087".

Create multiple records

Set up functions in a way that records are automatically created based on certain actions. For example, you can trigger the function to create a record in tasks upon changing the status of a lead. Use the crm.getApi("v2").createRecord() task to create records.

The below code shows the Java function to create a record in the Leads module using v2 integration task.

// Don't remove below imports. 

import com.zoho.cloud.function.Context;
import com.zoho.cloud.function.basic.*;
import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
import com.zoho.cloud.task.crm.CRM;
import org.json.simple.parser.JSONParser;

/*
   - The Class which implements ZCFunction will act as the main of the JAVA Package
   - Java Execution starts from the method name 'runner'. 
*/

public class createRecords implements ZCFunction {
    public void runner(Context context, BasicIO basicIO) throws Exception {

        String request = (String) basicIO.getParameter("crmAPIRequest");
        JSONParser parser = new JSONParser();
        JSONObject requestObj = (JSONObject) parser.parse(request);
        JSONObject record = (JSONObject) requestObj.get("record");

        String last_Name = (String) record.get("Last_Name");
        String first_Name = (String) record.get("First_Name");
        String company = (String) record.get("Company");
        String mobile = (String) record.get("Mobile");

        CRM crm = (CRM) context.getIntegrationTask().getService("CRM");
        JSONObject data = new JSONObject();
        JSONArray arr = new JSONArray();

        JSONObject leadInfo = new JSONObject();
        leadInfo.put("Last_Name", last_Name);
        leadInfo.put("First_Name", first_Name);
        leadInfo.put("Company", company);
        leadInfo.put("Mobile", mobile);
        arr.add(leadInfo);

        JSONObject leadInfo1 = new JSONObject();
        leadInfo1.put("Last_Name", last_Name);
        leadInfo1.put("First_Name", first_Name);
        leadInfo1.put("Company", company);
        leadInfo1.put("Mobile", mobile);
        arr.add(leadInfo1);

        data.put("data", arr);

        String response = crm.getApi("v2").createRecord("Leads", data);
        basicIO.write(response);

    }
}
Note
  • You can insert a maximum of 100 records per integration task.

Create a record

// Don't remove below imports. 

import com.zoho.cloud.function.Context;
import com.zoho.cloud.function.basic.*;
import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
import com.zoho.cloud.task.crm.CRM;
import org.json.simple.parser.JSONParser;

/*
   - The Class which implements ZCFunction will act as the main of the JAVA Package
   - Java Execution starts from the method name 'runner'. 
*/

public class createRecord implements ZCFunction {
    public void runner(Context context, BasicIO basicIO) throws Exception {

        String request = (String) basicIO.getParameter("crmAPIRequest");
        JSONParser parser = new JSONParser();
        JSONObject requestObj = (JSONObject) parser.parse(request);
        JSONObject record = (JSONObject) requestObj.get("record");

        String last_Name = (String) record.get("Last_Name");
        String first_Name = (String) record.get("First_Name");
        String company = (String) record.get("Company");
        String mobile = (String) record.get("Mobile");

        CRM crm = (CRM) context.getIntegrationTask().getService("CRM");
        JSONObject data = new JSONObject();
        JSONArray arr = new JSONArray();

        JSONObject leadInfo = new JSONObject();
        leadInfo.put("Last_Name", last_Name);
        leadInfo.put("First_Name", first_Name);
        leadInfo.put("Company", company);
        leadInfo.put("Mobile", mobile);
        arr.add(leadInfo);

        data.put("data", arr);

        String response = crm.getApi("v2").createRecord("Leads", data);
        basicIO.write(response);

    }
}

Update multiple records

You would have to update the records, often. Based on the programmed scenario, you can automate updating existing information, adding additional information etc, using the crm.getApi("v2").updateRecord() task.

The below code shows the Java function to update multiple records in the Leads module using v2 integration task.

import com.zoho.cloud.function.Context;
import com.zoho.cloud.function.basic.*;
import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
import com.zoho.cloud.task.crm.CRM;

public class updaterecords implements ZCFunction {
    public void runner(Context context, BasicIO basicIO) throws Exception {
        CRM crm = (CRM) context.getIntegrationTask().getService("CRM");
        JSONObject data = new JSONObject();
        JSONArray arr = new JSONArray();
        JSONObject leadInfo = new JSONObject();
        leadInfo.put("Last_Name", "Boyle1");
        leadInfo.put("Lead_Status", "Contacted");
        arr.add(leadInfo);

        JSONObject leadInfo1 = new JSONObject();
        leadInfo.put("Last_Name", "Boyle1");
        leadInfo.put("Lead_Status", "Contacted");
        arr.add(leadInfo1);
        data.put("data", arr);

        String response = crm.getApi("v2").updateRecord("Leads", data);
        basicIO.write(response);
    }
}
Note
  • You can update a maximum of 100 records per integration task.

Update a record

Use the below code to update a record using v2 integration task.

import com.zoho.cloud.function.Context;
import com.zoho.cloud.function.basic.*;
import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
import com.zoho.cloud.task.crm.CRM;

public class updaterecord implements ZCFunction {
    public void runner(Context context, BasicIO basicIO) throws Exception {
        CRM crm = (CRM) context.getIntegrationTask().getService("CRM");
        JSONObject data = new JSONObject();
        JSONArray arr = new JSONArray();
        JSONObject leadInfo = new JSONObject();
        leadInfo.put("Last_Name", "Boyle1");
        leadInfo.put("Lead_Status", "Pre-Qualified");
        arr.add(leadInfo);
        data.put("data", arr);
        String response = crm.getApi("v2").updateRecord("Leads", 655231000000458281l, data);
        basicIO.write(response);
    }
}
Note
  • You can update a maximum of 100 records per integration task.

Get Record by ID

You can use the CRM.V2.getRecordById() task to fetch the information of a particular record.

The below code shows the Java function to update a record in the Leads module using v2 integration task.

import com.zoho.cloud.function.Context;
import com.zoho.cloud.function.basic.*;
import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
import com.zoho.cloud.task.crm.CRM;

public class getrecord implements ZCFunction {
    public void runner(Context context, BasicIO basicIO) throws Exception {
        CRM crm = (CRM) context.getIntegrationTask().getService("CRM");
        String response = crm.getApi("v2").getRecordById("Leads", < record id >);
        basicIO.write(response);
    }
}

Get Org Info

You can use the CRM.V2.getOrgInfo() task to fetch information about your organization.

Use the below code to get your organization details using v2 integration task in a Java function.

import com.zoho.cloud.function.Context;
import com.zoho.cloud.function.basic.*;
import com.zoho.cloud.task.crm.CRM;

public class getorg implements ZCFunction {
    public void runner(Context context, BasicIO basicIO) throws Exception {
        CRM crm = (CRM) context.getIntegrationTask().getService("CRM");
        String response = crm.getApi("v2").getOrgInfo();
        basicIO.write(response);
    }
}

Search Records

Search for specific records by specifying the criteria for the search. The searched records can be used to perform actions anywhere. Searching for a record requires the module name and the search criteria to be specified.

import com.zoho.cloud.function.Context;
import com.zoho.cloud.function.basic.*;
import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
import com.zoho.cloud.task.crm.CRM;

public class searchRecords implements ZCFunction {
    public void runner(Context context, BasicIO basicIO) throws Exception {
        CRM crm = (CRM) context.getIntegrationTask().getService("CRM");
        String response = crm.getApi("v2").searchRecords("Leads", "(Last_Name:starts_with:Boyle)");
        basicIO.write(response);
    }
}

Convert Lead

Use the convertLead() task to convert a lead to a deal or a contact.

import com.zoho.cloud.function.Context;
import com.zoho.cloud.function.basic.*;
import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
import com.zoho.cloud.task.crm.CRM;

public class convertLead implements ZCFunction {
    public void runner(Context context, BasicIO basicIO) throws Exception {
        CRM crm = (CRM) context.getIntegrationTask().getService("CRM");
        String response = crm.getApi("v2").convertLead( <record_id>);
        basicIO.write(response);
    }
}

Get Org Variables

A CRM Variable can have a unique set of values and can be widely used as merge fields in Email templates, Mail merge templates, and Inventory templates. You can also use them as reusable authentication parameters in APIs.
Use the getOrgVariables() task to retrieve the variables created for your organization.

import com.zoho.cloud.function.Context;
import com.zoho.cloud.function.basic.*;
import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
import com.zoho.cloud.task.crm.CRM;

public class getOrgVariables implements ZCFunction {
    public void runner(Context context, BasicIO basicIO) throws Exception {
        CRM crm = (CRM) context.getIntegrationTask().getService("CRM");
        String response = crm.getApi("v2").getOrgVariables();
        basicIO.write(response);
    }
}

Get Org Variables by ID

Use the getOrgVariableById() task to retrieve a specific variable from a group by its variable and group IDs.

import com.zoho.cloud.function.Context;
import com.zoho.cloud.function.basic.*;
import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
import com.zoho.cloud.task.crm.CRM;

public class getOrgVariables implements ZCFunction {
    public void runner(Context context, BasicIO basicIO) throws Exception {
        CRM crm = (CRM) context.getIntegrationTask().getService("CRM");
        String response = crm.getApi("v2").getOrgVariableById(<variable_id>, <group_id>);
        basicIO.write(response);
    }
}

Get Related Records

Use the getRelatedRecords() task to retrieve the list of related list records associated to a parent record in a module.

import com.zoho.cloud.function.Context;
import com.zoho.cloud.function.basic.*;
import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
import com.zoho.cloud.task.crm.CRM;

public class getRelatedRecords implements ZCFunction {
    public void runner(Context context, BasicIO basicIO) throws Exception {
        CRM crm = (CRM) context.getIntegrationTask().getService("CRM");
        String response = crm.getApi("v2").getRelatedRecords(<relation_name>, <parent_module_name>, <parent_record_id>);
        basicIO.write(response);
    }
}