Skip to main content

Java SDK Samples - Blueprint Operations

Get Blueprint Details
Update Blueprint
              
              
package com.zoho.crm.sample.blueprint;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.List;

import java.util.Map;

import org.json.JSONObject;

import com.zoho.crm.api.blueprint.APIException;

import com.zoho.crm.api.blueprint.ActionResponse;

import com.zoho.crm.api.blueprint.AutoNumber;

import com.zoho.crm.api.blueprint.BluePrintOperations;

import com.zoho.crm.api.blueprint.BodyWrapper;

import com.zoho.crm.api.blueprint.Field;

import com.zoho.crm.api.blueprint.Layout;

import com.zoho.crm.api.blueprint.MultiSelectLookup;

import com.zoho.crm.api.blueprint.NextTransition;

import com.zoho.crm.api.blueprint.PickListValues;

import com.zoho.crm.api.blueprint.ProcessInfo;

import com.zoho.crm.api.blueprint.ResponseHandler;

import com.zoho.crm.api.blueprint.ResponseWrapper;

import com.zoho.crm.api.blueprint.SuccessResponse;

import com.zoho.crm.api.blueprint.ToolTip;

import com.zoho.crm.api.blueprint.Transition;

import com.zoho.crm.api.blueprint.ViewType;

import com.zoho.crm.api.record.Record;

import com.zoho.crm.api.users.User;

import com.zoho.crm.api.util.APIResponse;

import com.zoho.crm.api.util.Model;

public class BluePrint
{
    /**
     * Update Blueprint
     * This method is used to update a single record's Blueprint details with ID and print the response.
     * @param moduleAPIName The API Name of the record's module
     * @param recordId The ID of the record to get Blueprint
     * @param transitionId The ID of the Blueprint transition Id
     * @throws Exception
     */
    public static void updateBlueprint(String moduleAPIName, Long recordId, Long transitionId) throws Exception
    {
        //ID of the BluePrint to be updated
        //String moduleAPIName = "Leads";
        //Long recordId = 34770614381002l;
        //Long transitionId = 34770610173096l;
                
        //Get instance of BluePrintOperations Class that takes recordId and moduleAPIName as parameter
        BluePrintOperations bluePrintOperations = new BluePrintOperations(recordId, moduleAPIName);
        
        //Get instance of BodyWrapper Class that will contain the request body
        BodyWrapper bodyWrapper = new BodyWrapper();
        
        //List of BluePrint instances
        List bluePrintList = new ArrayList();

        //Get instance of BluePrint Class
        com.zoho.crm.api.blueprint.BluePrint bluePrint = new com.zoho.crm.api.blueprint.BluePrint();
        
        //Set transition_id to the BluePrint instance
        bluePrint.setTransitionId(transitionId);
        
        //Get instance of Record Class
        Record data = new Record();
        
        HashMap lookup = new HashMap();
        
        lookup.put("Phone", "8940372937");
        
        lookup.put("id", "8940372937");
        
        
        data.addKeyValue("Phone", "8940372937");
        
        data.addKeyValue("Notes", "Updated via blueprint");
        
        HashMap attachments = new HashMap();
        
        ArrayList fileIds = new ArrayList();
        
        fileIds.add("blojtd2d13b5f044e4041a3315e0793fb21ef");
        
        attachments.put("file_id", fileIds);
        
        data.addKeyValue("Attachments", attachments);
        
        ArrayList> checkLists = new ArrayList>();
        
        HashMap checkListItem = new HashMap();
        
        checkListItem.put("list 1", true);
        
        checkLists.add(checkListItem);
        
        checkListItem = new HashMap();
        
        checkListItem.put("list 2", true);
        
        checkLists.add(checkListItem);
        
        checkListItem = new HashMap();
        
        checkListItem.put("list 3", true);
        
        checkLists.add(checkListItem);
        
        data.addKeyValue("CheckLists", checkLists);
        
        //Set data to the BluePrint instance
        bluePrint.setData(data);
        
        //Add BluePrint instance to the list
        bluePrintList.add(bluePrint);
        
        //Set the list to bluePrint in BodyWrapper instance
        bodyWrapper.setBlueprint(bluePrintList);
        
        //Call updateBluePrint method that takes BodyWrapper instance 
        APIResponse response = bluePrintOperations.updateBlueprint(bodyWrapper);
        
        if(response != null)
        {
            //Get the status code from response
            System.out.println("Status Code: " + response.getStatusCode());
            
            //Check if expected response is received
            if(response.isExpected())
            {
                //Get object from response
                ActionResponse actionResponse = response.getObject();
                
                //Check if the request is successful
                if(actionResponse instanceof SuccessResponse)
                {
                    //Get the received SuccessResponse instance
                    SuccessResponse successResponse = (SuccessResponse)actionResponse;
                    
                    //Get the Status
                    System.out.println("Status: " + successResponse.getStatus().getValue());
                    
                    //Get the Code
                    System.out.println("Code: " + successResponse.getCode().getValue());
                    
                    System.out.println("Details: " );
                    
                    if(successResponse.getDetails() != null)
                    {
                        //Get the details map
                        for(Map.Entry entry : successResponse.getDetails().entrySet())
                        {
                            //Get each value in the map
                            System.out.println(entry.getKey() + ": " + entry.getValue());
                        }
                    }
                    
                    //Get the Message
                    System.out.println("Message: " + successResponse.getMessage().getValue());
                }
                //Check if the request returned an exception
                else if(actionResponse instanceof APIException)
                {
                    //Get the received APIException instance
                    APIException exception = (APIException) actionResponse;
                    
                    //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() + ": ");
                        
                        if(entry.getValue() instanceof List)
                        {
                            @SuppressWarnings("unchecked")
                            List validationError = (List) entry.getValue();
                            
                            for(ValidationError error : validationError)
                            {
                                System.out.println("Field APIName " + error.getAPIName() + " : " + error.getMessage());
                                System.out.println("Field index "+error.getIndex());
                                System.out.println("Field info message "+error.getInfoMessage());
                                System.out.println("Field parent api name "+error.getParentAPIName());
                            }
                        }
                        else
                        {
                            System.out.println(entry.getValue().toString());
                        }
                    }
                    
                    //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));
                }
            }
        }
    }
}