Skip to main content

Java SDK Samples - Share Records Operations

Get Shared Record Details
Share a Record
              
              
package samples.src.com.zoho.crm.api.sharerecords;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.List;

import java.util.Map;

import com.zoho.crm.api.ParameterMap;

import com.zoho.crm.api.modules.Module;

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

import com.zoho.crm.api.sharerecords.ActionHandler;

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

import com.zoho.crm.api.sharerecords.ActionWrapper;

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

import com.zoho.crm.api.sharerecords.DeleteActionHandler;

import com.zoho.crm.api.sharerecords.DeleteActionResponse;

import com.zoho.crm.api.sharerecords.DeleteActionWrapper;

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

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

import com.zoho.crm.api.sharerecords.ShareRecord;

import com.zoho.crm.api.sharerecords.ShareRecordsOperations;

import com.zoho.crm.api.sharerecords.ShareRecordsOperations.GetSharedRecordDetailsParam;

import com.zoho.crm.api.sharerecords.SharedThrough;

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

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

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

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

public class ShareRecords
{
    /**
     * Share Record
     * This method is used to share the record and print the response.
     * @param moduleAPIName - The API Name of the module to shared record.
     * @param recordId - The ID of the record to be obtained.
     * @throws Exception
     */
    public static void shareRecord(String moduleAPIName, Long recordId) throws Exception
    {
        //example
        //String moduleAPIName = "Leads";
        //Long recordId = 34770615177002L;
        
        //Get instance of ShareRecordsOperations Class that takes recordId and moduleAPIName as parameter
        ShareRecordsOperations shareRecordsOperations = new ShareRecordsOperations(recordId, moduleAPIName);
        
        //Get instance of BodyWrapper Class that will contain the request body
        BodyWrapper request = new BodyWrapper();
        
        //List of ShareRecord instances
        List shareList = new ArrayList();
        
        //Get instance of ShareRecord Class
        ShareRecord share1 = new ShareRecord();
        
        for(int i = 0; i  response = shareRecordsOperations.shareRecord(request);
        
        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
                ActionHandler actionHandler = response.getObject();
                
                if(actionHandler instanceof ActionWrapper)
                {
                    //Get the received ActionWrapper instance
                    ActionWrapper actionWrapper = (ActionWrapper) actionHandler;
                    
                    //Get the list of obtained ActionResponse instances
                    List actionResponses = actionWrapper.getShare();
                    
                    for(ActionResponse actionResponse : actionResponses)
                    {
                        //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: " );
                            
                            //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() + ": " + entry.getValue());
                            }
                            
                            //Get the Message
                            System.out.println("Message: " + exception.getMessage().getValue());
                        }
                    }
                }
                //Check if the request returned an exception
                else if(actionHandler instanceof APIException)
                {
                    //Get the received APIException instance
                    APIException exception = (APIException) actionHandler;
                    
                    //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));
                }
            }
        }
    }
}
 
Update Share Permissions
              
              
package samples.src.com.zoho.crm.api.sharerecords;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.List;

import java.util.Map;

import com.zoho.crm.api.ParameterMap;

import com.zoho.crm.api.modules.Module;

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

import com.zoho.crm.api.sharerecords.ActionHandler;

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

import com.zoho.crm.api.sharerecords.ActionWrapper;

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

import com.zoho.crm.api.sharerecords.DeleteActionHandler;

import com.zoho.crm.api.sharerecords.DeleteActionResponse;

import com.zoho.crm.api.sharerecords.DeleteActionWrapper;

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

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

import com.zoho.crm.api.sharerecords.ShareRecord;

import com.zoho.crm.api.sharerecords.ShareRecordsOperations;

import com.zoho.crm.api.sharerecords.ShareRecordsOperations.GetSharedRecordDetailsParam;

import com.zoho.crm.api.sharerecords.SharedThrough;

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

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

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

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

