Java SDK Samples - Related List Operations

Get All Related Lists of a Module
              
              
package samples.src.com.zoho.crm.api.relatedlist;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.zoho.crm.api.relatedlists.APIException;
import com.zoho.crm.api.relatedlists.RelatedListsOperations;
import com.zoho.crm.api.relatedlists.ResponseHandler;
import com.zoho.crm.api.relatedlists.ResponseWrapper;
import com.zoho.crm.api.util.APIResponse;
import com.zoho.crm.api.util.Model;

public class RelatedList
{
    /**
     * Get RelatedLists
     * This method is used to get the related list data of a particular module and print the response.
     * @param moduleAPIName - The API Name of the module to get related lists
     * @throws Exception
     */
    public static void getRelatedLists(String moduleAPIName) throws Exception
    {
        //example
        //String moduleAPIName = "Leads";
        
        //Get instance of RelatedListsOperations Class that takes moduleAPIName as parameter
        RelatedListsOperations relatedListsOperations = new RelatedListsOperations(moduleAPIName);
        
        //Call getRelatedLists method
        APIResponse response = relatedListsOperations.getRelatedLists();
        
        if(response != null)
        {
            //Get the status code from response
            System.out.println("Status Code: " + response.getStatusCode());
            
            if(Arrays.asList(204,304).contains(response.getStatusCode()))
            {
                System.out.println(response.getStatusCode() == 204? "No Content" : "Not Modified");
                return;
            }
            
            //Check if expected response is received
            if(response.isExpected())
            {
                //Get object from response
                ResponseHandler responseHandler = response.getObject();
                
                if(responseHandler instanceof ResponseWrapper)
                {
                    //Get the received ResponseWrapper instance
                    ResponseWrapper responseWrapper = (ResponseWrapper) responseHandler;
                    
                    //Get the list of obtained RelatedList instances
                    List relatedLists = responseWrapper.getRelatedLists();
                
                    for(com.zoho.crm.api.relatedlists.RelatedList relatedList : relatedLists)
                    {
                        //Get the SequenceNumber of each RelatedList
                        System.out.println("RelatedList SequenceNumber: " + relatedList.getSequenceNumber());
                        
                        //Get the DisplayLabel of each RelatedList
                        System.out.println("RelatedList DisplayLabel: " + relatedList.getDisplayLabel());
                        
                        //Get the APIName of each RelatedList
                        System.out.println("RelatedList APIName: " + relatedList.getAPIName());
                        
                        //Get the Module of each RelatedList
                        System.out.println("RelatedList Module: " + relatedList.getModule());
                        
                        //Get the Name of each RelatedList
                        System.out.println("RelatedList Name: " + relatedList.getName());
                        
                        //Get the Action of each RelatedList
                        System.out.println("RelatedList Action: " + relatedList.getAction());
    
                        //Get the ID of each RelatedList
                        System.out.println("RelatedList ID: " + relatedList.getId());
                        
                        //Get the Href of each RelatedList
                        System.out.println("RelatedList Href: " + relatedList.getHref());
                        
                        //Get the Type of each RelatedList
                        System.out.println("RelatedList Type: " + relatedList.getType());
                        
                        //Get the Connected Module of each RelatedList
                        System.out.println("RelatedList Connectedmodule: " + relatedList.getConnectedmodule());
                        
                        //Get the Linking Module of each RelatedList
                        System.out.println("RelatedList Linkingmodule: " + relatedList.getLinkingmodule());
                    }
                }
                //Check if the request returned an exception
                else if(responseHandler instanceof APIException)
                {
                    //Get the received APIException instance
                    APIException exception = (APIException) responseHandler;
                    
                    //Get the Status
                    System.out.println("Status: " + exception.getStatus().getValue());
                    
                    //Get the Code
                    System.out.println("Code: " + exception.getCode().getValue());
                    
                    System.out.println("Details: " );
                    
                    //Get the details map
                    for(Map.Entry entry : exception.getDetails().entrySet())
                    {
                        //Get each value in the map
                        System.out.println(entry.getKey() + ": " + entry.getValue());
                    }
                    
                    //Get the Message
                    System.out.println("Message: " + exception.getMessage().getValue());
                }
            }
            else
            {//If response is not as expected
                
                //Get model object from response
                Model responseObject = response.getModel();
                
                //Get the response object's class
                Class extends Model> clas = responseObject.getClass();
                
                //Get all declared fields of the response class
                java.lang.reflect.Field[] fields = clas.getDeclaredFields();
                
                for(java.lang.reflect.Field field : fields)
                {
                    //Get each value
                    System.out.println(field.getName() + ":" + field.get(responseObject));
                }
            }
        }
    }
}
 
