Scala SDK Samples - Notes Operations

Get Notes
              
              
package com.zoho.crm.sample.notes

import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util

import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.attachments.Attachment
import com.zoho.crm.api.notes.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Info, Note, NotesOperations, ResponseHandler, ResponseWrapper, SuccessResponse}
import com.zoho.crm.api.notes.NotesOperations.DeleteNotesParam
import com.zoho.crm.api.notes.NotesOperations.GetNotesHeader
import com.zoho.crm.api.notes.NotesOperations.GetNotesParam
import com.zoho.crm.api.record.Record
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer

object Notes {
	/**
   *  Get Notes 
   * This method is used to get the list of notes and print the response.
   *
   * @throws Exception
   */
  @throws[Exception]
  def getNotes(): Unit = { //Get instance of NotesOperations Class
    val notesOperations = new NotesOperations
    //Get instance of ParameterMap Class
    val paramInstance = new ParameterMap
    paramInstance.add(new GetNotesParam().page, 1)
    //paramInstance.add(GetNotesParam.PER_PAGE, 1)
    //Get instance of HeaderMap Class
    val headerInstance = new HeaderMap
    val startdatetime = OffsetDateTime.of(2019, 6, 1, 1, 0, 1, 0, ZoneOffset.of("+05:30"))
    headerInstance.add(new GetNotesHeader().IfModifiedSince, startdatetime)
    //Call getNotes method that takes paramInstance and headerInstance as parameters
    val responseOption = notesOperations.getNotes(Option(paramInstance), Option(headerInstance))
    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 Note instances
          val notes = responseWrapper.getData

          for (note {
                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 Notes
              
              
package com.zoho.crm.sample.notes

import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util

import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.attachments.Attachment
import com.zoho.crm.api.notes.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Info, Note, NotesOperations, ResponseHandler, ResponseWrapper, SuccessResponse}
import com.zoho.crm.api.notes.NotesOperations.DeleteNotesParam
import com.zoho.crm.api.notes.NotesOperations.GetNotesHeader
import com.zoho.crm.api.notes.NotesOperations.GetNotesParam
import com.zoho.crm.api.record.Record
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer

object Notes {
	/**
   *  Create Notes 
   * This method is used to add new notes and print the response.
   *
   * @throws Exception
   */
  @throws[Exception]
  def createNotes(): Unit = {
    val notesOperations = new NotesOperations
    //Get instance of BodyWrapper Class that will contain the request body
    val bodyWrapper = new BodyWrapper
    //List of Note instances
    val notes = new ArrayBuffer[Note]
    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: ")
              if (exception.getDetails != null) {
                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: ")
          if (exception.getDetails != null) {
            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 Notes
              
              
package com.zoho.crm.sample.notes

import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util

import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.attachments.Attachment
import com.zoho.crm.api.notes.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Info, Note, NotesOperations, ResponseHandler, ResponseWrapper, SuccessResponse}
import com.zoho.crm.api.notes.NotesOperations.DeleteNotesParam
import com.zoho.crm.api.notes.NotesOperations.GetNotesHeader
import com.zoho.crm.api.notes.NotesOperations.GetNotesParam
import com.zoho.crm.api.record.Record
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer


object Notes {
	/**
   *  Update Notes
   * This method is used to update an existing note and print the response.
   *
   * @throws Exception
   */
  @throws[Exception]
  def updateNotes(): Unit = {
    val notesOperations = new NotesOperations
    val bodyWrapper = new BodyWrapper
    val notes = new ArrayBuffer[Note]
    var note = new Note
    note.setId(Option(3524033000003390004l))
    note.setNoteTitle(Option("Contacted12"))
    note.setNoteContent(Option("Need to do further tracking12"))
    notes.addOne(note)
    note = new Note
    note.setId(Option(3477061000007376025l))
    note.setNoteTitle(Option("Contacted13"))
    note.setNoteContent(Option("Need to do further tracking13"))
    notes.addOne(note)
    bodyWrapper.setData(notes)
    //Call updateNotes method that takes BodyWrapper instance as parameter
    val responseOption = notesOperations.updateNotes(bodyWrapper)
    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.getData

          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: ")
              if (exception.getDetails != null) {
                if (exception.getDetails != null) {
                  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: ")
          if (exception.getDetails != null) {
            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 Notes
              
              
package com.zoho.crm.sample.notes

import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util

import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.attachments.Attachment
import com.zoho.crm.api.notes.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Info, Note, NotesOperations, ResponseHandler, ResponseWrapper, SuccessResponse}
import com.zoho.crm.api.notes.NotesOperations.DeleteNotesParam
import com.zoho.crm.api.notes.NotesOperations.GetNotesHeader
import com.zoho.crm.api.notes.NotesOperations.GetNotesParam
import com.zoho.crm.api.record.Record
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer


object Notes {
	/**
   * This method is used to delete notes in bulk and print the response.
   *
   * @param notesId - The List of Note IDs to be deleted
   * @throws Exception
   */
  @throws[Exception]
  def deleteNotes(notesId: ArrayBuffer[Long]): Unit = { //example
    //ArrayList notesId = new ArrayList(Arrays.asList(3477061000006153001l,3477061000006153002l))
    val notesOperations = new NotesOperations
    val paramInstance = new ParameterMap

    for (id {
                  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: ")
              if (exception.getDetails != null) {
                if (exception.getDetails != null) {
                  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: ")
          if (exception.getDetails != null) {
            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 a Note
              
              
package com.zoho.crm.sample.notes

import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util

import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.attachments.Attachment
import com.zoho.crm.api.notes.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Info, Note, NotesOperations, ResponseHandler, ResponseWrapper, SuccessResponse}
import com.zoho.crm.api.notes.NotesOperations.DeleteNotesParam
import com.zoho.crm.api.notes.NotesOperations.GetNotesHeader
import com.zoho.crm.api.notes.NotesOperations.GetNotesParam
import com.zoho.crm.api.record.Record
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer


object Notes {
	/**
   *  Get Note 
   * This method is used to get the note and print the response.
   *
   * @param noteId - The ID of the Note to be obtained
   * @throws Exception
   */
  @throws[Exception]
  def getNote(noteId: Long): Unit = { //example
    //Long noteId = 3477061000006153005l
    val notesOperations = new NotesOperations
    //Call getNote method that takes noteId as parameter
    val responseOption = notesOperations.getNote(noteId)
    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 responseHandler = response.getObject
        if (responseHandler.isInstanceOf[ResponseWrapper]) {
          val responseWrapper = responseHandler.asInstanceOf[ResponseWrapper]
          val notes = responseWrapper.getData

          for (note {
              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 a Note
              
              
package com.zoho.crm.sample.notes

import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util

import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.attachments.Attachment
import com.zoho.crm.api.notes.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Info, Note, NotesOperations, ResponseHandler, ResponseWrapper, SuccessResponse}
import com.zoho.crm.api.notes.NotesOperations.DeleteNotesParam
import com.zoho.crm.api.notes.NotesOperations.GetNotesHeader
import com.zoho.crm.api.notes.NotesOperations.GetNotesParam
import com.zoho.crm.api.record.Record
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer

object Notes {
	/**
   *  Update Note
   * This method is used to update an existing note and print the response.
   *
   * @param noteId - The ID of the Note to be obtained
   * @throws Exception
   */
  @throws[Exception]
  def updateNote(noteId: Long): Unit = {
    val notesOperations = new NotesOperations
    val bodyWrapper = new BodyWrapper
    val notes = new ArrayBuffer[Note]
    val note = new Note
    note.setNoteTitle(Option("Contacted12"))
    note.setNoteContent(Option("Need to do further tracking12"))
    val parentRecord = new Record
    parentRecord.setId(Option(3477061000007255001l))
    note.setParentId(Option(parentRecord))
    note.setseModule(Option("Contacts"))
    notes.addOne(note)
    bodyWrapper.setData(notes)
    //Call updateNote method that takes BodyWrapper instance and noteId as parameter
    val responseOption = notesOperations.updateNote(noteId,bodyWrapper)
    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.getData

          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: ")
              if (exception.getDetails != null) {
                if (exception.getDetails != null) {
                  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: ")
          if (exception.getDetails != null) {
            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 Note
              
              
package com.zoho.crm.sample.notes

import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util

import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.attachments.Attachment
import com.zoho.crm.api.notes.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Info, Note, NotesOperations, ResponseHandler, ResponseWrapper, SuccessResponse}
import com.zoho.crm.api.notes.NotesOperations.DeleteNotesParam
import com.zoho.crm.api.notes.NotesOperations.GetNotesHeader
import com.zoho.crm.api.notes.NotesOperations.GetNotesParam
import com.zoho.crm.api.record.Record
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer


object Notes {
	/**
   *  Delete Note 
   * This method is used to delete single Note with ID and print the response.
   *
   * @param noteID - The ID of the Note to be deleted
   * @throws Exception
   */
  @throws[Exception]
  def deleteNote(noteID: Long): Unit = {
    val notesOperations = new NotesOperations
    //Call deleteNote method that takes noteID as parameter
    val responseOption = notesOperations.deleteNote(noteID)
    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.getData

          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: ")
              if (exception.getDetails != null) {
                if (exception.getDetails != null) {
                  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: ")
          if (exception.getDetails != null) {
            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