Scala SDK Samples - Custom View Operations
package com.zoho.crm.sample.customview
import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.customviews.APIException
import com.zoho.crm.api.customviews.Criteria
import com.zoho.crm.api.customviews.CustomViewsOperations
import com.zoho.crm.api.customviews.CustomViewsOperations.GetCustomViewsParam
import com.zoho.crm.api.customviews.Info
import com.zoho.crm.api.customviews.ResponseHandler
import com.zoho.crm.api.customviews.ResponseWrapper
import com.zoho.crm.api.customviews.SharedDetails
import com.zoho.crm.api.customviews.Translation
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
object CustomViews {
/**
* Get CustomViews
* This method is used to get the custom views data of a particular module.
* Specify the module name in your API request whose custom view data you want to retrieve.
*
* @param moduleAPIName - Specify the API name of the required module.
* @throws Exception
*/
@throws[Exception]
def getCustomViews(moduleAPIName: String): Unit = { //example
//String moduleAPIName = "Leads"
//Get instance of CustomViewOperations Class that takes moduleAPIName as parameter
val customViewsOperations = new CustomViewsOperations(Option(moduleAPIName))
//Call getCustomViews method
val paramInstance = new ParameterMap
paramInstance.add(new GetCustomViewsParam().page,1)
val responseOption = customViewsOperations.getCustomViews(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 list of obtained CustomView instances
val customViews = responseWrapper.getCustomViews
for (customView {
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.customview
import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.customviews.APIException
import com.zoho.crm.api.customviews.Criteria
import com.zoho.crm.api.customviews.CustomViewsOperations
import com.zoho.crm.api.customviews.CustomViewsOperations.GetCustomViewsParam
import com.zoho.crm.api.customviews.Info
import com.zoho.crm.api.customviews.ResponseHandler
import com.zoho.crm.api.customviews.ResponseWrapper
import com.zoho.crm.api.customviews.SharedDetails
import com.zoho.crm.api.customviews.Translation
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
object CustomViews {
/**
* This method is used to get the data of any specific custom view of the module.
* Specify the custom view ID of the module in your API request whose custom view data you want to retrieve.
*
* @param moduleAPIName - Specify the API name of the required module.
* @param customViewId - ID of the CustomView to be obtained.
* @throws Exception
*/
@throws[Exception]
def getCustomView(moduleAPIName: String, customViewId: Long): Unit = { //Long customViewId = 34770605629003
val customViewsOperations = new CustomViewsOperations(Option(moduleAPIName))
//Call getCustomView method that takes customViewId as parameter
val responseOption = customViewsOperations.getCustomView(customViewId)
if (responseOption.isDefined) {
val 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
}
if (response.isExpected) {
val responseHandler = response.getObject
if (responseHandler.isInstanceOf[ResponseWrapper]) {
val responseWrapper = responseHandler.asInstanceOf[ResponseWrapper]
val customViews = responseWrapper.getCustomViews
for (customView {
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