Get a Related List
              
              
package samples.src.com.zoho.crm.api.relatedlist;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.zoho.crm.api.relatedlists.APIException;
import com.zoho.crm.api.relatedlists.RelatedListsOperations;
import com.zoho.crm.api.relatedlists.ResponseHandler;
import com.zoho.crm.api.relatedlists.ResponseWrapper;
import com.zoho.crm.api.util.APIResponse;
import com.zoho.crm.api.util.Model;

public class RelatedList
{
    /**
     * Get RelatedList
     * This method is used to get the single related list data of a particular module with relatedListId and print the response.
     * @param moduleAPIName - The API Name of the module to get related list
     * @param relatedListId - The ID of the relatedList to be obtained
     * @throws Exception
     */
    public static void getRelatedLists(String moduleAPIName) throws Exception
    {
        //example
        //String moduleAPIName = "Leads";
        
        //Get instance of RelatedListsOperations Class that takes moduleAPIName as parameter
        RelatedListsOperations relatedListsOperations = new RelatedListsOperations(moduleAPIName);
        
        //Call getRelatedLists method
        APIResponse response = relatedListsOperations.getRelatedLists();
        
        if(response != null)
        {
            //Get the status code from response
            System.out.println("Status Code: " + response.getStatusCode());
            
            if(Arrays.asList(204,304).contains(response.getStatusCode()))
            {
                System.out.println(response.getStatusCode() == 204? "No Content" : "Not Modified");
                return;
            }
            
            //Check if expected response is received
            if(response.isExpected())
            {
                //Get object from response
                ResponseHandler responseHandler = response.getObject();
                
                if(responseHandler instanceof ResponseWrapper)
                {
                    //Get the received ResponseWrapper instance
                    ResponseWrapper responseWrapper = (ResponseWrapper) responseHandler;
                    
                    //Get the list of obtained RelatedList instances
                    List relatedLists = responseWrapper.getRelatedLists();
                
                    for(com.zoho.crm.api.relatedlists.RelatedList relatedList : relatedLists)
                    {
                        //Get the SequenceNumber of each RelatedList
                        System.out.println("RelatedList SequenceNumber: " + relatedList.getSequenceNumber());
                        
                        //Get the DisplayLabel of each RelatedList
                        System.out.println("RelatedList DisplayLabel: " + relatedList.getDisplayLabel());
                        
                        //Get the APIName of each RelatedList
                        System.out.println("RelatedList APIName: " + relatedList.getAPIName());
                        
                        //Get the Module of each RelatedList
                        System.out.println("RelatedList Module: " + relatedList.getModule());
                        
                        //Get the Name of each RelatedList
                        System.out.println("RelatedList Name: " + relatedList.getName());
                        
                        //Get the Action of each RelatedList
                        System.out.println("RelatedList Action: " + relatedList.getAction());
    
                        //Get the ID of each RelatedList
                        System.out.println("RelatedList ID: " + relatedList.getId());
                        
                        //Get the Href of each RelatedList
                        System.out.println("RelatedList Href: " + relatedList.getHref());
                        
                        //Get the Type of each RelatedList
                        System.out.println("RelatedList Type: " + relatedList.getType());
                        
                        //Get the Connected Module of each RelatedList
                        System.out.println("RelatedList Connectedmodule: " + relatedList.getConnectedmodule());
                        
                        //Get the Linking Module of each RelatedList
                        System.out.println("RelatedList Linkingmodule: " + relatedList.getLinkingmodule());
                    }
                }
                //Check if the request returned an exception
                else if(responseHandler instanceof APIException)
                {
                    //Get the received APIException instance
                    APIException exception = (APIException) responseHandler;
                    
                    //Get the Status
                    System.out.println("Status: " + exception.getStatus().getValue());
                    
                    //Get the Code
                    System.out.println("Code: " + exception.getCode().getValue());
                    
                    System.out.println("Details: " );
                    
                    //Get the details map
                    for(Map.Entry entry : exception.getDetails().entrySet())
                    {
                        //Get each value in the map
                        System.out.println(entry.getKey() + ": " + entry.getValue());
                    }
                    
                    //Get the Message
                    System.out.println("Message: " + exception.getMessage().getValue());
                }
            }
            else
            {//If response is not as expected
                
                //Get model object from response
                Model responseObject = response.getModel();
                
                //Get the response object's class
                Class extends Model> clas = responseObject.getClass();
                
                //Get all declared fields of the response class
                java.lang.reflect.Field[] fields = clas.getDeclaredFields();
                
                for(java.lang.reflect.Field field : fields)
                {
                    //Get each value
                    System.out.println(field.getName() + ":" + field.get(responseObject));
                }
            }
        }
    }
}