Scala SDK Samples - Share Records Operations

Get Shared Record Details
              
              
package com.zoho.crm.sample.sharerecords

import java.util

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

import scala.collection.mutable.ArrayBuffer


object ShareRecords {
	/**
   *  Get Shared Record Details 
   * This method is used to get the details of a shared record and print the response.
   *
   * @param moduleAPIName - The API Name of the module to get shared record details.
   * @param recordId      - The ID of the record to be obtained.
   * @throws Exception
   */
  @throws[Exception]
  def getSharedRecordDetails(moduleAPIName: String, recordId: Long): Unit = { //example
    //String moduleAPIName = "Leads"
    //Long recordId = 3477061000005177002L
    //Get instance of ShareRecordsOperations Class that takes moduleAPIName and recordId as parameter
    val shareRecordsOperations = new ShareRecordsOperations(recordId,moduleAPIName )
    //Get instance of ParameterMap Class
    val paramInstance = new ParameterMap
    paramInstance.add(new GetSharedRecordDetailsParam().view, "summary")
    //		paramInstance.add(GetSharedRecordDetailsParam.SHAREDTO, 3477061000000173021l)
    //Call getSharedRecordDetails method that takes paramInstance as parameter
    val responseOption = shareRecordsOperations.getSharedRecordDetails(Option(paramInstance))
    if (responseOption.isDefined) { //check response
      var response= responseOption.get
      println("Status Code: " + response.getStatusCode)
      if (util.Arrays.asList(204, 304).contains(response.getStatusCode)) {
        println(if (response.getStatusCode == 204) "No Content"
        else "Not Modified")
        return
      }
      //Check if expected response is received
      if (response.isExpected) { //Get object from response
        val responseHandler = response.getObject
        if (responseHandler.isInstanceOf[ResponseWrapper]) { //Get the received ResponseWrapper instance
          val responseWrapper = responseHandler.asInstanceOf[ResponseWrapper]
          //Get the obtained ShareRecord instance
          val shareRecords = responseWrapper.getShare

          for (shareRecord {
              println(entry._1 + ": " + entry._2)
            })
            //Get the Message
            println("Message: " + exception.getMessage.getValue)
          }
        }
      }
      else { //If response is not as expected
        //Get model object from response
        val responseObject = response.getModel
        //Get the response object's class
        val clas = responseObject.getClass
        //Get all declared fields of the response class
        val fields = clas.getDeclaredFields
        for (field 
Share a Record
              
              
package com.zoho.crm.sample.sharerecords

import java.util

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

import scala.collection.mutable.ArrayBuffer


object 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
   */
  @throws[Exception]
  def shareRecord(moduleAPIName: String, recordId: Long): Unit = {
    val shareRecordsOperations = new ShareRecordsOperations(recordId,moduleAPIName)
    //Get instance of BodyWrapper Class that will contain the request body
    val request = new BodyWrapper
    //List of ShareRecord instances
    val shareList = new ArrayBuffer[ShareRecord]
    //Get instance of ShareRecord Class
    var share1 = new ShareRecord
    //    for (i {
                println(entry._1 + ": " + entry._2)
              })
              println("Message: " + successResponse.getMessage.getValue)
            }
            else if (actionResponse.isInstanceOf[APIException]) {
              val exception = actionResponse.asInstanceOf[APIException]
              println("Status: " + exception.getStatus.getValue)
              println("Code: " + exception.getCode.getValue)
              println("Details: ")
              exception.getDetails.foreach(entry=>{
                println(entry._1 + ": " + entry._2)
              })
              println("Message: " + exception.getMessage.getValue)
            }
          }
        }
        else if (actionHandler.isInstanceOf[APIException]) {
          val exception = actionHandler.asInstanceOf[APIException]
          println("Status: " + exception.getStatus.getValue)
          println("Code: " + exception.getCode.getValue)
          println("Details: ")
          exception.getDetails.foreach(entry=>{
            println(entry._1 + ": " + entry._2)
          })
          println("Message: " + exception.getMessage.getValue)
        }
      }
      else {
        val responseObject = response.getModel
        val clas = responseObject.getClass
        val fields = clas.getDeclaredFields
        for (field 
Update Share Permissions
              
              
package com.zoho.crm.sample.sharerecords

import java.util

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

import scala.collection.mutable.ArrayBuffer


object 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
   */
  @throws[Exception]
  def updateSharePermissions(moduleAPIName: String, recordId: Long): Unit = {
    val shareRecordsOperations = new ShareRecordsOperations(recordId,moduleAPIName)
    val request = new BodyWrapper
    val shareList = new ArrayBuffer[ShareRecord]
    val share1 = new ShareRecord
    share1.setShareRelatedRecords(Option(true))
    share1.setPermission(Option("full_access"))
    val user = new User
    user.setId(Option(3477061000005791024l))
    share1.setUser(Option(user))
    shareList.addOne(share1)
    request.setShare(shareList)
    //Call updateSharePermissions method that takes BodyWrapper instance as parameter
    val responseOption = shareRecordsOperations.updateSharePermissions(request)
    if (responseOption.isDefined) { //check response
      var response= responseOption.get
      println("Status Code: " + response.getStatusCode)
      if (response.isExpected) {
        val actionHandler = response.getObject
        if (actionHandler.isInstanceOf[ActionWrapper]) {
          val actionWrapper = actionHandler.asInstanceOf[ActionWrapper]
          val actionResponses = actionWrapper.getShare

          for (actionResponse {
                println(entry._1 + ": " + entry._2)
              })
              println("Message: " + successResponse.getMessage.getValue)
            }
            else if (actionResponse.isInstanceOf[APIException]) {
              val exception = actionResponse.asInstanceOf[APIException]
              println("Status: " + exception.getStatus.getValue)
              println("Code: " + exception.getCode.getValue)
              println("Details: ")
              exception.getDetails.foreach(entry=>{
                println(entry._1 + ": " + entry._2)
              })
              println("Message: " + exception.getMessage.getValue)
            }
          }
        }
        else if (actionHandler.isInstanceOf[APIException]) {
          val exception = actionHandler.asInstanceOf[APIException]
          println("Status: " + exception.getStatus.getValue)
          println("Code: " + exception.getCode.getValue)
          println("Details: ")
          exception.getDetails.foreach(entry=>{
            println(entry._1 + ": " + entry._2)
          })
          println("Message: " + exception.getMessage.getValue)
        }
      }
      else {
        val responseObject = response.getModel
        val clas = responseObject.getClass
        val fields = clas.getDeclaredFields
        for (field 
Revoke Access to a Shared Record
              
              
package com.zoho.crm.sample.sharerecords

import java.util

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

import scala.collection.mutable.ArrayBuffer


object 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
   */
  @throws[Exception]
  def revokeSharedRecord(moduleAPIName: String, recordId: Long): Unit = {
    val shareRecordsOperations = new ShareRecordsOperations(recordId,moduleAPIName)
    //Call revokeSharedRecord method
    val responseOption = shareRecordsOperations.revokeSharedRecord
    if (responseOption.isDefined) { //check response
      var response= responseOption.get
      println("Status Code: " + response.getStatusCode)
      if (response.isExpected) {
        val deleteActionHandler = response.getObject
        if (deleteActionHandler.isInstanceOf[DeleteActionWrapper]) { //Get the received DeleteActionWrapper instance
          val deleteActionWrapper = deleteActionHandler.asInstanceOf[DeleteActionWrapper]
          //Get the received DeleteActionResponse instance
          val deleteActionResponse = deleteActionWrapper.getShare
          if (deleteActionResponse.isInstanceOf[SuccessResponse]) {
            val successResponse = deleteActionResponse.asInstanceOf[SuccessResponse]
            println("Status: " + successResponse.getStatus.getValue)
            println("Code: " + successResponse.getCode.getValue)
            println("Details: ")
            successResponse.getDetails.foreach(entry=>{
              println(entry._1 + ": " + entry._2)
            })
            println("Message: " + successResponse.getMessage.getValue)
          }
          else if (deleteActionResponse.isInstanceOf[APIException]) {
            val exception = deleteActionResponse.asInstanceOf[APIException]
            println("Status: " + exception.getStatus.getValue)
            println("Code: " + exception.getCode.getValue)
            println("Details: ")
            exception.getDetails.foreach(entry=>{
              println(entry._1 + ": " + entry._2)
            })
            println("Message: " + exception.getMessage.getValue)
          }
        }
        else if (deleteActionHandler.isInstanceOf[APIException]) {
          val exception = deleteActionHandler.asInstanceOf[APIException]
          println("Status: " + exception.getStatus.getValue)
          println("Code: " + exception.getCode.getValue)
          println("Details: ")
          exception.getDetails.foreach(entry=>{
            println(entry._1 + ": " + entry._2)
          })
          println("Message: " + exception.getMessage.getValue)
        }
      }
      else {
        val responseObject = response.getModel
        val clas = responseObject.getClass
        val fields = clas.getDeclaredFields
        for (field