Scala SDK Samples - Share Records Operations
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 = 3477065177002L
//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, 3477060173021l)
//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
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
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