Scala SDK Samples - Records Operations
package com.zoho.crm.sample.record
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.time.LocalDate
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.layouts.Layout
import com.zoho.crm.api.record.Field.{Contacts, Deals, Events, Leads, Price_Books, Tasks}
import com.zoho.crm.api.record.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Comment, Consent, ConvertActionHandler, ConvertActionResponse, ConvertActionWrapper, ConvertBodyWrapper, DeletedRecord, DeletedRecordsHandler, DeletedRecordsWrapper, DownloadHandler, Field, FileBodyWrapper, FileDetails, FileHandler, Info, InventoryLineItems, LeadConverter, LineItemProduct, LineTax, MassUpdate, MassUpdateActionHandler, MassUpdateActionResponse, MassUpdateActionWrapper, MassUpdateBodyWrapper, MassUpdateResponse, MassUpdateResponseHandler, MassUpdateResponseWrapper, MassUpdateSuccessResponse, Participants, PricingDetails, Record, RecordOperations, RecurringActivity, RemindAt, ResponseHandler, ResponseWrapper, SuccessResponse, SuccessfulConvert, Territory}
import com.zoho.crm.api.tags.Tag
import com.zoho.crm.api.record.RecordOperations.DeleteRecordParam
import com.zoho.crm.api.record.RecordOperations.DeleteRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetMassUpdateStatusParam
import com.zoho.crm.api.record.RecordOperations.GetRecordHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordParam
import com.zoho.crm.api.record.RecordOperations.GetRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordsParam
import com.zoho.crm.api.record.RecordOperations.SearchRecordsParam
import com.zoho.crm.api.users.User
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Choice
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.util.StreamWrapper
import scala.collection.mutable.ArrayBuffer
object Records {
/**
* Get Record
* This method is used to get a single record of a module with ID and print the response.
*
* @param moduleAPIName - The API Name of the record's module.
* @param recordId - The ID of the record to be obtained.
* @param destinationFolder - The absolute path of the destination folder to store the file.
* @throws Exception
*/
@throws[Exception]
def getRecord(moduleAPIName: String, recordId: Long, destinationFolder: String): Unit = { //example
// Get instance of RecordOperations Class
val recordOperations = new RecordOperations
//Get instance of ParameterMap Class
val paramInstance = new ParameterMap
//
paramInstance.add(new GetRecordParam().approved, "both")
paramInstance.add(new GetRecordParam().converted, "false")
var fieldNames = new ArrayBuffer[String]()
fieldNames += ("Company", "Email")
fieldNames.foreach(fieldName=>{
paramInstance.add(new GetRecordParam().fields, fieldName)
})
var startdatetime = OffsetDateTime.of(2020, 7, 2, 11, 0, 1, 0, ZoneOffset.of("+05:30"))
paramInstance.add(new GetRecordParam().startDateTime, startdatetime)
var enddatetime = OffsetDateTime.of(2020, 8, 2, 12, 0, 1, 0, ZoneOffset.of("+05:30"))
paramInstance.add(new GetRecordParam().endDateTime, enddatetime)
paramInstance.add(new GetRecordParam().territoryId, "34770613051357")
paramInstance.add(new GetRecordParam().includeChild, "true")
val headerInstance = new HeaderMap
val ifmodifiedsince = OffsetDateTime.of(2019, 1, 2, 10, 0, 0, 0, ZoneOffset.of("+05:30"))
headerInstance.add(new GetRecordHeader().IfModifiedSince, ifmodifiedsince)
//Call getRecord method that takes paramInstance, moduleAPIName and recordID as parameter
val responseOption = recordOperations.getRecord(recordId,moduleAPIName)
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 Record instances
val records = responseWrapper.getData
for (record 0) {
for (tag {
val keyName = entry._1
var value = entry._2
if (value.isInstanceOf[Option[_]]) value = value.asInstanceOf[Option[_]].getOrElse(null)
if (value.isInstanceOf[ArrayBuffer[Any]]) {
val dataList = value.asInstanceOf[ArrayBuffer[Any]]
if (dataList.size > 0) if (dataList(0).isInstanceOf[FileDetails]) {
@SuppressWarnings(Array("unchecked")) val fileDetails = value.asInstanceOf[ArrayBuffer[FileDetails]]
for (fileDetail {
println(entry._1 + ": " + entry._2)
})
}
}
else if (dataList(0).isInstanceOf[LineTax]) {
@SuppressWarnings(Array("unchecked")) val lineTaxes = dataList.asInstanceOf[ ArrayBuffer[LineTax]]
for (lineTax {
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.record
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.time.LocalDate
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.layouts.Layout
import com.zoho.crm.api.record.Field.{Contacts, Deals, Events, Leads, Price_Books, Tasks}
import com.zoho.crm.api.record.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Comment, Consent, ConvertActionHandler, ConvertActionResponse, ConvertActionWrapper, ConvertBodyWrapper, DeletedRecord, DeletedRecordsHandler, DeletedRecordsWrapper, DownloadHandler, Field, FileBodyWrapper, FileDetails, FileHandler, Info, InventoryLineItems, LeadConverter, LineItemProduct, LineTax, MassUpdate, MassUpdateActionHandler, MassUpdateActionResponse, MassUpdateActionWrapper, MassUpdateBodyWrapper, MassUpdateResponse, MassUpdateResponseHandler, MassUpdateResponseWrapper, MassUpdateSuccessResponse, Participants, PricingDetails, Record, RecordOperations, RecurringActivity, RemindAt, ResponseHandler, ResponseWrapper, SuccessResponse, SuccessfulConvert, Territory}
import com.zoho.crm.api.tags.Tag
import com.zoho.crm.api.record.RecordOperations.DeleteRecordParam
import com.zoho.crm.api.record.RecordOperations.DeleteRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetMassUpdateStatusParam
import com.zoho.crm.api.record.RecordOperations.GetRecordHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordParam
import com.zoho.crm.api.record.RecordOperations.GetRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordsParam
import com.zoho.crm.api.record.RecordOperations.SearchRecordsParam
import com.zoho.crm.api.users.User
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Choice
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.util.StreamWrapper
import scala.collection.mutable.ArrayBuffer
object Records {
/**
* Delete Record
* This method is used to delete a single record of a module with ID and print the response.
*
* @param moduleAPIName - The API Name of the record's module.
* @param recordId - The ID of the record to be deleted.
* @throws Exception
*/
@throws[Exception]
def deleteRecord(moduleAPIName: String, recordId: Long): Unit = { //API Name of the module to delete record
val recordOperations = new RecordOperations
val paramInstance = new ParameterMap
paramInstance.add(new DeleteRecordParam().wfTrigger, "false")
//Call deleteRecord method that takes paramInstance, ModuleAPIName and recordId as parameter.
val responseOption = recordOperations.deleteRecord(recordId,moduleAPIName,Option(paramInstance))
if (responseOption.isDefined) {
val 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]
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: ")
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.record
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.time.LocalDate
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.layouts.Layout
import com.zoho.crm.api.record.Field.{Contacts, Deals, Events, Leads, Price_Books, Tasks}
import com.zoho.crm.api.record.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Comment, Consent, ConvertActionHandler, ConvertActionResponse, ConvertActionWrapper, ConvertBodyWrapper, DeletedRecord, DeletedRecordsHandler, DeletedRecordsWrapper, DownloadHandler, Field, FileBodyWrapper, FileDetails, FileHandler, Info, InventoryLineItems, LeadConverter, LineItemProduct, LineTax, MassUpdate, MassUpdateActionHandler, MassUpdateActionResponse, MassUpdateActionWrapper, MassUpdateBodyWrapper, MassUpdateResponse, MassUpdateResponseHandler, MassUpdateResponseWrapper, MassUpdateSuccessResponse, Participants, PricingDetails, Record, RecordOperations, RecurringActivity, RemindAt, ResponseHandler, ResponseWrapper, SuccessResponse, SuccessfulConvert, Territory}
import com.zoho.crm.api.tags.Tag
import com.zoho.crm.api.record.RecordOperations.DeleteRecordParam
import com.zoho.crm.api.record.RecordOperations.DeleteRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetMassUpdateStatusParam
import com.zoho.crm.api.record.RecordOperations.GetRecordHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordParam
import com.zoho.crm.api.record.RecordOperations.GetRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordsParam
import com.zoho.crm.api.record.RecordOperations.SearchRecordsParam
import com.zoho.crm.api.users.User
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Choice
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.util.StreamWrapper
import scala.collection.mutable.ArrayBuffer
object Records {
/**
* Get Records
* This method is used to get all the records of a module and print the response.
*
* @param moduleAPIName - The API Name of the module to obtain records.
* @throws Exception
*/
@throws[Exception]
def getRecords(moduleAPIName: String): Unit = {
val recordOperations = new RecordOperations
val paramInstance = new ParameterMap
paramInstance.add(new GetRecordsParam().approved, "both")
paramInstance.add(new GetRecordsParam().converted, "both")
// paramInstance.add(new GetRecordsParam().cvid, "3477060087501")
var ids = new ArrayBuffer[Long]()
ids += (3477061623115L, 34770614352001L)
ids.foreach(id=>{
paramInstance.add(new GetRecordsParam().ids,id)
})
// paramInstance.add(new GetRecordsParam().ids, 3524033071038l)
// paramInstance.add(new GetRecordsParam().uid, "34770610181008")
paramInstance.add(new GetRecordsParam().fields, "LastName")
paramInstance.add(new GetRecordsParam().sortBy, "Email")
paramInstance.add(new GetRecordsParam().sortOrder, "desc")
paramInstance.add(new GetRecordsParam().page, 1)
paramInstance.add(new GetRecordsParam().perPage, 1)
var startdatetime = OffsetDateTime.of(2019, 11, 20, 10, 0, 1, 0, ZoneOffset.of("+05:30"))
paramInstance.add(new GetRecordsParam().startDateTime, startdatetime)
var enddatetime = OffsetDateTime.of(2019, 12, 20, 10, 0, 1, 0, ZoneOffset.of("+05:30"))
paramInstance.add(new GetRecordsParam().endDateTime, enddatetime)
paramInstance.add(new GetRecordsParam().territoryId, "34770610051357")
paramInstance.add(new GetRecordsParam().includeChild, "true")
val headerInstance = new HeaderMap
val ifmodifiedsince = OffsetDateTime.of(2019, 5, 20, 10, 0, 1, 0, ZoneOffset.of("+05:30"))
headerInstance.add(new GetRecordsHeader().IfModifiedSince, ifmodifiedsince)
//Call getRecords method that takes paramInstance, headerInstance and moduleAPIName as parameter.
val responseOption = recordOperations.getRecords(moduleAPIName,Option(null),Option( null))
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) { //Get the object from response
val responseHandler = response.getObject
if (responseHandler.isInstanceOf[ResponseWrapper]) {
val responseWrapper = responseHandler.asInstanceOf[ResponseWrapper]
//Get the obtained Record instances
val records = responseWrapper.getData
for (record 0) {
for (tag {
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.record
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.time.LocalDate
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.layouts.Layout
import com.zoho.crm.api.record.Field.{Contacts, Deals, Events, Leads, Price_Books, Tasks}
import com.zoho.crm.api.record.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Comment, Consent, ConvertActionHandler, ConvertActionResponse, ConvertActionWrapper, ConvertBodyWrapper, DeletedRecord, DeletedRecordsHandler, DeletedRecordsWrapper, DownloadHandler, Field, FileBodyWrapper, FileDetails, FileHandler, Info, InventoryLineItems, LeadConverter, LineItemProduct, LineTax, MassUpdate, MassUpdateActionHandler, MassUpdateActionResponse, MassUpdateActionWrapper, MassUpdateBodyWrapper, MassUpdateResponse, MassUpdateResponseHandler, MassUpdateResponseWrapper, MassUpdateSuccessResponse, Participants, PricingDetails, Record, RecordOperations, RecurringActivity, RemindAt, ResponseHandler, ResponseWrapper, SuccessResponse, SuccessfulConvert, Territory}
import com.zoho.crm.api.tags.Tag
import com.zoho.crm.api.record.RecordOperations.DeleteRecordParam
import com.zoho.crm.api.record.RecordOperations.DeleteRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetMassUpdateStatusParam
import com.zoho.crm.api.record.RecordOperations.GetRecordHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordParam
import com.zoho.crm.api.record.RecordOperations.GetRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordsParam
import com.zoho.crm.api.record.RecordOperations.SearchRecordsParam
import com.zoho.crm.api.users.User
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Choice
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.util.StreamWrapper
import scala.collection.mutable.ArrayBuffer
object Records {
/**
* Create Records
* This method is used to create records of a module and print the response.
*
* @param moduleAPIName - The API Name of the module to create records.
* @throws Exception
*/
@throws[Exception]
def createRecords(moduleAPIName: String): Unit = { //API Name of the module to create records
val recordOperations = new RecordOperations
val bodyWrapper = new BodyWrapper
val records = new ArrayBuffer[Record]
val record1 = new Record
record1.addFieldValue( new Field.Leads().City, "City")
record1.addFieldValue(new Field.Leads().LastName, "Last Name")
record1.addFieldValue(new Field.Leads().FirstName, "First Name")
record1.addFieldValue(new Field.Leads().Company, "KKRNP")
// record1.addKeyValue("Date_1", LocalDate.of(2021, 1, 13))
// record1.addKeyValue("Subject", "AutomatedSDK")
// val fileDetails = new ArrayBuffer[FileDetails]
// val fileDetail1 = new FileDetails
// fileDetail1.setFileId(Option("ae9c7cefa418aec1d6a5cc2d7c2400dadca8ff55f620c65357da"))
// fileDetails.addOne(fileDetail1)
// val fileDetail2 = new FileDetails
// fileDetail2.setFileId(Option("ae9c7cefa418aec1d6a63e7321b5b4ca878a934519e6cdb2"))
// fileDetails.addOne(fileDetail2)
// val fileDetail3 = new FileDetails
// fileDetail3.setFileId(Option("ae9c7cefa418aec1d6a5cc780bfe0058133556f155795981f"))
// fileDetails.addOne(fileDetail3)
// record1.addKeyValue("File_Upload", fileDetails)
val subformList = new ArrayBuffer[Record]
val subform = new Record
// subform.addKeyValue("DOB", "sep")
// subform.addKeyValue("Name1", "test")
subformList.addOne(subform)
record1.addKeyValue("Subform_1", subformList)
// val dataConsent = new Consent
// dataConsent.setConsentRemarks(Option("Approved."))
// dataConsent.setConsentThrough(Option("Email"))
// dataConsent.setContactThroughEmail(Option(true))
// dataConsent.setContactThroughSocial(Option(false))
// record1.addKeyValue("Data_Processing_Basis_Details", dataConsent)
// /** Following methods are being used only by Activity modules */
// // Tasks
// record1.addFieldValue(new Tasks().Description, "Test Task")
// record1.addKeyValue("Currency", new Choice[String]("INR"))
// var remindAt1 = new RemindAt()
// remindAt1.setAlarm(Option("FREQ=NONE;ACTION=EMAILANDPOPUP;TRIGGER=DATE-TIME:2020-07-03T12:30:00+05:30"))
// var whoId = new com.zoho.crm.api.record.Record()
// whoId.setId(Option(3477061000004977055L))
// record1.addFieldValue(new Tasks().WhoId, whoId)
// record1.addFieldValue(new Tasks().Status, new Choice[String]("Waiting on someone else"))
// record1.addFieldValue(new Tasks().DueDate, LocalDate.of(2021, 1, 13))
// record1.addFieldValue(new Tasks().Priority, new Choice[String]("High"))
// record1.addFieldValue(new Tasks().Subject, "Email1")
// record1.addKeyValue("$se_module", "Accounts")
// var whatId = new com.zoho.crm.api.record.Record()
// whatId.setId(Option(3477061000000207118L))
// record1.addFieldValue(new Tasks().WhatId, whatId)
// /** Recurring Activity can be provided in any activity module */
// var recurringActivity = new RecurringActivity()
// recurringActivity.setRrule(Option("FREQ=DAILY;INTERVAL=10;UNTIL=2020-08-14;DTSTART=2020-07-03"))
// record1.addFieldValue(new Events().RecurringActivity, recurringActivity)
// // Events
// record1.addFieldValue(new Events().Description, "Test Events")
// var startDateTime = OffsetDateTime.of(2020, 1, 2, 10, 0, 0, 0, ZoneOffset.of("+05:30"))
// record1.addFieldValue(new Events().StartDateTime, startDateTime)
// var participants = new ArrayBuffer[Participants]()
// var participant1 = new Participants()
// participant1.setParticipant(Option("abc@gmail.com"))
// participant1.setType(Option("email"))
// participant1.setId(Option(3477061000005902017L))
// participants.addOne(participant1)
// var participant2 = new Participants()
// participant2.addKeyValue("participant", "34770617420005")
// participant2.addKeyValue("type", "lead")
// participants.addOne(participant2)
// record1.addFieldValue(new Events().Participants, participants)
// record1.addKeyValue("$send_notification", true)
// record1.addFieldValue(new Events().EventTitle, "New Automated Event")
// var enddatetime = OffsetDateTime.of(2020, 5, 2, 1, 0, 0, 0, ZoneOffset.of("+05:30"))
// record1.addFieldValue(new Events().EndDateTime, enddatetime)
// var remindAt2= OffsetDateTime.of(2020, 5, 2, 5, 0, 0, 0, ZoneOffset.of("+05:30"))
// record1.addFieldValue(new Events().RemindAt,remindAt2 )
// record1.addFieldValue(new Events().CheckInStatus, "PLANNED")
// record1.addKeyValue("$se_module", "Leads")
// whatId.setId(Option(3477061000004381002L))
// record1.addFieldValue(new Events().WhatId, whatId)
// record1.addKeyValue("Currency", new Choice[String]("USD"))
// /** End Activity **//** Following methods are being used only by Price_Books modules */
// var pricingDetails = new ArrayBuffer[PricingDetails]()
// var pricingDetail1 = new PricingDetails()
// pricingDetail1.setFromRange(Option(1.0))
// pricingDetail1.setToRange(Option(5.0))
// pricingDetail1.setDiscount(Option(2.0))
// pricingDetails.addOne(pricingDetail1)
// var pricingDetail2 = new PricingDetails()
// pricingDetail2.addKeyValue("from_range", 6.0)
// pricingDetail2.addKeyValue("to_range", 11.0)
// pricingDetail2.addKeyValue("discount", 3.0)
// pricingDetails.addOne(pricingDetail2)
// record1.addFieldValue(new Price_Books().PricingDetails, pricingDetails)
// record1.addKeyValue("Email", "abc.k124@zoho.com")
// record1.addFieldValue(new Price_Books().Description, "TEST")
// record1.addFieldValue(new Price_Books().PriceBookName, "book_name")
// record1.addFieldValue(new Price_Books().PricingModel, new Choice[String]("Flat"))
val tagList = new ArrayBuffer[Tag]
val tag = new Tag
tag.setName(Option("Testtask"))
tagList.addOne(tag)
record1.setTag(tagList)
records.addOne(record1)
bodyWrapper.setData(records)
val trigger = new ArrayBuffer[String]
trigger.addOne("approval")
trigger.addOne("workflow")
trigger.addOne("blueprint")
// bodyWrapper.setTrigger(trigger)
//bodyWrapper.setLarId("34770610515")
val headerInstance = new HeaderMap
//Call createRecords method that takes BodyWrapper instance as parameter.
val responseOption = recordOperations.createRecords(moduleAPIName,bodyWrapper, headerInstance)
if (responseOption.isDefined) {
val 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: ")
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 {
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.record
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.time.LocalDate
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.layouts.Layout
import com.zoho.crm.api.record.Field.{Contacts, Deals, Events, Leads, Price_Books, Tasks}
import com.zoho.crm.api.record.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Comment, Consent, ConvertActionHandler, ConvertActionResponse, ConvertActionWrapper, ConvertBodyWrapper, DeletedRecord, DeletedRecordsHandler, DeletedRecordsWrapper, DownloadHandler, Field, FileBodyWrapper, FileDetails, FileHandler, Info, InventoryLineItems, LeadConverter, LineItemProduct, LineTax, MassUpdate, MassUpdateActionHandler, MassUpdateActionResponse, MassUpdateActionWrapper, MassUpdateBodyWrapper, MassUpdateResponse, MassUpdateResponseHandler, MassUpdateResponseWrapper, MassUpdateSuccessResponse, Participants, PricingDetails, Record, RecordOperations, RecurringActivity, RemindAt, ResponseHandler, ResponseWrapper, SuccessResponse, SuccessfulConvert, Territory}
import com.zoho.crm.api.tags.Tag
import com.zoho.crm.api.record.RecordOperations.DeleteRecordParam
import com.zoho.crm.api.record.RecordOperations.DeleteRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetMassUpdateStatusParam
import com.zoho.crm.api.record.RecordOperations.GetRecordHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordParam
import com.zoho.crm.api.record.RecordOperations.GetRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordsParam
import com.zoho.crm.api.record.RecordOperations.SearchRecordsParam
import com.zoho.crm.api.users.User
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Choice
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.util.StreamWrapper
import scala.collection.mutable.ArrayBuffer
object Records {
/**
* Update Records
* This method is used to update the records of a module with ID and print the response.
*
* @param moduleAPIName - The API Name of the module to update records.
* @throws Exception
*/
@throws[Exception]
def updateRecords(moduleAPIName: String): Unit = {
val recordOperations = new RecordOperations
val request = new BodyWrapper
val records = new ArrayBuffer[Record]
val record1 = new Record
record1.setId(Option(34770615844006l))
record1.addFieldValue( new Field.Leads().City, "City")
record1.addFieldValue(new Field.Leads().LastName, "Last Name")
record1.addFieldValue(new Field.Leads().FirstName, "First Name")
record1.addFieldValue(new Field.Leads().Company, "KKRNP")
record1.addKeyValue("Custom_field", "Value")
record1.addKeyValue("Custom_field_2", "value")
val dataConsent = new Consent
dataConsent.setConsentRemarks(Option("Approved."))
dataConsent.setConsentThrough(Option("Email"))
dataConsent.setContactThroughEmail(Option(true))
dataConsent.setContactThroughSocial(Option(false))
record1.addKeyValue("Data_Processing_Basis_Details", dataConsent)
records.addOne(record1)
val record2 = new Record
record2.setId(Option(3477061844005l))
record2.addFieldValue( new Field.Leads().City, "City")
record2.addFieldValue(new Field.Leads().LastName, "Last Name")
record2.addFieldValue(new Field.Leads().FirstName, "First Name")
record2.addFieldValue(new Field.Leads().Company, "KKRNP")
record2.addKeyValue("Custom_field", "Value")
record2.addKeyValue("Custom_field_2", "value")
records.addOne(record2)
request.setData(records)
val trigger = new ArrayBuffer[String]
trigger.addOne("approval")
trigger.addOne("workflow")
trigger.addOne("blueprint")
request.setTrigger(trigger)
val headerInstance = new HeaderMap
//Call updateRecords method that takes BodyWrapper instance and moduleAPIName as parameter.
val responseOption = recordOperations.updateRecords(moduleAPIName,request, headerInstance)
if (responseOption.isDefined) {
val 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: ")
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.record
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.time.LocalDate
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.layouts.Layout
import com.zoho.crm.api.record.Field.{Contacts, Deals, Events, Leads, Price_Books, Tasks}
import com.zoho.crm.api.record.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Comment, Consent, ConvertActionHandler, ConvertActionResponse, ConvertActionWrapper, ConvertBodyWrapper, DeletedRecord, DeletedRecordsHandler, DeletedRecordsWrapper, DownloadHandler, Field, FileBodyWrapper, FileDetails, FileHandler, Info, InventoryLineItems, LeadConverter, LineItemProduct, LineTax, MassUpdate, MassUpdateActionHandler, MassUpdateActionResponse, MassUpdateActionWrapper, MassUpdateBodyWrapper, MassUpdateResponse, MassUpdateResponseHandler, MassUpdateResponseWrapper, MassUpdateSuccessResponse, Participants, PricingDetails, Record, RecordOperations, RecurringActivity, RemindAt, ResponseHandler, ResponseWrapper, SuccessResponse, SuccessfulConvert, Territory}
import com.zoho.crm.api.tags.Tag
import com.zoho.crm.api.record.RecordOperations.DeleteRecordParam
import com.zoho.crm.api.record.RecordOperations.DeleteRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetMassUpdateStatusParam
import com.zoho.crm.api.record.RecordOperations.GetRecordHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordParam
import com.zoho.crm.api.record.RecordOperations.GetRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordsParam
import com.zoho.crm.api.record.RecordOperations.SearchRecordsParam
import com.zoho.crm.api.users.User
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Choice
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.util.StreamWrapper
import scala.collection.mutable.ArrayBuffer
object Records {
/**
* Delete Records
* This method is used to delete records of a module and print the response.
*
* @param moduleAPIName - The API Name of the module to delete records.
* @param recordIds - The List of the record IDs to be deleted.
* @throws Exception
*/
@throws[Exception]
def deleteRecords(moduleAPIName: String, recordIds: ArrayBuffer[Long]): Unit = { //List recordIds = new ArrayList(Arrays.asList(3477061000005908033l,3477061000005908017l))
val recordOperations = new RecordOperations
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: ")
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.record
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.time.LocalDate
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.layouts.Layout
import com.zoho.crm.api.record.Field.{Contacts, Deals, Events, Leads, Price_Books, Tasks}
import com.zoho.crm.api.record.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Comment, Consent, ConvertActionHandler, ConvertActionResponse, ConvertActionWrapper, ConvertBodyWrapper, DeletedRecord, DeletedRecordsHandler, DeletedRecordsWrapper, DownloadHandler, Field, FileBodyWrapper, FileDetails, FileHandler, Info, InventoryLineItems, LeadConverter, LineItemProduct, LineTax, MassUpdate, MassUpdateActionHandler, MassUpdateActionResponse, MassUpdateActionWrapper, MassUpdateBodyWrapper, MassUpdateResponse, MassUpdateResponseHandler, MassUpdateResponseWrapper, MassUpdateSuccessResponse, Participants, PricingDetails, Record, RecordOperations, RecurringActivity, RemindAt, ResponseHandler, ResponseWrapper, SuccessResponse, SuccessfulConvert, Territory}
import com.zoho.crm.api.tags.Tag
import com.zoho.crm.api.record.RecordOperations.DeleteRecordParam
import com.zoho.crm.api.record.RecordOperations.DeleteRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetMassUpdateStatusParam
import com.zoho.crm.api.record.RecordOperations.GetRecordHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordParam
import com.zoho.crm.api.record.RecordOperations.GetRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordsParam
import com.zoho.crm.api.record.RecordOperations.SearchRecordsParam
import com.zoho.crm.api.users.User
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Choice
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.util.StreamWrapper
import scala.collection.mutable.ArrayBuffer
object Records {
/**
* Upsert Records
* This method is used to Upsert records of a module and print the response.
*
* @param moduleAPIName - The API Name of the module to upsert records.
* @throws Exception
*/
@throws[Exception]
def upsertRecords(moduleAPIName: String): Unit = {
val recordOperations = new RecordOperations
val request = new BodyWrapper
val records = new ArrayBuffer[Record]
val record1 = new Record
record1.addFieldValue( new Field.Leads().City, "City")
record1.addFieldValue(new Field.Leads().LastName, "Last Name")
record1.addFieldValue(new Field.Leads().FirstName, "First Name")
record1.addFieldValue(new Field.Leads().Company, "KKRNP")
record1.addKeyValue("Custom_field", "Value")
record1.addKeyValue("Custom_field_2", "value")
records.addOne(record1)
val record2 = new Record
record2.addFieldValue( new Field.Leads().City, "City")
record2.addFieldValue(new Field.Leads().LastName, "Last Name")
record2.addFieldValue(new Field.Leads().FirstName, "First Name")
record2.addFieldValue(new Field.Leads().Company, "ABC")
record2.addKeyValue("Custom_field", "Value")
record2.addKeyValue("Custom_field_2", "value")
records.addOne(record2)
val duplicateCheckFields = new ArrayBuffer[String]
duplicateCheckFields+= ("City", "First_Name")
request.setDuplicateCheckFields(duplicateCheckFields)
request.setData(records)
val headerInstance = new HeaderMap
//Call upsertRecords method that takes BodyWrapper instance and moduleAPIName as parameter.
val responseOption = recordOperations.upsertRecords(moduleAPIName,request,headerInstance)
if (responseOption.isDefined) {
val 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: ")
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.record
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.time.LocalDate
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.layouts.Layout
import com.zoho.crm.api.record.Field.{Contacts, Deals, Events, Leads, Price_Books, Tasks}
import com.zoho.crm.api.record.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Comment, Consent, ConvertActionHandler, ConvertActionResponse, ConvertActionWrapper, ConvertBodyWrapper, DeletedRecord, DeletedRecordsHandler, DeletedRecordsWrapper, DownloadHandler, Field, FileBodyWrapper, FileDetails, FileHandler, Info, InventoryLineItems, LeadConverter, LineItemProduct, LineTax, MassUpdate, MassUpdateActionHandler, MassUpdateActionResponse, MassUpdateActionWrapper, MassUpdateBodyWrapper, MassUpdateResponse, MassUpdateResponseHandler, MassUpdateResponseWrapper, MassUpdateSuccessResponse, Participants, PricingDetails, Record, RecordOperations, RecurringActivity, RemindAt, ResponseHandler, ResponseWrapper, SuccessResponse, SuccessfulConvert, Territory}
import com.zoho.crm.api.tags.Tag
import com.zoho.crm.api.record.RecordOperations.DeleteRecordParam
import com.zoho.crm.api.record.RecordOperations.DeleteRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetMassUpdateStatusParam
import com.zoho.crm.api.record.RecordOperations.GetRecordHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordParam
import com.zoho.crm.api.record.RecordOperations.GetRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordsParam
import com.zoho.crm.api.record.RecordOperations.SearchRecordsParam
import com.zoho.crm.api.users.User
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Choice
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.util.StreamWrapper
import scala.collection.mutable.ArrayBuffer
object Records {
/**
* Get Deleted Records
* This method is used to get the deleted records of a module and print the response.
*
* @param moduleAPIName - The API Name of the module to get the deleted records.
* @throws Exception
*/
@throws[Exception]
def getDeletedRecords(moduleAPIName: String): Unit = {
val recordOperations = new RecordOperations
val paramInstance = new ParameterMap
paramInstance.add(new GetDeletedRecordsParam().type1, "permanent") //all, recycle, permanent
paramInstance.add(new GetDeletedRecordsParam().page, 1)
paramInstance.add(new GetDeletedRecordsParam().perPage, 2)
//Get instance of HeaderMap Class
val headerInstance = new HeaderMap
val ifModifiedSince = OffsetDateTime.of(2020, 5, 2, 12, 0, 30, 0, ZoneOffset.of("+05:30"))
headerInstance.add(new GetDeletedRecordsHeader().IfModifiedSince, ifModifiedSince)
// Call getDeletedRecords method that takes paramInstance, headerInstance and moduleAPIName as parameter
val responseOption = recordOperations.getDeletedRecords(moduleAPIName,Option(paramInstance), Option(headerInstance))
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 deletedRecordsHandler = response.getObject
if (deletedRecordsHandler.isInstanceOf[DeletedRecordsWrapper]) { //Get the received DeletedRecordsWrapper instance
val deletedRecordsWrapper = deletedRecordsHandler.asInstanceOf[DeletedRecordsWrapper]
//Get the list of obtained DeletedRecord instances
val deletedRecords = deletedRecordsWrapper.getData
for (deletedRecord {
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.record
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.time.LocalDate
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.layouts.Layout
import com.zoho.crm.api.record.Field.{Contacts, Deals, Events, Leads, Price_Books, Tasks}
import com.zoho.crm.api.record.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Comment, Consent, ConvertActionHandler, ConvertActionResponse, ConvertActionWrapper, ConvertBodyWrapper, DeletedRecord, DeletedRecordsHandler, DeletedRecordsWrapper, DownloadHandler, Field, FileBodyWrapper, FileDetails, FileHandler, Info, InventoryLineItems, LeadConverter, LineItemProduct, LineTax, MassUpdate, MassUpdateActionHandler, MassUpdateActionResponse, MassUpdateActionWrapper, MassUpdateBodyWrapper, MassUpdateResponse, MassUpdateResponseHandler, MassUpdateResponseWrapper, MassUpdateSuccessResponse, Participants, PricingDetails, Record, RecordOperations, RecurringActivity, RemindAt, ResponseHandler, ResponseWrapper, SuccessResponse, SuccessfulConvert, Territory}
import com.zoho.crm.api.tags.Tag
import com.zoho.crm.api.record.RecordOperations.DeleteRecordParam
import com.zoho.crm.api.record.RecordOperations.DeleteRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetMassUpdateStatusParam
import com.zoho.crm.api.record.RecordOperations.GetRecordHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordParam
import com.zoho.crm.api.record.RecordOperations.GetRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordsParam
import com.zoho.crm.api.record.RecordOperations.SearchRecordsParam
import com.zoho.crm.api.users.User
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Choice
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.util.StreamWrapper
import scala.collection.mutable.ArrayBuffer
object Records {
/**
* Search Records
* This method is used to search records of a module and print the response.
*
* @param moduleAPIName - The API Name of the module to obtain records.
* @throws Exception
*/
@throws[Exception]
def searchRecords(moduleAPIName: String): Unit = {
val recordOperations = new RecordOperations
val paramInstance = new ParameterMap
paramInstance.add(new SearchRecordsParam().criteria, "(Last_Name:starts_with:a)")
paramInstance.add(new SearchRecordsParam().email, "abc@gmail.com")
paramInstance.add(new SearchRecordsParam().phone, "1234567890")
paramInstance.add(new SearchRecordsParam().word, "First Name Last Name")
paramInstance.add(new SearchRecordsParam().converted, "both")
paramInstance.add(new SearchRecordsParam().approved, "both")
paramInstance.add(new SearchRecordsParam().page, 1)
paramInstance.add(new SearchRecordsParam().perPage, 2)
val headerInstance = new HeaderMap
//Call searchRecords method that takes ParameterMap Instance and moduleAPIName as parameter
val responseOption = recordOperations.searchRecords(moduleAPIName,Option(paramInstance ),headerInstance)
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]
//Get the obtained Record instance
val records = responseWrapper.getData
for (record 0) {
for (tag {
val keyName = entry._1
var value = entry._2
if (value.isInstanceOf[Option[_]]) value = value.asInstanceOf[Option[_]].getOrElse(null)
if (value.isInstanceOf[ArrayBuffer[Any]]) {
val dataList = value.asInstanceOf[ArrayBuffer[Any]]
if (dataList.size > 0) if (dataList(0).isInstanceOf[FileDetails]) {
@SuppressWarnings(Array("unchecked")) val fileDetails = value.asInstanceOf[ArrayBuffer[FileDetails]]
for (fileDetail {
println(entry._1 + ": " + entry._2)
})
}
}
else if (dataList(0).isInstanceOf[LineTax]) {
@SuppressWarnings(Array("unchecked")) val lineTaxes = dataList.asInstanceOf[ ArrayBuffer[LineTax]]
for (lineTax {
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.record
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.time.LocalDate
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.layouts.Layout
import com.zoho.crm.api.record.Field.{Contacts, Deals, Events, Leads, Price_Books, Tasks}
import com.zoho.crm.api.record.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Comment, Consent, ConvertActionHandler, ConvertActionResponse, ConvertActionWrapper, ConvertBodyWrapper, DeletedRecord, DeletedRecordsHandler, DeletedRecordsWrapper, DownloadHandler, Field, FileBodyWrapper, FileDetails, FileHandler, Info, InventoryLineItems, LeadConverter, LineItemProduct, LineTax, MassUpdate, MassUpdateActionHandler, MassUpdateActionResponse, MassUpdateActionWrapper, MassUpdateBodyWrapper, MassUpdateResponse, MassUpdateResponseHandler, MassUpdateResponseWrapper, MassUpdateSuccessResponse, Participants, PricingDetails, Record, RecordOperations, RecurringActivity, RemindAt, ResponseHandler, ResponseWrapper, SuccessResponse, SuccessfulConvert, Territory}
import com.zoho.crm.api.tags.Tag
import com.zoho.crm.api.record.RecordOperations.DeleteRecordParam
import com.zoho.crm.api.record.RecordOperations.DeleteRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetMassUpdateStatusParam
import com.zoho.crm.api.record.RecordOperations.GetRecordHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordParam
import com.zoho.crm.api.record.RecordOperations.GetRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordsParam
import com.zoho.crm.api.record.RecordOperations.SearchRecordsParam
import com.zoho.crm.api.users.User
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Choice
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.util.StreamWrapper
import scala.collection.mutable.ArrayBuffer
object Records {
/**
* Convert Lead
* This method is used to Convert Lead record and print the response.
*
* @param leadId - The ID of the Lead to be converted.
* @throws Exception
*/
@throws[Exception]
def convertLead(leadId: Long): Unit = { //long leadId = 34770616603276L
val recordOperations = new RecordOperations
//Get instance of ConvertBodyWrapper Class that will contain the request body
val request = new ConvertBodyWrapper
//List of LeadConverter instances
val data = new ArrayBuffer[LeadConverter]
//Get instance of LeadConverter Class
val record1 = new LeadConverter
record1.setOverwrite(Option(true))
record1.setNotifyLeadOwner(Option(true))
record1.setNotifyNewEntityOwner(Option(true))
record1.setAccounts(Option("3477061848125"))
record1.setContacts(Option("3477061358009"))
record1.setAssignTo(Option("3524033191017"))
val deals = new Record
deals.addFieldValue(new Field.Deals().DealName, "deal_name")
deals.addFieldValue(new Field.Deals().Description, "deals description")
deals.addFieldValue(new Field.Deals().ClosingDate, LocalDate.of(2021, 1, 13))
deals.addFieldValue(new Field.Deals().Stage, new Choice[String]("Closed Won"))
deals.addFieldValue(new Field.Deals().Amount, 50.7)
deals.addKeyValue("Custom_field", "Value")
deals.addKeyValue("Custom_field_2", "value")
record1.setDeals(Option(deals))
data.addOne(record1)
request.setData(data)
//Call convertLead method that takes ConvertBodyWrapper instance and leadId as parameter.
val responseOption = recordOperations.convertLead(leadId,request)
if (responseOption.isDefined) {
val response = responseOption.get
println("Status Code: " + response.getStatusCode)
if (response.isExpected) {
val convertActionHandler = response.getObject
if (convertActionHandler.isInstanceOf[ConvertActionWrapper]) { //Get the received ConvertActionWrapper instance
val convertActionWrapper = convertActionHandler.asInstanceOf[ConvertActionWrapper]
//Get the list of obtained ConvertActionResponse instances
val convertActionResponses = convertActionWrapper.getData
for (convertActionResponse {
println(entry._1 + ": " + entry._2)
})
println("Message: " + exception.getMessage.getValue)
}
}
}
else if (convertActionHandler.isInstanceOf[APIException]) {
val exception = convertActionHandler.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.record
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.time.LocalDate
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.layouts.Layout
import com.zoho.crm.api.record.Field.{Contacts, Deals, Events, Leads, Price_Books, Tasks}
import com.zoho.crm.api.record.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Comment, Consent, ConvertActionHandler, ConvertActionResponse, ConvertActionWrapper, ConvertBodyWrapper, DeletedRecord, DeletedRecordsHandler, DeletedRecordsWrapper, DownloadHandler, Field, FileBodyWrapper, FileDetails, FileHandler, Info, InventoryLineItems, LeadConverter, LineItemProduct, LineTax, MassUpdate, MassUpdateActionHandler, MassUpdateActionResponse, MassUpdateActionWrapper, MassUpdateBodyWrapper, MassUpdateResponse, MassUpdateResponseHandler, MassUpdateResponseWrapper, MassUpdateSuccessResponse, Participants, PricingDetails, Record, RecordOperations, RecurringActivity, RemindAt, ResponseHandler, ResponseWrapper, SuccessResponse, SuccessfulConvert, Territory}
import com.zoho.crm.api.tags.Tag
import com.zoho.crm.api.record.RecordOperations.DeleteRecordParam
import com.zoho.crm.api.record.RecordOperations.DeleteRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetMassUpdateStatusParam
import com.zoho.crm.api.record.RecordOperations.GetRecordHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordParam
import com.zoho.crm.api.record.RecordOperations.GetRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordsParam
import com.zoho.crm.api.record.RecordOperations.SearchRecordsParam
import com.zoho.crm.api.users.User
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Choice
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.util.StreamWrapper
import scala.collection.mutable.ArrayBuffer
object Records {
/**
* This method is used to download a photo associated with a module.
*
* @param moduleAPIName - The API Name of the record's module
* @param recordId - The ID of the record to be obtained.
* @param destinationFolder - The absolute path of the destination folder to store the photo.
* @throws Exception
*/
@throws[Exception]
def getPhoto(moduleAPIName: String, recordId: Long, destinationFolder: String): Unit = { //Long recordId = 3477061000005177002L
//String destinationFolder = "/Users/user_name/Desktop"
val recordOperations = new RecordOperations
//Call getPhoto method that takes moduleAPIName and recordId as parameters
val responseOption = recordOperations.getPhoto(recordId,moduleAPIName )
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 downloadHandler = response.getObject
if (downloadHandler.isInstanceOf[FileBodyWrapper]) {
val fileBodyWrapper = downloadHandler.asInstanceOf[FileBodyWrapper]
val streamWrapper = fileBodyWrapper.getFile.get
val file = new File(destinationFolder + File.separatorChar + streamWrapper.getName.get)
val is = streamWrapper.getStream.get
val os = new FileOutputStream(file)
val buffer = new Array[Byte](1024)
var bytesRead = 0
//read the InputStream till the end
while ( {
bytesRead = is.read(buffer)
bytesRead != -1
}) { //write data to OutputStream
os.write(buffer, 0, bytesRead)
}
is.close()
os.flush()
os.close()
}
else if (downloadHandler.isInstanceOf[APIException]) {
val exception = downloadHandler.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.record
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.time.LocalDate
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.layouts.Layout
import com.zoho.crm.api.record.Field.{Contacts, Deals, Events, Leads, Price_Books, Tasks}
import com.zoho.crm.api.record.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Comment, Consent, ConvertActionHandler, ConvertActionResponse, ConvertActionWrapper, ConvertBodyWrapper, DeletedRecord, DeletedRecordsHandler, DeletedRecordsWrapper, DownloadHandler, Field, FileBodyWrapper, FileDetails, FileHandler, Info, InventoryLineItems, LeadConverter, LineItemProduct, LineTax, MassUpdate, MassUpdateActionHandler, MassUpdateActionResponse, MassUpdateActionWrapper, MassUpdateBodyWrapper, MassUpdateResponse, MassUpdateResponseHandler, MassUpdateResponseWrapper, MassUpdateSuccessResponse, Participants, PricingDetails, Record, RecordOperations, RecurringActivity, RemindAt, ResponseHandler, ResponseWrapper, SuccessResponse, SuccessfulConvert, Territory}
import com.zoho.crm.api.tags.Tag
import com.zoho.crm.api.record.RecordOperations.DeleteRecordParam
import com.zoho.crm.api.record.RecordOperations.DeleteRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetMassUpdateStatusParam
import com.zoho.crm.api.record.RecordOperations.GetRecordHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordParam
import com.zoho.crm.api.record.RecordOperations.GetRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordsParam
import com.zoho.crm.api.record.RecordOperations.SearchRecordsParam
import com.zoho.crm.api.users.User
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Choice
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.util.StreamWrapper
import scala.collection.mutable.ArrayBuffer
object Records {
/**
* This method is used to attach a photo to a record. You must include the photo in the request with content type as multipart/form data.
*
* @param moduleAPIName - The API Name of the record's module
* @param recordId - The ID of the record to be obtained.
* @param absoluteFilePath - The absolute file path of the file to be uploads
* @throws Exception
*/
@throws[Exception]
def uploadPhoto(moduleAPIName: String, recordId: Long, absoluteFilePath: String): Unit = { //String absoluteFilePath = "/Users/use_name/Desktop/image.png"
val recordOperations = new RecordOperations
//Get instance of FileBodyWrapper class that will contain the request file
val fileBodyWrapper = new FileBodyWrapper
//Get instance of StreamWrapper class that takes absolute path of the file to be attached as parameter
val streamWrapper = new StreamWrapper(absoluteFilePath)
//Set file to the FileBodyWrapper instance
fileBodyWrapper.setFile(Option(streamWrapper))
//Call uploadPhoto method that takes FileBodyWrapper instance, moduleAPIName and recordId as parameter
val responseOption = recordOperations.uploadPhoto(recordId,moduleAPIName,fileBodyWrapper)
if (responseOption.isDefined) {
val response = responseOption.get
println("Status Code: " + response.getStatusCode)
if (response.isExpected) {
val fileHandler = response.getObject
if (fileHandler.isInstanceOf[SuccessResponse]) {
val successResponse = fileHandler.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 (fileHandler.isInstanceOf[APIException]) {
val exception = fileHandler.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.record
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.time.LocalDate
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.layouts.Layout
import com.zoho.crm.api.record.Field.{Contacts, Deals, Events, Leads, Price_Books, Tasks}
import com.zoho.crm.api.record.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Comment, Consent, ConvertActionHandler, ConvertActionResponse, ConvertActionWrapper, ConvertBodyWrapper, DeletedRecord, DeletedRecordsHandler, DeletedRecordsWrapper, DownloadHandler, Field, FileBodyWrapper, FileDetails, FileHandler, Info, InventoryLineItems, LeadConverter, LineItemProduct, LineTax, MassUpdate, MassUpdateActionHandler, MassUpdateActionResponse, MassUpdateActionWrapper, MassUpdateBodyWrapper, MassUpdateResponse, MassUpdateResponseHandler, MassUpdateResponseWrapper, MassUpdateSuccessResponse, Participants, PricingDetails, Record, RecordOperations, RecurringActivity, RemindAt, ResponseHandler, ResponseWrapper, SuccessResponse, SuccessfulConvert, Territory}
import com.zoho.crm.api.tags.Tag
import com.zoho.crm.api.record.RecordOperations.DeleteRecordParam
import com.zoho.crm.api.record.RecordOperations.DeleteRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetMassUpdateStatusParam
import com.zoho.crm.api.record.RecordOperations.GetRecordHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordParam
import com.zoho.crm.api.record.RecordOperations.GetRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordsParam
import com.zoho.crm.api.record.RecordOperations.SearchRecordsParam
import com.zoho.crm.api.users.User
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Choice
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.util.StreamWrapper
import scala.collection.mutable.ArrayBuffer
object Records {
/**
* This method is used to delete a photo from a record in a module.
*
* @param moduleAPIName - The API Name of the record's module
* @param recordId - The ID of the record to be obtained.
* @throws Exception
*/
@throws[Exception]
def deletePhoto(moduleAPIName: String, recordId: Long): Unit = {
val recordOperations = new RecordOperations
//Call deletePhoto method that takes moduleAPIName and recordId as parameter
val responseOption = recordOperations.deletePhoto(recordId,moduleAPIName )
if (responseOption.isDefined) {
val response = responseOption.get
println("Status Code: " + response.getStatusCode)
if (response.isExpected) {
val fileHandler = response.getObject
if (fileHandler.isInstanceOf[SuccessResponse]) {
val successResponse = fileHandler.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 (fileHandler.isInstanceOf[APIException]) {
val exception = fileHandler.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.record
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.time.LocalDate
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.layouts.Layout
import com.zoho.crm.api.record.Field.{Contacts, Deals, Events, Leads, Price_Books, Tasks}
import com.zoho.crm.api.record.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Comment, Consent, ConvertActionHandler, ConvertActionResponse, ConvertActionWrapper, ConvertBodyWrapper, DeletedRecord, DeletedRecordsHandler, DeletedRecordsWrapper, DownloadHandler, Field, FileBodyWrapper, FileDetails, FileHandler, Info, InventoryLineItems, LeadConverter, LineItemProduct, LineTax, MassUpdate, MassUpdateActionHandler, MassUpdateActionResponse, MassUpdateActionWrapper, MassUpdateBodyWrapper, MassUpdateResponse, MassUpdateResponseHandler, MassUpdateResponseWrapper, MassUpdateSuccessResponse, Participants, PricingDetails, Record, RecordOperations, RecurringActivity, RemindAt, ResponseHandler, ResponseWrapper, SuccessResponse, SuccessfulConvert, Territory}
import com.zoho.crm.api.tags.Tag
import com.zoho.crm.api.record.RecordOperations.DeleteRecordParam
import com.zoho.crm.api.record.RecordOperations.DeleteRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetMassUpdateStatusParam
import com.zoho.crm.api.record.RecordOperations.GetRecordHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordParam
import com.zoho.crm.api.record.RecordOperations.GetRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordsParam
import com.zoho.crm.api.record.RecordOperations.SearchRecordsParam
import com.zoho.crm.api.users.User
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Choice
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.util.StreamWrapper
import scala.collection.mutable.ArrayBuffer
object Records {
/**
* This method is used to update the values of specific fields for multiple records and print the response.
*
* @param moduleAPIName - The API Name of the module to obtain records.
* @throws Exception
*/
@throws[Exception]
def massUpdateRecords(moduleAPIName: String): Unit = { //API Name of the module to massUpdateRecords
val recordOperations = new RecordOperations
//Get instance of MassUpdateBodyWrapper Class that will contain the request body
val request = new MassUpdateBodyWrapper
val records = new ArrayBuffer[Record]
val record1 = new Record
record1.addKeyValue("City", "Value")
record1.addKeyValue("Company", "Value")
records.addOne(record1)
request.setData(records)
request.setCvid(Option("3524033087501"))
val ids = new ArrayBuffer[Long]
ids += (34770615922192l)
request.setIds(ids)
var territory = new Territory()
// territory.setId("")
territory.setIncludeChild(Option(true))
request.setTerritory(Option(territory))
request.setOverWrite(Option(true))
//Call massUpdateRecords method that takes BodyWrapper instance, ModuleAPIName as parameter.
val responseOption = recordOperations.massUpdateRecords(moduleAPIName,request )
if (responseOption.isDefined) {
val response = responseOption.get
println("Status Code: " + response.getStatusCode)
if (response.isExpected) {
val massUpdateActionHandler = response.getObject
if (massUpdateActionHandler.isInstanceOf[MassUpdateActionWrapper]) { //Get the received MassUpdateActionWrapper instance
val massUpdateActionWrapper = massUpdateActionHandler.asInstanceOf[MassUpdateActionWrapper]
//Get the list of obtained MassUpdateActionResponse instances
val massUpdateActionResponses = massUpdateActionWrapper.getData
for (massUpdateActionResponse {
println(entry._1 + ": " + entry._2)
})
println("Message: " + massUpdateSuccessResponse.getMessage.getValue)
}
else if (massUpdateActionResponse.isInstanceOf[APIException]) {
val exception = massUpdateActionResponse.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 (massUpdateActionHandler.isInstanceOf[APIException]) {
val exception = massUpdateActionHandler.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.record
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.time.LocalDate
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.layouts.Layout
import com.zoho.crm.api.record.Field.{Contacts, Deals, Events, Leads, Price_Books, Tasks}
import com.zoho.crm.api.record.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Comment, Consent, ConvertActionHandler, ConvertActionResponse, ConvertActionWrapper, ConvertBodyWrapper, DeletedRecord, DeletedRecordsHandler, DeletedRecordsWrapper, DownloadHandler, Field, FileBodyWrapper, FileDetails, FileHandler, Info, InventoryLineItems, LeadConverter, LineItemProduct, LineTax, MassUpdate, MassUpdateActionHandler, MassUpdateActionResponse, MassUpdateActionWrapper, MassUpdateBodyWrapper, MassUpdateResponse, MassUpdateResponseHandler, MassUpdateResponseWrapper, MassUpdateSuccessResponse, Participants, PricingDetails, Record, RecordOperations, RecurringActivity, RemindAt, ResponseHandler, ResponseWrapper, SuccessResponse, SuccessfulConvert, Territory}
import com.zoho.crm.api.tags.Tag
import com.zoho.crm.api.record.RecordOperations.DeleteRecordParam
import com.zoho.crm.api.record.RecordOperations.DeleteRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetDeletedRecordsParam
import com.zoho.crm.api.record.RecordOperations.GetMassUpdateStatusParam
import com.zoho.crm.api.record.RecordOperations.GetRecordHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordParam
import com.zoho.crm.api.record.RecordOperations.GetRecordsHeader
import com.zoho.crm.api.record.RecordOperations.GetRecordsParam
import com.zoho.crm.api.record.RecordOperations.SearchRecordsParam
import com.zoho.crm.api.users.User
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Choice
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.util.StreamWrapper
import scala.collection.mutable.ArrayBuffer
object Records {
/**
* This method is used to get the status of the mass update job scheduled previously and print the response.
*
* @param moduleAPIName - The API Name of the module to obtain records.
* @param jobId - The ID of the job from the response of Mass Update Records.
* @throws Exception
*/
@throws[Exception]
def getMassUpdateStatus(moduleAPIName: String, jobId: String): Unit = { //String jobId = "3477061000005177002"
val recordOperations = new RecordOperations
val paramInstance = new ParameterMap
paramInstance.add(new GetMassUpdateStatusParam().jobId, jobId)
//Call getMassUpdateStatus method that takes paramInstance, moduleAPIName as parameter
val responseOption = recordOperations.getMassUpdateStatus(moduleAPIName,Option(paramInstance))
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 massUpdateResponseHandler = response.getObject
if (massUpdateResponseHandler.isInstanceOf[MassUpdateResponseWrapper]) { //Get the received MassUpdateResponseWrapper instance
val massUpdateResponseWrapper = massUpdateResponseHandler.asInstanceOf[MassUpdateResponseWrapper]
//Get the list of obtained MassUpdateResponse instances
val massUpdateResponses = massUpdateResponseWrapper.getData
for (massUpdateResponse {
println(entry._1 + ": " + entry._2)
})
println("Message: " + exception.getMessage.getValue)
}
}
}
else if (massUpdateResponseHandler.isInstanceOf[APIException]) {
val exception = massUpdateResponseHandler.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