public class ShareRecords
{
    /**
     * Update Share Permissions
     * This method is used to update the sharing permissions of a record granted to users as Read-Write, Read-only, or grant full access.
     * @param moduleAPIName - The API Name of the module to update share permissions.
     * @param recordId - The ID of the record to be obtained.
     * @throws Exception
     */
    public static void updateSharePermissions(String moduleAPIName, Long recordId) throws Exception
    {
        //example
        //String moduleAPIName = "Leads";
        //Long recordId = 34770615177002L;
        
        //Get instance of ShareRecordsOperations Class that takes recordId and moduleAPIName as parameter
        ShareRecordsOperations shareRecordsOperations = new ShareRecordsOperations(recordId, moduleAPIName);
        
        //Get instance of BodyWrapper Class that will contain the request body
        BodyWrapper request = new BodyWrapper();
        
        //List of ShareRecord instances
        List shareList = new ArrayList();
        
        //Get instance of ShareRecord Class
        ShareRecord share1 = new ShareRecord();
        
        share1.setShareRelatedRecords(true);
        
        share1.setPermission("full_access");
        
        User user = new User();
        
        user.setId(34770615791024l);
        
        share1.setUser(user);
        
        shareList.add(share1);
        
        request.setShare(shareList);
        
        //Call updateSharePermissions method that takes BodyWrapper instance as parameter
        APIResponse response = shareRecordsOperations.updateSharePermissions(request);
        
        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
                ActionHandler actionHandler = response.getObject();
                
                if(actionHandler instanceof ActionWrapper)
                {
                    //Get the received ActionWrapper instance
                    ActionWrapper actionWrapper = (ActionWrapper) actionHandler;
                    
                    //Get the list of obtained ActionResponse instances
                    List actionResponses = actionWrapper.getShare();
                    
                    for(ActionResponse actionResponse : actionResponses)
                    {
                        //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: " );
                            
                            //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() + ": " + entry.getValue());
                            }
                            
                            //Get the Message
                            System.out.println("Message: " + exception.getMessage().getValue());
                        }
                    }
                }
                //Check if the request returned an exception
                else if(actionHandler instanceof APIException)
                {
                    //Get the received APIException instance
                    APIException exception = (APIException) actionHandler;
                    
                    //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));
                }
            }
        }
    }
}
 
Revoke Access to a Shared Record
              
              
package samples.src.com.zoho.crm.api.sharerecords;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.List;

import java.util.Map;

import com.zoho.crm.api.ParameterMap;

import com.zoho.crm.api.modules.Module;

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

import com.zoho.crm.api.sharerecords.ActionHandler;

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

import com.zoho.crm.api.sharerecords.ActionWrapper;

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

import com.zoho.crm.api.sharerecords.DeleteActionHandler;

import com.zoho.crm.api.sharerecords.DeleteActionResponse;

import com.zoho.crm.api.sharerecords.DeleteActionWrapper;

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

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

import com.zoho.crm.api.sharerecords.ShareRecord;

import com.zoho.crm.api.sharerecords.ShareRecordsOperations;

import com.zoho.crm.api.sharerecords.ShareRecordsOperations.GetSharedRecordDetailsParam;

import com.zoho.crm.api.sharerecords.SharedThrough;

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

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

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

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

public class ShareRecords
{
    /**
     * Revoke Shared Record 
     * This method is used to revoke access to a shared record that was shared to users and print the response.
     * @param moduleAPIName - The API Name of the module to revoke shared record.
     * @param recordId - The ID of the record to be obtained.
     * @throws Exception
     */
    public static void revokeSharedRecord(String moduleAPIName, Long recordId) throws Exception
    {
        //example
        //String moduleAPIName = "Leads";
        //Long recordId = 34770615177002L;
        
        //Get instance of ShareRecordsOperations Class that takes recordId and moduleAPIName as parameter
        ShareRecordsOperations shareRecordsOperations = new ShareRecordsOperations(recordId, moduleAPIName);
        
        //Call revokeSharedRecord method
        APIResponse response = shareRecordsOperations.revokeSharedRecord();
        
        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
                DeleteActionHandler deleteActionHandler = response.getObject();
                
                if(deleteActionHandler instanceof DeleteActionWrapper)
                {
                    //Get the received DeleteActionWrapper instance
                    DeleteActionWrapper deleteActionWrapper = (DeleteActionWrapper) deleteActionHandler;
                    
                    //Get the received DeleteActionResponse instance
                    DeleteActionResponse deleteActionResponse = deleteActionWrapper.getShare();
                    
                    //Check if the request is successful
                    if(deleteActionResponse instanceof SuccessResponse)
                    {
                        //Get the received SuccessResponse instance
                        SuccessResponse successResponse = (SuccessResponse)deleteActionResponse;
                        
                        //Get the Status
                        System.out.println("Status: " + successResponse.getStatus().getValue());
                        
                        //Get the Code
                        System.out.println("Code: " + successResponse.getCode().getValue());
                        
                        System.out.println("Details: " );
                        
                        //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(deleteActionResponse instanceof APIException)
                    {
                        //Get the received APIException instance
                        APIException exception = (APIException) deleteActionResponse;
                        
                        //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());
                    }
                }
                //Check if the request returned an exception
                else if(deleteActionHandler instanceof APIException)
                {
                    //Get the received APIException instance
                    APIException exception = (APIException) deleteActionHandler;
                    
                    //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));
                }
            }
        }
    }
}