Scala SDK Samples - Profile Operations
Get All Profiles
package com.zoho.crm.sample.profiles
import java.util
import com.zoho.crm.api.profiles.APIException
import com.zoho.crm.api.profiles.Category
import com.zoho.crm.api.profiles.PermissionDetail
import com.zoho.crm.api.profiles.ProfilesOperations
import com.zoho.crm.api.profiles.ResponseHandler
import com.zoho.crm.api.profiles.ResponseWrapper
import com.zoho.crm.api.profiles.Section
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
object Profiles {
/**
* Get Profiles
* This method is used to retrieve the data of profiles through an API request and print the response.
*
* @throws Exception
*/
@throws[Exception]
def getProfiles(): Unit = { //Get instance of ProfilesOperations Class
val profilesOperations = new ProfilesOperations
//Call getProfiles method
val responseOption = profilesOperations.getProfiles
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 Profile instances
val profiles = responseWrapper.getProfiles
for (profile <- profiles) { //Get the DisplayLabel of the each Profile
println("Profile DisplayLabel: " + profile.getDisplayLabel)
if (profile.getCreatedTime != null) { //Get the CreatedTime of each Profile
println("Profile CreatedTime: " + profile.getCreatedTime)
}
if (profile.getModifiedTime != null) { //Get the ModifiedTime of each Profile
println("Profile ModifiedTime: " + profile.getModifiedTime)
}
//Get the Name of the each Profile
println("Profile Name: " + profile.getName)
//Get the modifiedBy User instance of each Profile
val modifiedByOption = profile.getModifiedBy()
if (modifiedByOption.isDefined) {
val modifiedBy = modifiedByOption.get
println("Profile Modified By User-ID: " + modifiedBy.getId)
//Get the name of the modifiedBy User
println("Profile Modified By User-Name: " + modifiedBy.getName)
//Get the Email of the modifiedBy User
println("Profile Modified By User-Email: " + modifiedBy.getEmail)
}
//Get the Description of the each Profile
println("Profile Description: " + profile.getDescription)
//Get the ID of the each Profile
println("Profile ID: " + profile.getId)
//Get the Category of the each Profile
println("Profile Category: " + profile.getCategory.toString)
//Get the createdBy User instance of each Profile
val createdByOption = profile.getCreatedBy
if (createdByOption.isDefined) {
val createdBy = createdByOption.get
println("Profile Created By User-ID: " + createdBy.getId)
//Get the name of the createdBy User
println("Profile Created By User-Name: " + createdBy.getName)
//Get the Email of the createdBy User
println("Profile Created By User-Email: " + createdBy.getEmail)
}
}
}
else { //Check if the request returned an exception
if (responseHandler.isInstanceOf[APIException]) { //Get the received APIException instance
val exception = responseHandler.asInstanceOf[APIException]
//Get the Status
println("Status: " + exception.getStatus.getValue)
//Get the Code
println("Code: " + exception.getCode.getValue)
println("Details: ")
//Get the details map
exception.getDetails.foreach(entry=>{
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 <- fields) { //Get each value
println(field.getName + ":" + field.get(responseObject))
}
}
}
}
}
Get Specific Profile