Scala SDK Samples - Tags Operations

Get Tags
              
              
package com.zoho.crm.sample.tags

import java.util

import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.tags.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, ConflictWrapper, CountHandler, CountWrapper, Info, MergeWrapper, RecordActionHandler, RecordActionResponse, RecordActionWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, Tag, TagsOperations}
import com.zoho.crm.api.tags.TagsOperations.CreateTagsParam
import com.zoho.crm.api.tags.TagsOperations.GetRecordCountForTagParam
import com.zoho.crm.api.tags.TagsOperations.GetTagsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromRecordParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToRecordParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer

object Tags {
	/**
   *  Get Tags 
   * This method is used to get all the tags in a module.
   *
   * @param moduleAPIName - The API Name of the module to get tags.
   * @throws Exception
   */
  @throws[Exception]
  def getTags(moduleAPIName: String): Unit = { //example
    //String moduleAPIName = "Leads"
    //Get instance of TagsOperations Class
    val tagsOperations = new TagsOperations
    //Get instance of ParameterMap Class
    val paramInstance = new ParameterMap
    paramInstance.add(new GetTagsParam().module, moduleAPIName)
    //paramInstance.add(GetTagsParam.MY_TAGS, "") //Displays the names of the tags created by the current user.
    //Call getTags method that takes paramInstance as parameter
    val responseOption = tagsOperations.getTags(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 tags = responseWrapper.getTags

          for (tag { //Get each value in the map
              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 
Create Tags
              
              
package com.zoho.crm.sample.tags

import java.util

import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.tags.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, ConflictWrapper, CountHandler, CountWrapper, Info, MergeWrapper, RecordActionHandler, RecordActionResponse, RecordActionWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, Tag, TagsOperations}
import com.zoho.crm.api.tags.TagsOperations.CreateTagsParam
import com.zoho.crm.api.tags.TagsOperations.GetRecordCountForTagParam
import com.zoho.crm.api.tags.TagsOperations.GetTagsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromRecordParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToRecordParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer


object Tags {
	/**
   *  Create Tags 
   * This method is used to create new tags and print the response.
   *
   * @param moduleAPIName - The API Name of the module to create tags.
   * @throws Exception
   */
  @throws[Exception]
  def createTags(moduleAPIName: String): Unit = {
    val tagsOperations = new TagsOperations
    //Get instance of BodyWrapper Class that will contain the request body
    val request = new BodyWrapper
    val paramInstance = new ParameterMap
    paramInstance.add(new CreateTagsParam().module, moduleAPIName)
    //List of Tag instances
    val tagList = new ArrayBuffer[Tag]
    //Get instance of Tag Class
    val tag1 = new Tag
    tag1.setName(Option("tagName"))
    tagList.addOne(tag1)
    request.setTags(tagList)
    //Call createTags method that takes BodyWrapper instance and paramInstance as parameter
    val responseOption = tagsOperations.createTags(request, Option(paramInstance))
    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]) { //Get the received ActionWrapper instance
          val actionWrapper = actionHandler.asInstanceOf[ActionWrapper]
          //Get the list of obtained ActionResponse instances
          val actionResponses = actionWrapper.getTags

          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 
Update Tags
              
              
package com.zoho.crm.sample.tags

import java.util

import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.tags.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, ConflictWrapper, CountHandler, CountWrapper, Info, MergeWrapper, RecordActionHandler, RecordActionResponse, RecordActionWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, Tag, TagsOperations}
import com.zoho.crm.api.tags.TagsOperations.CreateTagsParam
import com.zoho.crm.api.tags.TagsOperations.GetRecordCountForTagParam
import com.zoho.crm.api.tags.TagsOperations.GetTagsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromRecordParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToRecordParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer


object Tags {
	/**
   *  Update Tags 
   * This method is used to update multiple tags simultaneously and print the response.
   *
   * @param moduleAPIName - The API Name of the module to update tags.
   * @throws Exception
   */
  @throws[Exception]
  def updateTags(moduleAPIName: String): Unit = {
    val tagsOperations = new TagsOperations
    val request = new BodyWrapper
    val paramInstance = new ParameterMap
    paramInstance.add(new UpdateTagsParam().module, moduleAPIName)
    val tagList = new ArrayBuffer[Tag]
    val tag1 = new Tag
    tag1.setId(Option(3524033700023l))
    tag1.setName(Option("tagName123"))
    tagList.addOne(tag1)
    request.setTags(tagList)
    //Call updateTags method that takes BodyWrapper instance and paramInstance as parameter
    val responseOption = tagsOperations.updateTags(request, Option(paramInstance))
    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.getTags

          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 
Update Specific Tag
              
              
package com.zoho.crm.sample.tags

import java.util

import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.tags.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, ConflictWrapper, CountHandler, CountWrapper, Info, MergeWrapper, RecordActionHandler, RecordActionResponse, RecordActionWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, Tag, TagsOperations}
import com.zoho.crm.api.tags.TagsOperations.CreateTagsParam
import com.zoho.crm.api.tags.TagsOperations.GetRecordCountForTagParam
import com.zoho.crm.api.tags.TagsOperations.GetTagsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromRecordParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToRecordParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer


object Tags {
	/**
   *  Update Tag 
   * This method is used to update single tag and print the response.
   *
   * @param moduleAPIName - The API Name of the module to update tag.
   * @param tagId         - The ID of the tag to be obtained.
   * @throws Exception
   */
  @throws[Exception]
  def updateTag(moduleAPIName: String, tagId: Long): Unit = { //Long tagId = 3477061000005794039
    val tagsOperations = new TagsOperations
    val request = new BodyWrapper
    val paramInstance = new ParameterMap
    paramInstance.add(new UpdateTagParam().module, moduleAPIName)
    val tagList = new ArrayBuffer[Tag]
    val tag1 = new Tag
    tag1.setName(Option("tagName12345"))
    tagList.addOne(tag1)
    request.setTags(tagList)
    //Call updateTag method that takes BodyWrapper instance, paramInstance and tagId as parameter
    val responseOption = tagsOperations.updateTag(tagId,request, Option(paramInstance ))
    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.getTags

          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 
Delete a Tag
              
              
package com.zoho.crm.sample.tags

import java.util

import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.tags.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, ConflictWrapper, CountHandler, CountWrapper, Info, MergeWrapper, RecordActionHandler, RecordActionResponse, RecordActionWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, Tag, TagsOperations}
import com.zoho.crm.api.tags.TagsOperations.CreateTagsParam
import com.zoho.crm.api.tags.TagsOperations.GetRecordCountForTagParam
import com.zoho.crm.api.tags.TagsOperations.GetTagsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromRecordParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToRecordParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer


object Tags {
	/**
   *  Delete Tag 
   * This method is used to delete a tag from the module and print the response.
   *
   * @param tagId - The ID of the tag to be obtained.
   * @throws Exception
   */
  @throws[Exception]
  def deleteTag(tagId: Long): Unit = {
    val tagsOperations = new TagsOperations
    //Call deleteTag method that takes tag id as parameter
    val responseOption = tagsOperations.deleteTag(tagId)
    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.getTags

          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 
Merge Tags
              
              
package com.zoho.crm.sample.tags

import java.util

import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.tags.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, ConflictWrapper, CountHandler, CountWrapper, Info, MergeWrapper, RecordActionHandler, RecordActionResponse, RecordActionWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, Tag, TagsOperations}
import com.zoho.crm.api.tags.TagsOperations.CreateTagsParam
import com.zoho.crm.api.tags.TagsOperations.GetRecordCountForTagParam
import com.zoho.crm.api.tags.TagsOperations.GetTagsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromRecordParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToRecordParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer


object Tags {
	/**
   *  Merge Tag 
   * This method is used to merge tags and put all the records under the two tags into a single tag and print the response.
   *
   * @param tagId      - The ID of the tag to be obtained.
   * @param conflictId - The ID of the conflict tag to be obtained.
   * @throws Exception
   */
  @throws[Exception]
  def mergeTags(tagId: Long, conflictId: String): Unit = { //Long conflictId = 3477061000005803151
    val tagsOperations = new TagsOperations
    //Get instance of MergeWrapper Class that will contain the request body
    val request = new MergeWrapper
    //List of Tag ConflictWrapper
    val tags = new ArrayBuffer[ConflictWrapper]
    //Get instance of ConflictWrapper Class
    val mergeTag = new ConflictWrapper
    mergeTag.setConflictId(Option(conflictId))
    tags.addOne(mergeTag)
    request.setTags(tags)
    //Call mergeTags method that takes MergeWrapper instance and tag id as parameter
    val responseOption = tagsOperations.mergeTags(tagId,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.getTags

          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 
Add Tags to a Record
              
              
package com.zoho.crm.sample.tags

import java.util

import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.tags.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, ConflictWrapper, CountHandler, CountWrapper, Info, MergeWrapper, RecordActionHandler, RecordActionResponse, RecordActionWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, Tag, TagsOperations}
import com.zoho.crm.api.tags.TagsOperations.CreateTagsParam
import com.zoho.crm.api.tags.TagsOperations.GetRecordCountForTagParam
import com.zoho.crm.api.tags.TagsOperations.GetTagsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromRecordParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToRecordParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer


object Tags {
	/**
   *  Add Tags To Record 
   * This method is used to add tags to a specific record and print the response.
   *
   * @param moduleAPIName - The API Name of the module to add tag.
   * @param recordId      - The ID of the record to be obtained.
   * @param tagNames      - The names of the tags to be added.
   * @throws Exception
   */
  @throws[Exception]
  def addTagsToRecord(moduleAPIName: String, recordId: Long, tagNames: ArrayBuffer[String]): Unit = { //long recordId =  3477061000005623115L
    //ArrayList tagNames = new ArrayList(Arrays.asList("addtag1,addtag12"))
    val tagsOperations = new TagsOperations
    val paramInstance = new ParameterMap

    for (tagName {
                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 (recordActionHandler.isInstanceOf[APIException]) {
          val exception = recordActionHandler.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 
Remove Tags from a Record
              
              
package com.zoho.crm.sample.tags

import java.util

import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.tags.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, ConflictWrapper, CountHandler, CountWrapper, Info, MergeWrapper, RecordActionHandler, RecordActionResponse, RecordActionWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, Tag, TagsOperations}
import com.zoho.crm.api.tags.TagsOperations.CreateTagsParam
import com.zoho.crm.api.tags.TagsOperations.GetRecordCountForTagParam
import com.zoho.crm.api.tags.TagsOperations.GetTagsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromRecordParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToRecordParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer


object Tags {
	/**
   *  Remove Tags From Record 
   * This method is used to delete the tag associated with a specific record and print the response.
   *
   * @param moduleAPIName - The API Name of the module to remove tag.
   * @param recordId      - The ID of the record to be obtained.
   * @param tagNames      - The names of the tags to be remove.
   * @throws Exception
   */
  @throws[Exception]
  def removeTagsFromRecord(moduleAPIName: String, recordId: Long, tagNames: ArrayBuffer[String]): Unit = {
    val tagsOperations = new TagsOperations
    val paramInstance = new ParameterMap

    for (tagName {
                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 (recordActionHandler.isInstanceOf[APIException]) {
          val exception = recordActionHandler.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 
Add Tags to Multiple Records
              
              
package com.zoho.crm.sample.tags

import java.util

import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.tags.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, ConflictWrapper, CountHandler, CountWrapper, Info, MergeWrapper, RecordActionHandler, RecordActionResponse, RecordActionWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, Tag, TagsOperations}
import com.zoho.crm.api.tags.TagsOperations.CreateTagsParam
import com.zoho.crm.api.tags.TagsOperations.GetRecordCountForTagParam
import com.zoho.crm.api.tags.TagsOperations.GetTagsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromRecordParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToRecordParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer


object Tags {
	/**
   *  Add Tags To Multiple Records 
   * This method is used to add tags to multiple records simultaneously and print the response.
   *
   * @param moduleAPIName - The API Name of the module to add tags.
   * @param recordIds     - The ID of the record to be obtained.
   * @param tagNames      - The names of the tags to be add.
   * @throws Exception
   */
  @throws[Exception]
  def addTagsToMultipleRecords(moduleAPIName: String, recordIds: ArrayBuffer[Long], tagNames: ArrayBuffer[String]): Unit = { //ArrayList recordIds = new ArrayList(Arrays.asList(3477061000005623115l, 3477061000006114067l))
    val tagsOperations = new TagsOperations
    val paramInstance = new ParameterMap

    for (tagName {
                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)
            }
          }
          //Check if locked count is null
          if (recordActionWrapper.getLockedCount != null) println("Locked Count: " + recordActionWrapper.getLockedCount.toString)
          //Check if success count is null
          if (recordActionWrapper.getSuccessCount != null) println("Success Count: " + recordActionWrapper.getSuccessCount)
          //Check if wf scheduler is null
          if (recordActionWrapper.getWfScheduler != null) println("WF Scheduler: " + recordActionWrapper.getWfScheduler)
        }
        else if (recordActionHandler.isInstanceOf[APIException]) {
          val exception = recordActionHandler.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 
Remove Tags from Multiple Records
              
              
package com.zoho.crm.sample.tags

import java.util

import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.tags.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, ConflictWrapper, CountHandler, CountWrapper, Info, MergeWrapper, RecordActionHandler, RecordActionResponse, RecordActionWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, Tag, TagsOperations}
import com.zoho.crm.api.tags.TagsOperations.CreateTagsParam
import com.zoho.crm.api.tags.TagsOperations.GetRecordCountForTagParam
import com.zoho.crm.api.tags.TagsOperations.GetTagsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromRecordParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToRecordParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer


object Tags {
	/**
   *  Remove Tags From Multiple Records 
   * This method is used to delete the tags associated with multiple records and print the response.
   *
   * @param moduleAPIName - The API Name of the module to remove tags.
   * @param recordIds     - The ID of the record to be obtained.
   * @param tagNames      - The names of the tags to be remove.
   * @throws Exception
   */
  @throws[Exception]
  def removeTagsFromMultipleRecords(moduleAPIName: String, recordIds: ArrayBuffer[Long], tagNames: ArrayBuffer[String]): Unit = { //ArrayList recordIds = new ArrayList(Arrays.asList(3477061000005623115, 3477061000006114067))
    val tagsOperations = new TagsOperations
    val paramInstance = new ParameterMap

    for (tagName {
                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)
            }
          }
          if (recordActionWrapper.getLockedCount != null) println("Locked Count: " + recordActionWrapper.getLockedCount.toString)
          if (recordActionWrapper.getSuccessCount != null) println("Success Count: " + recordActionWrapper.getSuccessCount)
          if (recordActionWrapper.getWfScheduler != null) println("WF Scheduler: " + recordActionWrapper.getWfScheduler)
        }
        else if (recordActionHandler.isInstanceOf[APIException]) {
          val exception = recordActionHandler.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 
Get Record Count for a Tag
              
              
package com.zoho.crm.sample.tags

import java.util

import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.tags.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, ConflictWrapper, CountHandler, CountWrapper, Info, MergeWrapper, RecordActionHandler, RecordActionResponse, RecordActionWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, Tag, TagsOperations}
import com.zoho.crm.api.tags.TagsOperations.CreateTagsParam
import com.zoho.crm.api.tags.TagsOperations.GetRecordCountForTagParam
import com.zoho.crm.api.tags.TagsOperations.GetTagsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.RemoveTagsFromRecordParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagParam
import com.zoho.crm.api.tags.TagsOperations.UpdateTagsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToMultipleRecordsParam
import com.zoho.crm.api.tags.TagsOperations.AddTagsToRecordParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer


object Tags {
	/**
   *  Get Record Count For Tag 
   * This method is used to get the total number of records under a tag and print the response.
   *
   * @param moduleAPIName - The API Name of the module.
   * @param tagId         - The ID of the tag to be obtained.
   * @throws Exception
   */
  @throws[Exception]
  def getRecordCountForTag(moduleAPIName: String, tagId: Long): Unit = { //Long tagId = 34770615803151l
    val tagsOperations = new TagsOperations
    val paramInstance = new ParameterMap
    paramInstance.add(new GetRecordCountForTagParam().module, moduleAPIName)
    //Call getRecordCountForTag method that takes paramInstance and tagId as parameter
    val responseOption = tagsOperations.getRecordCountForTag( tagId,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
      }
      if (response.isExpected) {
        val countHandler = response.getObject
        if (countHandler.isInstanceOf[CountWrapper]) { //Get the received CountWrapper instance
          val countWrapper = countHandler.asInstanceOf[CountWrapper]
          //Get the Count of Tag
          println("Tag Count: " + countWrapper.getCount)
        }
        else if (countHandler.isInstanceOf[APIException]) {
          val exception = countHandler.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