Skip to product menu
close
  • Recent Launches
    Press Space or Enter to display list of options
EXPLORE ALL PRODUCTS

Recent Launches

New

Payroll software with automated tax payments and filing.

Try now
New

Robotic process automation software to automate high-volume, rule-based tasks.

Try for free
New

Low-code IoT platform and solutions for connected businesses.

Try now
New

Business formation service to launch and grow your businesses.

Try now
New

Privacy-friendly application analytics solution.

Try for free

Sales

 
CRM

Comprehensive CRM platform for customer-facing teams.

CRM
 
Bigin

Simple CRM for small businesses moving from spreadsheets.

Bigin
 
Forms

Build online forms for every business need.

Forms
 
SalesIQ

Live chat app to engage and convert website visitors.

SalesIQ
 
Bookings

Appointment scheduling app for consultations with customers.

Bookings
 
Sign

Digital signature app for businesses.

Sign
 
RouteIQ

Comprehensive sales map visualization and optimal route planning solution.

RouteIQ
 
Thrive

Complete loyalty and affiliate management platform.

Thrive
 
Voice

Cloud Contact Center Software for businesses.

Voice
 
Suites
CRM Plus

Unified platform to deliver top-notch customer experience.

CRM Plus

Marketing

 
Social

All-in-one social media management software.

Social
 
Campaigns

Create, send, and track targeted email campaigns that drive sales.

Campaigns
 
Forms

Build online forms for every business need.

Forms
 
Survey

Design surveys to reach and interact with your audience.

Survey
 
Sites

Online website builder with extensive customisation options.

Sites
 
PageSense

Website conversion optimization and personalisation platform.

PageSense
 
Backstage

End-to-end event management software.

Backstage
 
Webinar

Webinar platform for webcasting online webinars.

Webinar
 
Marketing Automation

All-in-one marketing automation software.

Marketing Automation
 
LandingPage

Smart landing page builder to increase conversion rates

LandingPage
 
Publish

Manage all your local business listings on a single platform.

Publish
 
SalesIQ

Live chat app to engage and convert website visitors.

SalesIQ
 
Sign

Digital signature app for businesses.

Sign
 
Thrive

Complete loyalty and affiliate management platform.

Thrive
 
Voice

Cloud Contact Center Software for businesses.

Voice
 
NEW
LeadChain

Sync, manage, and convert leads across channels seamlessly.

LeadChain
 
NEW
CommunitySpaces

Online community platform for individuals and businesses to grow their network and brand.

CommunitySpaces
 
Suites
Marketing Plus

Unified marketing platform for marketing teams.

Marketing Plus

Commerce

 
Commerce

eCommerce platform to manage and market your online store.

Commerce

Service

 
Desk

Helpdesk software to deliver great customer support.

Desk
 
Assist

Remote support and unattended remote access software.

Assist
 
Lens

Interactive remote assistance software with augmented reality.

Lens
 
FSM

End-to-end field service management platform for service businesses.

FSM
 
SalesIQ

Live chat app to engage and convert website visitors.

SalesIQ
 
Voice

Cloud Contact Center Software for businesses.

Voice
 
NEW
Solo

The all-in-one toolkit for solopreneurs.

Solo
 
Bookings

Appointment scheduling app for consultations with customers.

Bookings
 
Suites
Service Plus

Unified platform for customer service and support teams.

Service Plus

Finance

 
Books

Powerful accounting platform for growing businesses.

Books
 
FREE
Invoice

100% Free invoicing solution.

Invoice
 
Expense

Effortless expense reporting platform.

Expense
 
Inventory

Powerful stock management and inventory control software.

Inventory
 
Billing

End-to-end billing solution for your business.

Billing
 
Checkout

Collect payments online with custom branded pages.

Checkout
 
NEW
Payroll

Payroll software with automated tax payments and filing.

Payroll
 
NEW
Solo

The all-in-one toolkit for solopreneurs.

Solo
 
Practice

Practice management software for accounting firms.

Practice
 
Sign

Digital signature app for businesses.

Sign
 
Commerce

eCommerce platform to manage and market your online store.

Commerce
 
Suites
Finance Plus

All-in-one suite to manage your operations and finances.

Finance Plus

Email and Collaboration

 
Mail

Secure email service for teams of all sizes.

Mail
 
Meeting

Online meeting software for all your video conferencing & webinar needs.

Meeting
 
Writer

Word processor for focused writing and discussions.

Writer
 
Sheet

Spreadsheet software for collaborative teams.

Sheet
 
Show

Create, edit, and share slides with a sleek presentation app.

Show
 
Notebook

Beautiful home for all your notes.

Notebook
 
Cliq

Stay in touch with teams no matter where you are.

Cliq
 
Connect

Employee experience platform to communicate, engage, and build positive employee relations.

Connect
 
Bookings

Appointment scheduling app for consultations with customers.

Bookings
 
TeamInbox

Shared inboxes for teams.

TeamInbox
 
WorkDrive

Online file management for teams.

WorkDrive
 
Sign

Digital signature app for businesses.

Sign
 
Office Suite

Powerful collaborative work platform for teams.

Office Suite
 
Office Integrator

Built in document editors for web apps.

Office Integrator
 
ZeptoMail

Secure and reliable transactional email sending service.

ZeptoMail
 
Calendar

Online business calendar to manage events and schedule appointments.

Calendar
 
Learn

Knowledge and learning management platform.

Learn
 
Voice

Cloud Contact Center Software for businesses.

Voice
 
ToDo

Collaborative task management for individuals and teams.

ToDo
 
Tables

Work management tool to connect people, processes, and information.

Tables
 
FREE
PDF Editor

Collaborative online PDF editing tool.

PDF Editor
 
Suites
Workplace

Application suite built to improve team productivity and collaboration.

Workplace

Human Resources

 
People

Organize, automate, and simplify your HR processes.

People
 
Recruit

Intuitive recruiting platform built to provide hiring solutions.

Recruit
 
Expense

Effortless expense reporting platform.

Expense
 
Workerly

Manage temporary staffing with an employee scheduling solution.

Workerly
 
NEW
Payroll

Payroll software with automated tax payments and filing.

Payroll
 
Shifts

Employee scheduling and time tracking app.

Shifts
 
Sign

Digital signature app for businesses.

Sign
 
Suites
People Plus

Comprehensive HR platform for seamless employee experiences.

People Plus

Security and IT Management

 
Creator

Build custom apps to simplify business processes.

Creator
 
Directory

Workforce identity and access management solution for cloud businesses.

Directory
 
FREE
OneAuth

Secure multi-factor authenticator (MFA) for all your online accounts.

OneAuth
 
Vault

Online password manager for teams.

Vault
 
Catalyst

Pro-code platform to build and deploy your apps.

Catalyst
 
Toolkit

Complete resource for any admin-related lookup queries.

Toolkit
 
Lens

Interactive remote assistance software with augmented reality.

Lens
 
Assist

Remote support and unattended remote access software.

Assist
 
QEngine

Test automation software to build, manage, execute, and report testcases.

QEngine
 
NEW
RPA

Automate manual, tedious, and repetitive tasks easily.

RPA

BI and Analytics

 
Analytics

Modern self-service BI and analytics platform.

Analytics
 
Embedded BI

Embedded analytics and white label BI solutions, tailored for your needs.

Embedded BI
 
DataPrep

AI-powered data preparation service for your data-driven organization.

DataPrep
 
NEW
IoT

Harnessing IoT analytics for real-time operational intelligence.

IoT

Project Management

 
Projects

Manage, track, and collaborate on projects with teams.

Projects
 
Sprints

Planning and tracking tool for scrum teams.

Sprints
 
BugTracker

Automatic bug tracking software for managing bugs.

BugTracker
 
NEW
Solo

The all-in-one toolkit for solopreneurs.

Solo

Developer Platforms

 
Creator

Build custom apps to simplify business processes.

Creator
 
Flow

Automate business workflows by creating smart integrations.

Flow
 
Catalyst

Pro-code platform to build and deploy your apps.

Catalyst
 
Office Integrator

Built in document editors for web apps.

Office Integrator
 
ZeptoMail

Secure and reliable transactional email sending service.

ZeptoMail
 
QEngine

Test automation software to build, manage, execute, and report testcases.

QEngine
 
Tables

Work management tool to connect people, processes, and information.

Tables
 
NEW
RPA

Automate manual, tedious, and repetitive tasks easily.

RPA
 
NEW
Apptics

Application analytics for all apps.

Apptics
 
Embedded BI

Embedded analytics and white label BI solutions, tailored for your needs.

Embedded BI
 
NEW
IoT

Build, deploy, and scale IoT solutions for connected businesses.

IoT
 
DataPrep

AI-powered data preparation service for your data-driven organization.

DataPrep

IoT

 
NEW
IoT

Low-code IoT platform and solutions for connected businesses.

IoT

Search Result

 
CRM Plus

Unified platform to deliver top-notch customer experience.

Try now
CRM Plus
 
Service Plus

Unified platform for customer service and support teams.

Try now
Service Plus
 
Finance Plus

All-in-one suite to manage your operations and finances.

Try now
Finance Plus
 
People Plus

Comprehensive HR platform for seamless employee experiences.

Try now
People Plus
 
Workplace

Application suite built to improve team productivity and collaboration.

Try now
Workplace
 
Marketing Plus

Unified marketing platform for marketing teams.

Try now
Marketing Plus
 
All-in-one suite

Zoho One

The Operating System for Business

Run your entire business on Zoho with our unified cloud software, designed to help you break down silos between departments and increase organizational efficiency.

TRY ZOHO ONE
Zoho One
Zoho Marketplace

With over 2000 ready-to-use extensions across 40+ categories, connect your favorite business tools with the Zoho products you already use.

EXPLORE MARKETPLACE
Marketplace
Skip to main content

Scala SDK Samples - Related Records Operations

Get Related Records

              
package com.zoho.crm.sample.relatedrecords

import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
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.{Comment, Consent, FileDetails, InventoryLineItems, LineTax, Participants, PricingDetails, Record, RecurringActivity, RemindAt}
import com.zoho.crm.api.relatedrecords.FileBodyWrapper
import com.zoho.crm.api.relatedrecords.APIException
import com.zoho.crm.api.relatedrecords.ActionHandler
import com.zoho.crm.api.relatedrecords.ActionResponse
import com.zoho.crm.api.relatedrecords.ActionWrapper
import com.zoho.crm.api.relatedrecords.BodyWrapper
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.DelinkRecordsParam
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsParam
import com.zoho.crm.api.relatedrecords.ResponseHandler
import com.zoho.crm.api.relatedrecords.ResponseWrapper
import com.zoho.crm.api.relatedrecords.SuccessResponse
import com.zoho.crm.api.tags.Tag
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 Relatedrecord {
/**
   *  Get Related Records 
   * This method is used to get the related list records and print the response.
   *
   * @param moduleAPIName      - The API Name of the module to get related records.
   * @param recordId           - The ID of the record to be obtained.
   * @param relatedListAPIName - The API name of the related list. To get the API name of the related list.
   * @throws Exception
   */
  @throws[Exception]
  def getRelatedRecords(moduleAPIName: String, recordId: Long, relatedListAPIName: String): Unit = { //example
    //Get instance of RelatedRecordsOperations Class that takes moduleAPIName, recordId and relatedListAPIName as parameter
    val relatedRecordsOperations = new RelatedRecordsOperations(relatedListAPIName, moduleAPIName)
    //Get instance of ParameterMap Class
    val paramInstance = new ParameterMap
//    paramInstance.add(new GetRelatedRecordsParam().page, 1)
//    paramInstance.add(new GetRelatedRecordsParam().perPage, 2)
    //Get instance of HeaderMap Class
    val headerInstance = new HeaderMap
//    val startdatetime = OffsetDateTime.of(2019, 6, 1, 10, 0, 1, 0, ZoneOffset.of("+05:30"))
//    headerInstance.add(new GetRelatedRecordsHeader().IfModifiedSince, startdatetime)
    //Call getRelatedRecords method that takes paramInstance, headerInstance as parameter
    val responseOption = relatedRecordsOperations.getRelatedRecords(recordId, 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 Record instances
          val records = responseWrapper.getData

          for (record <- records) { //Get the ID of each Record
            println("Record ID: " + record.getId)
            //Get the createdBy User instance of each Record
            var createdByOption = record.getCreatedBy
            //Check if createdBy is not null
            if (createdByOption.isDefined) { //Get the ID of the createdBy User
              var createdBy = createdByOption.get
              println("Record Created By User-ID: " + createdBy.getId)
              //Get the name of the createdBy User
              println("Record Created By User-Name: " + createdBy.getName)
              //Get the Email of the createdBy User
              println("Record Created By User-Email: " + createdBy.getEmail)
            }
            //Get the CreatedTime of each Record
            println("Record CreatedTime: " + record.getCreatedTime)
            //Get the modifiedBy User instance of each Record
            var modifiedByOption = record.getModifiedBy
            //Check if modifiedBy is not null
            if (modifiedByOption.isDefined) { //Get the ID of the modifiedBy User
              var modifiedBy =modifiedByOption.get
              println("Record Modified By User-ID: " + modifiedBy.getId)
              //Get the name of the modifiedBy User
              println("Record Modified By User-Name: " + modifiedBy.getName)
              //Get the Email of the modifiedBy User
              println("Record Modified By User-Email: " + modifiedBy.getEmail)
            }
            //Get the ModifiedTime of each Record
            println("Record ModifiedTime: " + record.getModifiedTime)
            //Get the list of Tag instance each Record
            val tags = record.getTag
            //Check if tags is not null
            if (tags.length > 0) {

              for (tag <- tags) { //Get the Name of each Tag
                println("Record Tag Name: " + tag.getName)
                //Get the Id of each Tag
                println("Record Tag ID: " + tag.getId)
              }
            }
            //To get particular field value
            println("Record Field Value: " + record.getKeyValue("Last_Name")) // FieldApiName

            println("Record KeyValues: ")
            //Get the KeyValue map
            record.getKeyValues.foreach(entry=>{
              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 <- fileDetails) { //Get the Extn of each FileDetails
                    println("Record FileDetails Extn: " + fileDetail.getExtn)
                    //Get the IsPreviewAvailable of each FileDetails
                    println("Record FileDetails IsPreviewAvailable: " + fileDetail.getIsPreviewAvailable)
                    //Get the DownloadUrl of each FileDetails
                    println("Record FileDetails DownloadUrl: " + fileDetail.getDownloadUrl)
                    //Get the DeleteUrl of each FileDetails
                    println("Record FileDetails DeleteUrl: " + fileDetail.getDeleteUrl)
                    //Get the EntityId of each FileDetails
                    println("Record FileDetails EntityId: " + fileDetail.getEntityId)
                    //Get the Mode of each FileDetails
                    println("Record FileDetails Mode: " + fileDetail.getMode)
                    //Get the OriginalSizeByte of each FileDetails
                    println("Record FileDetails OriginalSizeByte: " + fileDetail.getOriginalSizeByte)
                    //Get the PreviewUrl of each FileDetails
                    println("Record FileDetails PreviewUrl: " + fileDetail.getPreviewUrl)
                    //Get the FileName of each FileDetails
                    println("Record FileDetails FileName: " + fileDetail.getFileName)
                    //Get the FileId of each FileDetails
                    println("Record FileDetails FileId: " + fileDetail.getFileId)
                    //Get the AttachmentId of each FileDetails
                    println("Record FileDetails AttachmentId: " + fileDetail.getAttachmentId)
                    //Get the FileSize of each FileDetails
                    println("Record FileDetails FileSize: " + fileDetail.getFileSize)
                    //Get the CreatorId of each FileDetails
                    println("Record FileDetails CreatorId: " + fileDetail.getCreatorId)
                    //Get the LinkDocs of each FileDetails
                    println("Record FileDetails LinkDocs: " + fileDetail.getLinkDocs)
                  }
                }
                else if (dataList(0).isInstanceOf[Choice[_]]) {
                  @SuppressWarnings(Array("unchecked")) val choiceList = dataList.asInstanceOf[(ArrayBuffer[Choice[_$1]]) forSome {type _$1}]
                  println(keyName)
                  println("values")

                  for (choice <- choiceList) {
                    println(choice.getValue)
                  }
                }
                else if (dataList(0).isInstanceOf[InventoryLineItems]) {
                  @SuppressWarnings(Array("unchecked")) val productDetails = value.asInstanceOf[ArrayBuffer[InventoryLineItems]]

                  for (productDetail <- productDetails) {
                    val lineItemProductOption = productDetail.getProduct
                    if (lineItemProductOption.isDefined) {
                      val lineItemProduct= lineItemProductOption.get
                      println("Record ProductDetails LineItemProduct ProductCode: " + lineItemProduct.getProductCode)
                      println("Record ProductDetails LineItemProduct Currency: " + lineItemProduct.getCurrency)
                      println("Record ProductDetails LineItemProduct Name: " + lineItemProduct.getName)
                      println("Record ProductDetails LineItemProduct Id: " + lineItemProduct.getId)
                    }
                    println("Record ProductDetails Quantity: " + productDetail.getQuantity.toString)
                    println("Record ProductDetails Discount: " + productDetail.getDiscount)
                    println("Record ProductDetails TotalAfterDiscount: " + productDetail.getTotalAfterDiscount.toString)
                    println("Record ProductDetails NetTotal: " + productDetail.getNetTotal.toString)
                    if (productDetail.getBook.isDefined) println("Record ProductDetails Book: " + productDetail.getBook.toString)
                    println("Record ProductDetails Tax: " + productDetail.getTax.toString)
                    println("Record ProductDetails ListPrice: " + productDetail.getListPrice.toString)
                    println("Record ProductDetails UnitPrice: " + productDetail.getUnitPrice)
                    println("Record ProductDetails QuantityInStock: " + productDetail.getQuantityInStock.toString)
                    println("Record ProductDetails Total: " + productDetail.getTotal.toString)
                    println("Record ProductDetails ID: " + productDetail.getId)
                    println("Record ProductDetails ProductDescription: " + productDetail.getProductDescription)
                    val lineTaxes = productDetail.getLineTax

                    for (lineTax <- lineTaxes) {
                      println("Record ProductDetails LineTax Percentage: " + lineTax.getPercentage.toString)
                      println("Record ProductDetails LineTax Name: " + lineTax.getName)
                      println("Record ProductDetails LineTax Id: " + lineTax.getId)
                      println("Record ProductDetails LineTax Value: " + lineTax.getValue.toString)
                    }
                  }
                }
                else if (dataList(0).isInstanceOf[Tag]) {
                  @SuppressWarnings(Array("unchecked")) val tagList = value.asInstanceOf[ArrayBuffer[Tag]]

                  for (tag <- tagList) {
                    println("Record Tag Name: " + tag.getName)
                    println("Record Tag ID: " + tag.getId)
                  }
                }
                else if (dataList(0).isInstanceOf[PricingDetails]) {
                  @SuppressWarnings(Array("unchecked")) val pricingDetails = value.asInstanceOf[ ArrayBuffer[PricingDetails]]

                  for (pricingDetail <- pricingDetails) {
                    println("Record PricingDetails ToRange: " + pricingDetail.getToRange.toString)
                    println("Record PricingDetails Discount: " + pricingDetail.getDiscount.toString)
                    println("Record PricingDetails ID: " + pricingDetail.getId)
                    println("Record PricingDetails FromRange: " + pricingDetail.getFromRange.toString)
                  }
                }
                else if(dataList(0).isInstanceOf[Participants])
                {
                  val participants = value.asInstanceOf[ ArrayBuffer[Participants]]
                  for (participant <- participants) {
                    println("Record Participants Name: " + participant.getName().toString)
                    println("Record Participants Invited: " + participant.getInvited().toString())
                    println("Record Participants ID: " + participant.getId().toString)
                    println("Record Participants Type: " + participant.getType().toString)
                    println("Record Participants Participant: " + participant.getParticipant().toString)
                    println("Record Participants Status: " + participant.getStatus().toString)
                  }
                }
                else if (dataList(0).isInstanceOf[Record]) {
                  @SuppressWarnings(Array("unchecked")) val recordList = dataList.asInstanceOf[ ArrayBuffer[Record]]

                  for (record1 <- recordList) { //Get the details map


                    record1.getKeyValues.foreach(entry=>{
                      println(entry._1 + ": " + entry._2)
                    })
                  }
                }
                else if (dataList(0).isInstanceOf[LineTax]) {
                  @SuppressWarnings(Array("unchecked")) val lineTaxes = dataList.asInstanceOf[ ArrayBuffer[LineTax]]

                  for (lineTax <- lineTaxes) {
                    println("Record ProductDetails LineTax Percentage: " + lineTax.getPercentage.toString)
                    println("Record ProductDetails LineTax Name: " + lineTax.getName)
                    println("Record ProductDetails LineTax Id: " + lineTax.getId)
                    println("Record ProductDetails LineTax Value: " + lineTax.getValue.toString)
                  }
                }
                else if (dataList(0).isInstanceOf[Comment]) {
                  @SuppressWarnings(Array("unchecked")) val comments = dataList.asInstanceOf[ ArrayBuffer[Comment]]

                  for (comment <- comments) {
                    println("Record Comment CommentedBy: " + comment.getCommentedBy)
                    println("Record Comment CommentedTime: " + comment.getCommentedTime.toString)
                    println("Record Comment CommentContent: " + comment.getCommentContent)
                    println("Record Comment Id: " + comment.getId)
                  }
                }
                else if (dataList(0).isInstanceOf[Attachment]) { //Get the list of obtained Attachment instances
                  @SuppressWarnings(Array("unchecked")) val attachments = dataList.asInstanceOf[ ArrayBuffer[Attachment]]


                  for (attachment <- attachments) { //Get the owner User instance of each attachment
                    val ownerOption = attachment.getOwner
                    //Check if owner is not null
                    if (ownerOption.isDefined) { //Get the Name of the Owner
                      var owner = ownerOption.get
                      println("Record Attachment Owner User-Name: " + owner.getName)
                      //Get the ID of the Owner
                      println("Record Attachment Owner User-ID: " + owner.getId)
                      //Get the Email of the Owner
                      println("Record Attachment Owner User-Email: " + owner.getEmail)
                    }
                    //Get the modified time of each attachment
                    println("Record Attachment Modified Time: " + attachment.getModifiedTime.toString)
                    //Get the name of the File
                    println("Record Attachment File Name: " + attachment.getFileName)
                    //Get the created time of each attachment
                    println("Record Attachment Created Time: " + attachment.getCreatedTime.toString)
                    //Get the Attachment file size
                    println("Record Attachment File Size: " + attachment.getSize.toString)
                    //Get the parentId Record instance of each attachment
                    val parentIdOption = attachment.getParentId
                    //Check if parentId is not null
                    if (parentIdOption.isDefined) { //Get the parent record Name of each attachment
                      var parentId =parentIdOption.get
                      println("Record Attachment parent record Name: " + parentId.getKeyValue("name"))
                      //Get the parent record ID of each attachment
                      println("Record Attachment parent record ID: " + parentId.getId)
                    }
                    //Get the attachment is Editable
                    println("Record Attachment is Editable: " + attachment.geteditable().toString)
                    //Get the file ID of each attachment
                    println("Record Attachment File ID: " + attachment.getfileId())
                    //Get the type of each attachment
                    println("Record Attachment File Type: " + attachment.gettype)
                    //Get the seModule of each attachment
                    println("Record Attachment seModule: " + attachment.getseModule())
                    //Get the modifiedBy User instance of each attachment
                    var modifiedByOption = attachment.getModifiedBy
                    if (modifiedByOption.isDefined) { //Get the Name of the modifiedBy User
                      var modifiedBy = modifiedByOption.get
                      println("Record Attachment Modified By User-Name: " + modifiedBy.getName)
                      println("Record Attachment Modified By User-ID: " + modifiedBy.getId)
                      println("Record Attachment Modified By User-Email: " + modifiedBy.getEmail)
                    }
                    //Get the state of each attachment
                    println("Record Attachment State: " + attachment.getstate)
                    //Get the ID of each attachment
                    println("Record Attachment ID: " + attachment.getId)
                    //Get the createdBy User instance of each attachment
                    var createdByOption = attachment.getCreatedBy
                    if (createdByOption.isDefined) {
                      var createdBy = modifiedByOption.get

                      println("Record Attachment Created By User-Name: " + createdBy.getName)
                      println("Record Attachment Created By User-ID: " + createdBy.getId)
                      println("Record Attachment Created By User-Email: " + createdBy.getEmail)
                    }
                    //Get the linkUrl of each attachment
                    println("Record Attachment LinkUrl: " + attachment.getlinkUrl())
                  }
                }
                else println(keyName + ": " + value)
              }
              else if (value.isInstanceOf[Record]) {
                val recordValue = value.asInstanceOf[Record]
                println("Record " + keyName + " ID: " + recordValue.getId)
                println("Record " + keyName + " Name: " + recordValue.getKeyValue("name"))
              }
              else if (value.isInstanceOf[Layout]) {
                val layout = value.asInstanceOf[Layout]
                if (layout != null) {
                  println("Record " + keyName + " ID: " + layout.getId)
                  println("Record " + keyName + " Name: " + layout.getName)
                }
              }
              else if (value.isInstanceOf[User]) {
                val user = value.asInstanceOf[User]
                if (user != null) {
                  println("Record " + keyName + " User-ID: " + user.getId)
                  println("Record " + keyName + " User-Name: " + user.getName)
                  println("Record " + keyName + " User-Email: " + user.getEmail)
                }
              }
              else if (value.isInstanceOf[Choice[_]]) println(keyName + ": " + value.asInstanceOf[Choice[_]].getValue)
              else if (value.isInstanceOf[RemindAt]) println(keyName + ": " + value.asInstanceOf[RemindAt].getAlarm)
              else if (value.isInstanceOf[RecurringActivity]) {
                println(keyName)
                println("RRULE" + ": " + value.asInstanceOf[RecurringActivity].getRrule)
              }
              else if (value.isInstanceOf[Consent]) {
                val consent = value.asInstanceOf[Consent]
                println("Record Consent ID: " + consent.getId)
                //Get the Owner User instance of each attachment
                val ownerOption = consent.getOwner
                if (ownerOption.isDefined) { //Get the name of the owner User
                  var owner = ownerOption.get
                  println("Record Consent Owner Name: " + owner.getName)
                  //Get the ID of the owner User
                  println("Record Consent Owner ID: " + owner.getId)
                  //Get the Email of the owner User
                  println("Record Consent Owner Email: " + owner.getEmail)
                }
                val consentCreatedByOption = consent.getCreatedBy
                if (consentCreatedByOption.isDefined) { //Get the name of the CreatedBy User
                  var consentCreatedBy = consentCreatedByOption.get
                  println("Record Consent CreatedBy Name: " + consentCreatedBy.getName)
                  //Get the ID of the CreatedBy User
                  println("Record Consent CreatedBy ID: " + consentCreatedBy.getId)
                  //Get the Email of the CreatedBy User
                  println("Record Consent CreatedBy Email: " + consentCreatedBy.getEmail)
                }
                val consentModifiedByOption = consent.getModifiedBy
                if (consentModifiedByOption.isDefined) { //Get the name of the ModifiedBy User
                  var consentModifiedBy = consentModifiedByOption.get
                  println("Record Consent ModifiedBy Name: " + consentModifiedBy.getName)
                  //Get the ID of the ModifiedBy User
                  println("Record Consent ModifiedBy ID: " + consentModifiedBy.getId)
                  //Get the Email of the ModifiedBy User
                  println("Record Consent ModifiedBy Email: " + consentModifiedBy.getEmail)
                }
                println("Record Consent CreatedTime: " + consent.getCreatedTime)
                println("Record Consent ModifiedTime: " + consent.getModifiedTime)
                println("Record Consent ContactThroughEmail: " + consent.getContactThroughEmail)
                println("Record Consent ContactThroughSocial: " + consent.getContactThroughSocial)
                println("Record Consent ContactThroughSurvey: " + consent.getContactThroughSurvey)
                println("Record Consent ContactThroughPhone: " + consent.getContactThroughPhone)
                println("Record Consent MailSentTime: " + consent.getMailSentTime.toString)
                println("Record Consent ConsentDate: " + consent.getConsentDate.toString)
                println("Record Consent ConsentRemarks: " + consent.getConsentRemarks)
                println("Record Consent ConsentThrough: " + consent.getConsentThrough)
                println("Record Consent DataProcessingBasis: " + consent.getDataProcessingBasis)
                //To get custom values
                println("Record Consent Lawful Reason: " + consent.getKeyValue("Lawful_Reason"))
              }
              else println(keyName + ": " + value)
            })
          }
        }

        else { //Check if the request returned an exception
          if (responseHandler.isInstanceOf[APIException]) { //Get the received APIException instance
            val exception = responseHandler.asInstanceOf[APIException]
            //Get the Status
            println("Status: " + exception.getStatus.getValue)
            //Get the Code
            println("Code: " + exception.getCode.getValue)
            println("Details: ")

            exception.getDetails.foreach(entry=>{
              println(entry._1 + ": " + entry._2)
            })
            //Get the Message
            println("Message: " + exception.getMessage.getValue)
          }
        }
      }
      else { //If response is not as expected
        //Get model object from response
        val responseObject = response.getModel
        //Get the response object's class
        val clas = responseObject.getClass
        //Get all declared fields of the response class
        val fields = clas.getDeclaredFields
        for (field <- fields) { //Get each value
          println(field.getName + ":" + field.get(responseObject))
        }
      }
    }
  }
}
 
Update Related Records

              
package com.zoho.crm.sample.relatedrecords

import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
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.{Comment, Consent, FileDetails, InventoryLineItems, LineTax, Participants, PricingDetails, Record, RecurringActivity, RemindAt}
import com.zoho.crm.api.relatedrecords.FileBodyWrapper
import com.zoho.crm.api.relatedrecords.APIException
import com.zoho.crm.api.relatedrecords.ActionHandler
import com.zoho.crm.api.relatedrecords.ActionResponse
import com.zoho.crm.api.relatedrecords.ActionWrapper
import com.zoho.crm.api.relatedrecords.BodyWrapper
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.DelinkRecordsParam
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsParam
import com.zoho.crm.api.relatedrecords.ResponseHandler
import com.zoho.crm.api.relatedrecords.ResponseWrapper
import com.zoho.crm.api.relatedrecords.SuccessResponse
import com.zoho.crm.api.tags.Tag
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 Relatedrecord {
/**
   *  Update Related Records 
   * This method is used to update the relation between the records and print the response.
   *
   * @param moduleAPIName      - The API Name of the module to update related records.
   * @param recordId           - The ID of the record to be obtained.
   * @param relatedListAPIName - The API name of the related list. To get the API name of the related list.
   * @throws Exception
   */
  @throws[Exception]
  def updateRelatedRecords(moduleAPIName: String, recordId: Long, relatedListAPIName: String): Unit = { //API Name of the module
    val relatedRecordsOperations = new RelatedRecordsOperations(relatedListAPIName, moduleAPIName)
    //Get instance of BodyWrapper Class that will contain the request body
    val request = new BodyWrapper
    //List of Record instances
    val records = new ArrayBuffer[Record]
    //Get instance of Record Class
    val record1 = new Record
    /*
     * Call addKeyValue method that takes two arguments
     * 1 -> A string that is the Field's API Name
     * 2 -> Value
     */
    record1.addKeyValue("id", 3477067230023l)
    record1.addKeyValue("Note_Content", "asd")
    //Add Record instance to the list
    records.addOne(record1)
    val record2 = new Record
    record2.addKeyValue("id", 3477065919001l)
    record2.addKeyValue("Note_Content", "asd")
    records.addOne(record2)
    //Set the list to Records in BodyWrapper instance
    request.setData(records)
    //Call updateRelatedRecords method that takes BodyWrapper instance as parameter.
    val responseOption = relatedRecordsOperations.updateRelatedRecords(recordId, request)
    if (responseOption.isDefined) {
      var response = responseOption.get
      println("Status Code: " + response.getStatusCode)
      if (response.isExpected) {
        val actionHandler = response.getObject
        if (actionHandler.isInstanceOf[ActionWrapper]) { //Get the received ActionWrapper instance
          val actionWrapper = actionHandler.asInstanceOf[ActionWrapper]
          //Get the list of obtained ActionResponse instances
          val actionResponses = actionWrapper.getData
           
          for (actionResponse <- actionResponses) { //Check if the request is successful
            if (actionResponse.isInstanceOf[SuccessResponse]) { //Get the received SuccessResponse instance
              val successResponse = actionResponse.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 (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 <- fields) {
          println(field.getName + ":" + field.get(responseObject))
        }
      }
    }
  }
}
 

              
package com.zoho.crm.sample.relatedrecords

import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
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.{Comment, Consent, FileDetails, InventoryLineItems, LineTax, Participants, PricingDetails, Record, RecurringActivity, RemindAt}
import com.zoho.crm.api.relatedrecords.FileBodyWrapper
import com.zoho.crm.api.relatedrecords.APIException
import com.zoho.crm.api.relatedrecords.ActionHandler
import com.zoho.crm.api.relatedrecords.ActionResponse
import com.zoho.crm.api.relatedrecords.ActionWrapper
import com.zoho.crm.api.relatedrecords.BodyWrapper
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.DelinkRecordsParam
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsParam
import com.zoho.crm.api.relatedrecords.ResponseHandler
import com.zoho.crm.api.relatedrecords.ResponseWrapper
import com.zoho.crm.api.relatedrecords.SuccessResponse
import com.zoho.crm.api.tags.Tag
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 Relatedrecord {
/**
   *  Delink Records 
   * This method is used to delete the association between modules and print the response.
   *
   * @param moduleAPIName      - The API Name of the module to delink related records.
   * @param recordId           - The ID of the record
   * @param relatedListAPIName - The API name of the related list. To get the API name of the related list.
   * @param relatedListIds     - The List of related record IDs.
   * @throws Exception
   */
  @throws[Exception]
  def delinkRecords(moduleAPIName: String, recordId: Long, relatedListAPIName: String, relatedListIds: ArrayBuffer[String]): Unit = { //List<Long> relatedListIds = new ArrayList<Long>(Arrays.asList(3477061000005919001l, 34770615917011l))
    val relatedRecordsOperations = new RelatedRecordsOperations(relatedListAPIName, moduleAPIName)
    val paramInstance = new ParameterMap
     
    for (relatedListId <- relatedListIds) {
      paramInstance.add(new DelinkRecordsParam().ids, relatedListId)
    }
    //Call delinkRecords method that takes paramInstance instance as parameter.
    val responseOption = relatedRecordsOperations.delinkRecords(recordId, Option(paramInstance))
    if (responseOption.isDefined) {
      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 <- actionResponses) {
            if (actionResponse.isInstanceOf[SuccessResponse]) {
              val successResponse = actionResponse.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 (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 <- fields) {
          println(field.getName + ":" + field.get(responseObject))
        }
      }
    }
  }
}
 
Get Related Records Using External ID

              
package com.zoho.crm.sample.relatedrecords

import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
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.{Comment, Consent, FileDetails, InventoryLineItems, LineTax, Participants, PricingDetails, Record, RecurringActivity, RemindAt}
import com.zoho.crm.api.relatedrecords.FileBodyWrapper
import com.zoho.crm.api.relatedrecords.APIException
import com.zoho.crm.api.relatedrecords.ActionHandler
import com.zoho.crm.api.relatedrecords.ActionResponse
import com.zoho.crm.api.relatedrecords.ActionWrapper
import com.zoho.crm.api.relatedrecords.BodyWrapper
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.DelinkRecordsParam
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsParam
import com.zoho.crm.api.relatedrecords.ResponseHandler
import com.zoho.crm.api.relatedrecords.ResponseWrapper
import com.zoho.crm.api.relatedrecords.SuccessResponse
import com.zoho.crm.api.tags.Tag
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 Relatedrecord {
/**
   *  Get Related Records Using External Id 
   * This method is used to get the related list records and print the response.
   *
   * @param moduleAPIName      - The API Name of the module to get related records.
   * @param externalValue      -
   * @param relatedListAPIName - The API name of the related list. To get the API name of the related list.
   * @throws Exception
   */
  @throws[Exception]
  def getRelatedRecordsUsingExternalId(moduleAPIName: String, externalValue: String, relatedListAPIName: String): Unit = { //example
    val xExternal = "Leads.External"
    //Get instance of RelatedRecordsOperations Class that takes relatedListAPIName, moduleAPIName and xExternal as parameter
    val relatedRecordsOperations = new RelatedRecordsOperations(relatedListAPIName, moduleAPIName, Option(xExternal))
    //Get instance of ParameterMap Class
    val paramInstance = new ParameterMap
//    paramInstance.add(new GetRelatedRecordsParam().page, 1)
//    paramInstance.add(new GetRelatedRecordsParam().perPage, 2)
    //Get instance of HeaderMap Class
    val headerInstance = new HeaderMap
//    val startdatetime = OffsetDateTime.of(2019, 6, 1, 10, 0, 1, 0, ZoneOffset.of("+05:30"))
//    headerInstance.add(new GetRelatedRecordsHeader().IfModifiedSince, startdatetime)
    //Call getRelatedRecordsUsingExternalId method that takes externalValue, paramInstance and headerInstance as parameter
    val responseOption = relatedRecordsOperations.getRelatedRecordsUsingExternalId(externalValue, 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 Record instances
          val records = responseWrapper.getData

          for (record <- records) { //Get the ID of each Record
            println("Record ID: " + record.getId)
            //Get the createdBy User instance of each Record
            var createdByOption = record.getCreatedBy
            //Check if createdBy is not null
            if (createdByOption.isDefined) { //Get the ID of the createdBy User
              var createdBy = createdByOption.get
              println("Record Created By User-ID: " + createdBy.getId)
              //Get the name of the createdBy User
              println("Record Created By User-Name: " + createdBy.getName)
              //Get the Email of the createdBy User
              println("Record Created By User-Email: " + createdBy.getEmail)
            }
            //Get the CreatedTime of each Record
            println("Record CreatedTime: " + record.getCreatedTime)
            //Get the modifiedBy User instance of each Record
            var modifiedByOption = record.getModifiedBy
            //Check if modifiedBy is not null
            if (modifiedByOption.isDefined) { //Get the ID of the modifiedBy User
              var modifiedBy =modifiedByOption.get
              println("Record Modified By User-ID: " + modifiedBy.getId)
              //Get the name of the modifiedBy User
              println("Record Modified By User-Name: " + modifiedBy.getName)
              //Get the Email of the modifiedBy User
              println("Record Modified By User-Email: " + modifiedBy.getEmail)
            }
            //Get the ModifiedTime of each Record
            println("Record ModifiedTime: " + record.getModifiedTime)
            //Get the list of Tag instance each Record
            val tags = record.getTag
            //Check if tags is not null
            if (tags.length > 0) {

              for (tag <- tags) { //Get the Name of each Tag
                println("Record Tag Name: " + tag.getName)
                //Get the Id of each Tag
                println("Record Tag ID: " + tag.getId)
              }
            }
            //To get particular field value
            println("Record Field Value: " + record.getKeyValue("Last_Name")) // FieldApiName

            println("Record KeyValues: ")
            //Get the KeyValue map
            record.getKeyValues.foreach(entry=>{
              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 <- fileDetails) { //Get the Extn of each FileDetails
                    println("Record FileDetails Extn: " + fileDetail.getExtn)
                    //Get the IsPreviewAvailable of each FileDetails
                    println("Record FileDetails IsPreviewAvailable: " + fileDetail.getIsPreviewAvailable)
                    //Get the DownloadUrl of each FileDetails
                    println("Record FileDetails DownloadUrl: " + fileDetail.getDownloadUrl)
                    //Get the DeleteUrl of each FileDetails
                    println("Record FileDetails DeleteUrl: " + fileDetail.getDeleteUrl)
                    //Get the EntityId of each FileDetails
                    println("Record FileDetails EntityId: " + fileDetail.getEntityId)
                    //Get the Mode of each FileDetails
                    println("Record FileDetails Mode: " + fileDetail.getMode)
                    //Get the OriginalSizeByte of each FileDetails
                    println("Record FileDetails OriginalSizeByte: " + fileDetail.getOriginalSizeByte)
                    //Get the PreviewUrl of each FileDetails
                    println("Record FileDetails PreviewUrl: " + fileDetail.getPreviewUrl)
                    //Get the FileName of each FileDetails
                    println("Record FileDetails FileName: " + fileDetail.getFileName)
                    //Get the FileId of each FileDetails
                    println("Record FileDetails FileId: " + fileDetail.getFileId)
                    //Get the AttachmentId of each FileDetails
                    println("Record FileDetails AttachmentId: " + fileDetail.getAttachmentId)
                    //Get the FileSize of each FileDetails
                    println("Record FileDetails FileSize: " + fileDetail.getFileSize)
                    //Get the CreatorId of each FileDetails
                    println("Record FileDetails CreatorId: " + fileDetail.getCreatorId)
                    //Get the LinkDocs of each FileDetails
                    println("Record FileDetails LinkDocs: " + fileDetail.getLinkDocs)
                  }
                }
                else if (dataList(0).isInstanceOf[Choice[_]]) {
                  @SuppressWarnings(Array("unchecked")) val choiceList = dataList.asInstanceOf[(ArrayBuffer[Choice[_$1]]) forSome {type _$1}]
                  println(keyName)
                  println("values")

                  for (choice <- choiceList) {
                    println(choice.getValue)
                  }
                }
                else if (dataList(0).isInstanceOf[InventoryLineItems]) {
                  @SuppressWarnings(Array("unchecked")) val productDetails = value.asInstanceOf[ArrayBuffer[InventoryLineItems]]

                  for (productDetail <- productDetails) {
                    val lineItemProductOption = productDetail.getProduct
                    if (lineItemProductOption.isDefined) {
                      val lineItemProduct= lineItemProductOption.get
                      println("Record ProductDetails LineItemProduct ProductCode: " + lineItemProduct.getProductCode)
                      println("Record ProductDetails LineItemProduct Currency: " + lineItemProduct.getCurrency)
                      println("Record ProductDetails LineItemProduct Name: " + lineItemProduct.getName)
                      println("Record ProductDetails LineItemProduct Id: " + lineItemProduct.getId)
                    }
                    println("Record ProductDetails Quantity: " + productDetail.getQuantity.toString)
                    println("Record ProductDetails Discount: " + productDetail.getDiscount)
                    println("Record ProductDetails TotalAfterDiscount: " + productDetail.getTotalAfterDiscount.toString)
                    println("Record ProductDetails NetTotal: " + productDetail.getNetTotal.toString)
                    if (productDetail.getBook.isDefined) println("Record ProductDetails Book: " + productDetail.getBook.toString)
                    println("Record ProductDetails Tax: " + productDetail.getTax.toString)
                    println("Record ProductDetails ListPrice: " + productDetail.getListPrice.toString)
                    println("Record ProductDetails UnitPrice: " + productDetail.getUnitPrice)
                    println("Record ProductDetails QuantityInStock: " + productDetail.getQuantityInStock.toString)
                    println("Record ProductDetails Total: " + productDetail.getTotal.toString)
                    println("Record ProductDetails ID: " + productDetail.getId)
                    println("Record ProductDetails ProductDescription: " + productDetail.getProductDescription)
                    val lineTaxes = productDetail.getLineTax

                    for (lineTax <- lineTaxes) {
                      println("Record ProductDetails LineTax Percentage: " + lineTax.getPercentage.toString)
                      println("Record ProductDetails LineTax Name: " + lineTax.getName)
                      println("Record ProductDetails LineTax Id: " + lineTax.getId)
                      println("Record ProductDetails LineTax Value: " + lineTax.getValue.toString)
                    }
                  }
                }
                else if (dataList(0).isInstanceOf[Tag]) {
                  @SuppressWarnings(Array("unchecked")) val tagList = value.asInstanceOf[ArrayBuffer[Tag]]

                  for (tag <- tagList) {
                    println("Record Tag Name: " + tag.getName)
                    println("Record Tag ID: " + tag.getId)
                  }
                }
                else if (dataList(0).isInstanceOf[PricingDetails]) {
                  @SuppressWarnings(Array("unchecked")) val pricingDetails = value.asInstanceOf[ ArrayBuffer[PricingDetails]]

                  for (pricingDetail <- pricingDetails) {
                    println("Record PricingDetails ToRange: " + pricingDetail.getToRange.toString)
                    println("Record PricingDetails Discount: " + pricingDetail.getDiscount.toString)
                    println("Record PricingDetails ID: " + pricingDetail.getId)
                    println("Record PricingDetails FromRange: " + pricingDetail.getFromRange.toString)
                  }
                }
                else if(dataList(0).isInstanceOf[Participants])
                {
                  val participants = value.asInstanceOf[ ArrayBuffer[Participants]]
                  for (participant <- participants) {
                    println("Record Participants Name: " + participant.getName().toString)
                    println("Record Participants Invited: " + participant.getInvited().toString())
                    println("Record Participants ID: " + participant.getId().toString)
                    println("Record Participants Type: " + participant.getType().toString)
                    println("Record Participants Participant: " + participant.getParticipant().toString)
                    println("Record Participants Status: " + participant.getStatus().toString)
                  }
                }
                else if (dataList(0).isInstanceOf[Record]) {
                  @SuppressWarnings(Array("unchecked")) val recordList = dataList.asInstanceOf[ ArrayBuffer[Record]]

                  for (record1 <- recordList) { //Get the details map


                    record1.getKeyValues.foreach(entry=>{
                      println(entry._1 + ": " + entry._2)
                    })
                  }
                }
                else if (dataList(0).isInstanceOf[LineTax]) {
                  @SuppressWarnings(Array("unchecked")) val lineTaxes = dataList.asInstanceOf[ ArrayBuffer[LineTax]]

                  for (lineTax <- lineTaxes) {
                    println("Record ProductDetails LineTax Percentage: " + lineTax.getPercentage.toString)
                    println("Record ProductDetails LineTax Name: " + lineTax.getName)
                    println("Record ProductDetails LineTax Id: " + lineTax.getId)
                    println("Record ProductDetails LineTax Value: " + lineTax.getValue.toString)
                  }
                }
                else if (dataList(0).isInstanceOf[Comment]) {
                  @SuppressWarnings(Array("unchecked")) val comments = dataList.asInstanceOf[ ArrayBuffer[Comment]]

                  for (comment <- comments) {
                    println("Record Comment CommentedBy: " + comment.getCommentedBy)
                    println("Record Comment CommentedTime: " + comment.getCommentedTime.toString)
                    println("Record Comment CommentContent: " + comment.getCommentContent)
                    println("Record Comment Id: " + comment.getId)
                  }
                }
                else if (dataList(0).isInstanceOf[Attachment]) { //Get the list of obtained Attachment instances
                  @SuppressWarnings(Array("unchecked")) val attachments = dataList.asInstanceOf[ ArrayBuffer[Attachment]]


                  for (attachment <- attachments) { //Get the owner User instance of each attachment
                    val ownerOption = attachment.getOwner
                    //Check if owner is not null
                    if (ownerOption.isDefined) { //Get the Name of the Owner
                      var owner = ownerOption.get
                      println("Record Attachment Owner User-Name: " + owner.getName)
                      //Get the ID of the Owner
                      println("Record Attachment Owner User-ID: " + owner.getId)
                      //Get the Email of the Owner
                      println("Record Attachment Owner User-Email: " + owner.getEmail)
                    }
                    //Get the modified time of each attachment
                    println("Record Attachment Modified Time: " + attachment.getModifiedTime.toString)
                    //Get the name of the File
                    println("Record Attachment File Name: " + attachment.getFileName)
                    //Get the created time of each attachment
                    println("Record Attachment Created Time: " + attachment.getCreatedTime.toString)
                    //Get the Attachment file size
                    println("Record Attachment File Size: " + attachment.getSize.toString)
                    //Get the parentId Record instance of each attachment
                    val parentIdOption = attachment.getParentId
                    //Check if parentId is not null
                    if (parentIdOption.isDefined) { //Get the parent record Name of each attachment
                      var parentId =parentIdOption.get
                      println("Record Attachment parent record Name: " + parentId.getKeyValue("name"))
                      //Get the parent record ID of each attachment
                      println("Record Attachment parent record ID: " + parentId.getId)
                    }
                    //Get the attachment is Editable
                    println("Record Attachment is Editable: " + attachment.geteditable().toString)
                    //Get the file ID of each attachment
                    println("Record Attachment File ID: " + attachment.getfileId())
                    //Get the type of each attachment
                    println("Record Attachment File Type: " + attachment.gettype)
                    //Get the seModule of each attachment
                    println("Record Attachment seModule: " + attachment.getseModule())
                    //Get the modifiedBy User instance of each attachment
                    var modifiedByOption = attachment.getModifiedBy
                    if (modifiedByOption.isDefined) { //Get the Name of the modifiedBy User
                      var modifiedBy = modifiedByOption.get
                      println("Record Attachment Modified By User-Name: " + modifiedBy.getName)
                      println("Record Attachment Modified By User-ID: " + modifiedBy.getId)
                      println("Record Attachment Modified By User-Email: " + modifiedBy.getEmail)
                    }
                    //Get the state of each attachment
                    println("Record Attachment State: " + attachment.getstate)
                    //Get the ID of each attachment
                    println("Record Attachment ID: " + attachment.getId)
                    //Get the createdBy User instance of each attachment
                    var createdByOption = attachment.getCreatedBy
                    if (createdByOption.isDefined) {
                      var createdBy = modifiedByOption.get

                      println("Record Attachment Created By User-Name: " + createdBy.getName)
                      println("Record Attachment Created By User-ID: " + createdBy.getId)
                      println("Record Attachment Created By User-Email: " + createdBy.getEmail)
                    }
                    //Get the linkUrl of each attachment
                    println("Record Attachment LinkUrl: " + attachment.getlinkUrl())
                  }
                }
                else println(keyName + ": " + value)
              }
              else if (value.isInstanceOf[Record]) {
                val recordValue = value.asInstanceOf[Record]
                println("Record " + keyName + " ID: " + recordValue.getId)
                println("Record " + keyName + " Name: " + recordValue.getKeyValue("name"))
              }
              else if (value.isInstanceOf[Layout]) {
                val layout = value.asInstanceOf[Layout]
                if (layout != null) {
                  println("Record " + keyName + " ID: " + layout.getId)
                  println("Record " + keyName + " Name: " + layout.getName)
                }
              }
              else if (value.isInstanceOf[User]) {
                val user = value.asInstanceOf[User]
                if (user != null) {
                  println("Record " + keyName + " User-ID: " + user.getId)
                  println("Record " + keyName + " User-Name: " + user.getName)
                  println("Record " + keyName + " User-Email: " + user.getEmail)
                }
              }
              else if (value.isInstanceOf[Choice[_]]) println(keyName + ": " + value.asInstanceOf[Choice[_]].getValue)
              else if (value.isInstanceOf[RemindAt]) println(keyName + ": " + value.asInstanceOf[RemindAt].getAlarm)
              else if (value.isInstanceOf[RecurringActivity]) {
                println(keyName)
                println("RRULE" + ": " + value.asInstanceOf[RecurringActivity].getRrule)
              }
              else if (value.isInstanceOf[Consent]) {
                val consent = value.asInstanceOf[Consent]
                println("Record Consent ID: " + consent.getId)
                //Get the Owner User instance of each attachment
                val ownerOption = consent.getOwner
                if (ownerOption.isDefined) { //Get the name of the owner User
                  var owner = ownerOption.get
                  println("Record Consent Owner Name: " + owner.getName)
                  //Get the ID of the owner User
                  println("Record Consent Owner ID: " + owner.getId)
                  //Get the Email of the owner User
                  println("Record Consent Owner Email: " + owner.getEmail)
                }
                val consentCreatedByOption = consent.getCreatedBy
                if (consentCreatedByOption.isDefined) { //Get the name of the CreatedBy User
                  var consentCreatedBy = consentCreatedByOption.get
                  println("Record Consent CreatedBy Name: " + consentCreatedBy.getName)
                  //Get the ID of the CreatedBy User
                  println("Record Consent CreatedBy ID: " + consentCreatedBy.getId)
                  //Get the Email of the CreatedBy User
                  println("Record Consent CreatedBy Email: " + consentCreatedBy.getEmail)
                }
                val consentModifiedByOption = consent.getModifiedBy
                if (consentModifiedByOption.isDefined) { //Get the name of the ModifiedBy User
                  var consentModifiedBy = consentModifiedByOption.get
                  println("Record Consent ModifiedBy Name: " + consentModifiedBy.getName)
                  //Get the ID of the ModifiedBy User
                  println("Record Consent ModifiedBy ID: " + consentModifiedBy.getId)
                  //Get the Email of the ModifiedBy User
                  println("Record Consent ModifiedBy Email: " + consentModifiedBy.getEmail)
                }
                println("Record Consent CreatedTime: " + consent.getCreatedTime)
                println("Record Consent ModifiedTime: " + consent.getModifiedTime)
                println("Record Consent ContactThroughEmail: " + consent.getContactThroughEmail)
                println("Record Consent ContactThroughSocial: " + consent.getContactThroughSocial)
                println("Record Consent ContactThroughSurvey: " + consent.getContactThroughSurvey)
                println("Record Consent ContactThroughPhone: " + consent.getContactThroughPhone)
                println("Record Consent MailSentTime: " + consent.getMailSentTime.toString)
                println("Record Consent ConsentDate: " + consent.getConsentDate.toString)
                println("Record Consent ConsentRemarks: " + consent.getConsentRemarks)
                println("Record Consent ConsentThrough: " + consent.getConsentThrough)
                println("Record Consent DataProcessingBasis: " + consent.getDataProcessingBasis)
                //To get custom values
                println("Record Consent Lawful Reason: " + consent.getKeyValue("Lawful_Reason"))
              }
              else println(keyName + ": " + value)
            })
          }
        }

        else { //Check if the request returned an exception
          if (responseHandler.isInstanceOf[APIException]) { //Get the received APIException instance
            val exception = responseHandler.asInstanceOf[APIException]
            //Get the Status
            println("Status: " + exception.getStatus.getValue)
            //Get the Code
            println("Code: " + exception.getCode.getValue)
            println("Details: ")

            exception.getDetails.foreach(entry=>{
              println(entry._1 + ": " + entry._2)
            })
            //Get the Message
            println("Message: " + exception.getMessage.getValue)
          }
        }
      }
      else { //If response is not as expected
        //Get model object from response
        val responseObject = response.getModel
        //Get the response object's class
        val clas = responseObject.getClass
        //Get all declared fields of the response class
        val fields = clas.getDeclaredFields
        for (field <- fields) { //Get each value
          println(field.getName + ":" + field.get(responseObject))
        }
      }
    }
  }
}
 
Update Related Records Using External ID

              
package com.zoho.crm.sample.relatedrecords

import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
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.{Comment, Consent, FileDetails, InventoryLineItems, LineTax, Participants, PricingDetails, Record, RecurringActivity, RemindAt}
import com.zoho.crm.api.relatedrecords.FileBodyWrapper
import com.zoho.crm.api.relatedrecords.APIException
import com.zoho.crm.api.relatedrecords.ActionHandler
import com.zoho.crm.api.relatedrecords.ActionResponse
import com.zoho.crm.api.relatedrecords.ActionWrapper
import com.zoho.crm.api.relatedrecords.BodyWrapper
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.DelinkRecordsParam
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsParam
import com.zoho.crm.api.relatedrecords.ResponseHandler
import com.zoho.crm.api.relatedrecords.ResponseWrapper
import com.zoho.crm.api.relatedrecords.SuccessResponse
import com.zoho.crm.api.tags.Tag
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 Relatedrecord {
/**
   *  Update Related Records Using External Id
   * This method is used to update the relation between the records and print the response.
   *
   * @param moduleAPIName      - The API Name of the module to update related records.
   * @param externalValue      -
   * @param relatedListAPIName - The API name of the related list. To get the API name of the related list.
   * @throws Exception
   */
  @throws[Exception]
  def updateRelatedRecordsUsingExternalId(moduleAPIName: String, externalValue: String, relatedListAPIName: String): Unit = { //API Name of the module
    val xExternal = "Leads.External,Products.Products_External"
    val relatedRecordsOperations = new RelatedRecordsOperations(relatedListAPIName, moduleAPIName, Option(xExternal))
    //Get instance of BodyWrapper Class that will contain the request body
    val request = new BodyWrapper
    //List of Record instances
    val records = new ArrayBuffer[Record]
    //Get instance of Record Class
    val record1 = new Record
    /*
      * Call addKeyValue method that takes two arguments
      * 1 -> A string that is the Field's API Name
      * 2 -> Value
      */
    record1.addKeyValue("Products_External", "TestExternalLead121")
    record1.addKeyValue("Note_Content", "asd")
    //Add Record instance to the list
    records.addOne(record1)
    val record2 = new Record
    record2.addKeyValue("Products_External", "TestExternal122")
    record2.addKeyValue("Note_Content", "asd")
    records.addOne(record2)
    //Set the list to Records in BodyWrapper instance
    request.setData(records)
    //Call updateRelatedRecordsUsingExternalId method that takes externalValue and BodyWrapper instance as parameter.
    val responseOption = relatedRecordsOperations.updateRelatedRecordsUsingExternalId(externalValue, request)
    if (responseOption.isDefined) {
      var response = responseOption.get
      println("Status Code: " + response.getStatusCode)
      if (response.isExpected) {
        val actionHandler = response.getObject
        if (actionHandler.isInstanceOf[ActionWrapper]) { //Get the received ActionWrapper instance
          val actionWrapper = actionHandler.asInstanceOf[ActionWrapper]
          //Get the list of obtained ActionResponse instances
          val actionResponses = actionWrapper.getData

          for (actionResponse <- actionResponses) { //Check if the request is successful
            if (actionResponse.isInstanceOf[SuccessResponse]) { //Get the received SuccessResponse instance
              val successResponse = actionResponse.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 (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 <- fields) {
          println(field.getName + ":" + field.get(responseObject))
        }
      }
    }
  }
}
 
Delete Related Records Using External ID

              
package com.zoho.crm.sample.relatedrecords

import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
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.{Comment, Consent, FileDetails, InventoryLineItems, LineTax, Participants, PricingDetails, Record, RecurringActivity, RemindAt}
import com.zoho.crm.api.relatedrecords.FileBodyWrapper
import com.zoho.crm.api.relatedrecords.APIException
import com.zoho.crm.api.relatedrecords.ActionHandler
import com.zoho.crm.api.relatedrecords.ActionResponse
import com.zoho.crm.api.relatedrecords.ActionWrapper
import com.zoho.crm.api.relatedrecords.BodyWrapper
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.DelinkRecordsParam
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsParam
import com.zoho.crm.api.relatedrecords.ResponseHandler
import com.zoho.crm.api.relatedrecords.ResponseWrapper
import com.zoho.crm.api.relatedrecords.SuccessResponse
import com.zoho.crm.api.tags.Tag
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 Relatedrecord {
/**
   *  Delete RelatedRecords Using External Id 
   * This method is used to delete the association between modules and print the response.
   *
   * @param moduleAPIName      - The API Name of the module to delink related records.
   * @param externalValue      -
   * @param relatedListAPIName - The API name of the related list. To get the API name of the related list.
   * @param relatedListIds     - The List of related record IDs.
   * @throws Exception
   */
  @throws[Exception]
  def deleteRelatedRecordsUsingExternalId(moduleAPIName: String, externalValue: String, relatedListAPIName: String, relatedListIds: ArrayBuffer[String]): Unit = { //List<Long> relatedListIds = new ArrayList<Long>(Arrays.asList(3477061919001l, 34770617011l))
    val xExternal = "Leads.External,Products.Products_External"
    val relatedRecordsOperations = new RelatedRecordsOperations(relatedListAPIName, moduleAPIName, Option(xExternal))
    val paramInstance = new ParameterMap

    for (relatedListId <- relatedListIds) {
      paramInstance.add(new DelinkRecordsParam().ids, relatedListId)
    }
    //Call deleteRelatedRecordsUsingExternalId method that takes externalValue and paramInstance instance as parameter.
    val responseOption = relatedRecordsOperations.deleteRelatedRecordsUsingExternalId(externalValue, Option(paramInstance))
    if (responseOption.isDefined) {
      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 <- actionResponses) {
            if (actionResponse.isInstanceOf[SuccessResponse]) {
              val successResponse = actionResponse.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 (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 <- fields) {
          println(field.getName + ":" + field.get(responseObject))
        }
      }
    }
  }
}
 
Get Related Record Using External ID

              
package com.zoho.crm.sample.relatedrecords

import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
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.{Comment, Consent, FileDetails, InventoryLineItems, LineTax, Participants, PricingDetails, Record, RecurringActivity, RemindAt}
import com.zoho.crm.api.relatedrecords.FileBodyWrapper
import com.zoho.crm.api.relatedrecords.APIException
import com.zoho.crm.api.relatedrecords.ActionHandler
import com.zoho.crm.api.relatedrecords.ActionResponse
import com.zoho.crm.api.relatedrecords.ActionWrapper
import com.zoho.crm.api.relatedrecords.BodyWrapper
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.DelinkRecordsParam
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsParam
import com.zoho.crm.api.relatedrecords.ResponseHandler
import com.zoho.crm.api.relatedrecords.ResponseWrapper
import com.zoho.crm.api.relatedrecords.SuccessResponse
import com.zoho.crm.api.tags.Tag
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 Relatedrecord {
/**
   *  Get Related Record Using External Id 
   * This method is used to get the single related list record and print the response.
   *
   * @param moduleAPIName      - The API Name of the module to get related record.
   * @param externalValue      -
   * @param relatedListAPIName - The API name of the related list. To get the API name of the related list.
   * @param externalFieldValue -
   * @param destinationFolder  - The absolute path of the destination folder to store the file.
   * @throws Exception
   */
  @throws[Exception]
  def getRelatedRecordUsingExternalId(moduleAPIName: String, externalValue: String, relatedListAPIName: String, externalFieldValue: String, destinationFolder: String): Unit = { //Long relatedListId = 3477061994115l
    val xExternal = "Leads.External,Products.Products_External"
    val relatedRecordsOperations = new RelatedRecordsOperations(relatedListAPIName, moduleAPIName, Option(xExternal))
    val headerInstance = new HeaderMap
    val startdatetime = OffsetDateTime.of(2019, 6, 1, 10, 0, 1, 0, ZoneOffset.of("+05:30"))
    headerInstance.add(new GetRelatedRecordHeader().IfModifiedSince, startdatetime)
    //Call getRelatedRecordUsingExternalId method that takes headerInstance and relatedRecordId as parameter
    val responseOption = relatedRecordsOperations.getRelatedRecordUsingExternalId(externalFieldValue, externalValue, 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 Record instances
          val records = responseWrapper.getData

          for (record <- records) { //Get the ID of each Record
            println("Record ID: " + record.getId)
            //Get the createdBy User instance of each Record
            var createdByOption = record.getCreatedBy
            //Check if createdBy is not null
            if (createdByOption.isDefined) { //Get the ID of the createdBy User
              var createdBy = createdByOption.get
              println("Record Created By User-ID: " + createdBy.getId)
              //Get the name of the createdBy User
              println("Record Created By User-Name: " + createdBy.getName)
              //Get the Email of the createdBy User
              println("Record Created By User-Email: " + createdBy.getEmail)
            }
            //Get the CreatedTime of each Record
            println("Record CreatedTime: " + record.getCreatedTime)
            //Get the modifiedBy User instance of each Record
            var modifiedByOption = record.getModifiedBy
            //Check if modifiedBy is not null
            if (modifiedByOption.isDefined) { //Get the ID of the modifiedBy User
              var modifiedBy =modifiedByOption.get
              println("Record Modified By User-ID: " + modifiedBy.getId)
              //Get the name of the modifiedBy User
              println("Record Modified By User-Name: " + modifiedBy.getName)
              //Get the Email of the modifiedBy User
              println("Record Modified By User-Email: " + modifiedBy.getEmail)
            }
            //Get the ModifiedTime of each Record
            println("Record ModifiedTime: " + record.getModifiedTime)
            //Get the list of Tag instance each Record
            val tags = record.getTag
            //Check if tags is not null
            if (tags.length > 0) {

              for (tag <- tags) { //Get the Name of each Tag
                println("Record Tag Name: " + tag.getName)
                //Get the Id of each Tag
                println("Record Tag ID: " + tag.getId)
              }
            }
            //To get particular field value
            println("Record Field Value: " + record.getKeyValue("Last_Name")) // FieldApiName

            println("Record KeyValues: ")
            //Get the KeyValue map
            record.getKeyValues.foreach(entry=>{
              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 <- fileDetails) { //Get the Extn of each FileDetails
                    println("Record FileDetails Extn: " + fileDetail.getExtn)
                    //Get the IsPreviewAvailable of each FileDetails
                    println("Record FileDetails IsPreviewAvailable: " + fileDetail.getIsPreviewAvailable)
                    //Get the DownloadUrl of each FileDetails
                    println("Record FileDetails DownloadUrl: " + fileDetail.getDownloadUrl)
                    //Get the DeleteUrl of each FileDetails
                    println("Record FileDetails DeleteUrl: " + fileDetail.getDeleteUrl)
                    //Get the EntityId of each FileDetails
                    println("Record FileDetails EntityId: " + fileDetail.getEntityId)
                    //Get the Mode of each FileDetails
                    println("Record FileDetails Mode: " + fileDetail.getMode)
                    //Get the OriginalSizeByte of each FileDetails
                    println("Record FileDetails OriginalSizeByte: " + fileDetail.getOriginalSizeByte)
                    //Get the PreviewUrl of each FileDetails
                    println("Record FileDetails PreviewUrl: " + fileDetail.getPreviewUrl)
                    //Get the FileName of each FileDetails
                    println("Record FileDetails FileName: " + fileDetail.getFileName)
                    //Get the FileId of each FileDetails
                    println("Record FileDetails FileId: " + fileDetail.getFileId)
                    //Get the AttachmentId of each FileDetails
                    println("Record FileDetails AttachmentId: " + fileDetail.getAttachmentId)
                    //Get the FileSize of each FileDetails
                    println("Record FileDetails FileSize: " + fileDetail.getFileSize)
                    //Get the CreatorId of each FileDetails
                    println("Record FileDetails CreatorId: " + fileDetail.getCreatorId)
                    //Get the LinkDocs of each FileDetails
                    println("Record FileDetails LinkDocs: " + fileDetail.getLinkDocs)
                  }
                }
                else if (dataList(0).isInstanceOf[Choice[_]]) {
                  @SuppressWarnings(Array("unchecked")) val choiceList = dataList.asInstanceOf[(ArrayBuffer[Choice[_$1]]) forSome {type _$1}]
                  println(keyName)
                  println("values")

                  for (choice <- choiceList) {
                    println(choice.getValue)
                  }
                }
                else if (dataList(0).isInstanceOf[InventoryLineItems]) {
                  @SuppressWarnings(Array("unchecked")) val productDetails = value.asInstanceOf[ArrayBuffer[InventoryLineItems]]

                  for (productDetail <- productDetails) {
                    val lineItemProductOption = productDetail.getProduct
                    if (lineItemProductOption.isDefined) {
                      val lineItemProduct= lineItemProductOption.get
                      println("Record ProductDetails LineItemProduct ProductCode: " + lineItemProduct.getProductCode)
                      println("Record ProductDetails LineItemProduct Currency: " + lineItemProduct.getCurrency)
                      println("Record ProductDetails LineItemProduct Name: " + lineItemProduct.getName)
                      println("Record ProductDetails LineItemProduct Id: " + lineItemProduct.getId)
                    }
                    println("Record ProductDetails Quantity: " + productDetail.getQuantity.toString)
                    println("Record ProductDetails Discount: " + productDetail.getDiscount)
                    println("Record ProductDetails TotalAfterDiscount: " + productDetail.getTotalAfterDiscount.toString)
                    println("Record ProductDetails NetTotal: " + productDetail.getNetTotal.toString)
                    if (productDetail.getBook.isDefined) println("Record ProductDetails Book: " + productDetail.getBook.toString)
                    println("Record ProductDetails Tax: " + productDetail.getTax.toString)
                    println("Record ProductDetails ListPrice: " + productDetail.getListPrice.toString)
                    println("Record ProductDetails UnitPrice: " + productDetail.getUnitPrice)
                    println("Record ProductDetails QuantityInStock: " + productDetail.getQuantityInStock.toString)
                    println("Record ProductDetails Total: " + productDetail.getTotal.toString)
                    println("Record ProductDetails ID: " + productDetail.getId)
                    println("Record ProductDetails ProductDescription: " + productDetail.getProductDescription)
                    val lineTaxes = productDetail.getLineTax

                    for (lineTax <- lineTaxes) {
                      println("Record ProductDetails LineTax Percentage: " + lineTax.getPercentage.toString)
                      println("Record ProductDetails LineTax Name: " + lineTax.getName)
                      println("Record ProductDetails LineTax Id: " + lineTax.getId)
                      println("Record ProductDetails LineTax Value: " + lineTax.getValue.toString)
                    }
                  }
                }
                else if (dataList(0).isInstanceOf[Tag]) {
                  @SuppressWarnings(Array("unchecked")) val tagList = value.asInstanceOf[ArrayBuffer[Tag]]

                  for (tag <- tagList) {
                    println("Record Tag Name: " + tag.getName)
                    println("Record Tag ID: " + tag.getId)
                  }
                }
                else if (dataList(0).isInstanceOf[PricingDetails]) {
                  @SuppressWarnings(Array("unchecked")) val pricingDetails = value.asInstanceOf[ ArrayBuffer[PricingDetails]]

                  for (pricingDetail <- pricingDetails) {
                    println("Record PricingDetails ToRange: " + pricingDetail.getToRange.toString)
                    println("Record PricingDetails Discount: " + pricingDetail.getDiscount.toString)
                    println("Record PricingDetails ID: " + pricingDetail.getId)
                    println("Record PricingDetails FromRange: " + pricingDetail.getFromRange.toString)
                  }
                }
                else if(dataList(0).isInstanceOf[Participants])
                {
                  val participants = value.asInstanceOf[ ArrayBuffer[Participants]]
                  for (participant <- participants) {
                    println("Record Participants Name: " + participant.getName().toString)
                    println("Record Participants Invited: " + participant.getInvited().toString())
                    println("Record Participants ID: " + participant.getId().toString)
                    println("Record Participants Type: " + participant.getType().toString)
                    println("Record Participants Participant: " + participant.getParticipant().toString)
                    println("Record Participants Status: " + participant.getStatus().toString)
                  }
                }
                else if (dataList(0).isInstanceOf[Record]) {
                  @SuppressWarnings(Array("unchecked")) val recordList = dataList.asInstanceOf[ ArrayBuffer[Record]]

                  for (record1 <- recordList) { //Get the details map


                    record1.getKeyValues.foreach(entry=>{
                      println(entry._1 + ": " + entry._2)
                    })
                  }
                }
                else if (dataList(0).isInstanceOf[LineTax]) {
                  @SuppressWarnings(Array("unchecked")) val lineTaxes = dataList.asInstanceOf[ ArrayBuffer[LineTax]]

                  for (lineTax <- lineTaxes) {
                    println("Record ProductDetails LineTax Percentage: " + lineTax.getPercentage.toString)
                    println("Record ProductDetails LineTax Name: " + lineTax.getName)
                    println("Record ProductDetails LineTax Id: " + lineTax.getId)
                    println("Record ProductDetails LineTax Value: " + lineTax.getValue.toString)
                  }
                }
                else if (dataList(0).isInstanceOf[Comment]) {
                  @SuppressWarnings(Array("unchecked")) val comments = dataList.asInstanceOf[ ArrayBuffer[Comment]]

                  for (comment <- comments) {
                    println("Record Comment CommentedBy: " + comment.getCommentedBy)
                    println("Record Comment CommentedTime: " + comment.getCommentedTime.toString)
                    println("Record Comment CommentContent: " + comment.getCommentContent)
                    println("Record Comment Id: " + comment.getId)
                  }
                }
                else if (dataList(0).isInstanceOf[Attachment]) { //Get the list of obtained Attachment instances
                  @SuppressWarnings(Array("unchecked")) val attachments = dataList.asInstanceOf[ ArrayBuffer[Attachment]]


                  for (attachment <- attachments) { //Get the owner User instance of each attachment
                    val ownerOption = attachment.getOwner
                    //Check if owner is not null
                    if (ownerOption.isDefined) { //Get the Name of the Owner
                      var owner = ownerOption.get
                      println("Record Attachment Owner User-Name: " + owner.getName)
                      //Get the ID of the Owner
                      println("Record Attachment Owner User-ID: " + owner.getId)
                      //Get the Email of the Owner
                      println("Record Attachment Owner User-Email: " + owner.getEmail)
                    }
                    //Get the modified time of each attachment
                    println("Record Attachment Modified Time: " + attachment.getModifiedTime.toString)
                    //Get the name of the File
                    println("Record Attachment File Name: " + attachment.getFileName)
                    //Get the created time of each attachment
                    println("Record Attachment Created Time: " + attachment.getCreatedTime.toString)
                    //Get the Attachment file size
                    println("Record Attachment File Size: " + attachment.getSize.toString)
                    //Get the parentId Record instance of each attachment
                    val parentIdOption = attachment.getParentId
                    //Check if parentId is not null
                    if (parentIdOption.isDefined) { //Get the parent record Name of each attachment
                      var parentId =parentIdOption.get
                      println("Record Attachment parent record Name: " + parentId.getKeyValue("name"))
                      //Get the parent record ID of each attachment
                      println("Record Attachment parent record ID: " + parentId.getId)
                    }
                    //Get the attachment is Editable
                    println("Record Attachment is Editable: " + attachment.geteditable().toString)
                    //Get the file ID of each attachment
                    println("Record Attachment File ID: " + attachment.getfileId())
                    //Get the type of each attachment
                    println("Record Attachment File Type: " + attachment.gettype)
                    //Get the seModule of each attachment
                    println("Record Attachment seModule: " + attachment.getseModule())
                    //Get the modifiedBy User instance of each attachment
                    var modifiedByOption = attachment.getModifiedBy
                    if (modifiedByOption.isDefined) { //Get the Name of the modifiedBy User
                      var modifiedBy = modifiedByOption.get
                      println("Record Attachment Modified By User-Name: " + modifiedBy.getName)
                      println("Record Attachment Modified By User-ID: " + modifiedBy.getId)
                      println("Record Attachment Modified By User-Email: " + modifiedBy.getEmail)
                    }
                    //Get the state of each attachment
                    println("Record Attachment State: " + attachment.getstate)
                    //Get the ID of each attachment
                    println("Record Attachment ID: " + attachment.getId)
                    //Get the createdBy User instance of each attachment
                    var createdByOption = attachment.getCreatedBy
                    if (createdByOption.isDefined) {
                      var createdBy = modifiedByOption.get

                      println("Record Attachment Created By User-Name: " + createdBy.getName)
                      println("Record Attachment Created By User-ID: " + createdBy.getId)
                      println("Record Attachment Created By User-Email: " + createdBy.getEmail)
                    }
                    //Get the linkUrl of each attachment
                    println("Record Attachment LinkUrl: " + attachment.getlinkUrl())
                  }
                }
                else println(keyName + ": " + value)
              }
              else if (value.isInstanceOf[Record]) {
                val recordValue = value.asInstanceOf[Record]
                println("Record " + keyName + " ID: " + recordValue.getId)
                println("Record " + keyName + " Name: " + recordValue.getKeyValue("name"))
              }
              else if (value.isInstanceOf[Layout]) {
                val layout = value.asInstanceOf[Layout]
                if (layout != null) {
                  println("Record " + keyName + " ID: " + layout.getId)
                  println("Record " + keyName + " Name: " + layout.getName)
                }
              }
              else if (value.isInstanceOf[User]) {
                val user = value.asInstanceOf[User]
                if (user != null) {
                  println("Record " + keyName + " User-ID: " + user.getId)
                  println("Record " + keyName + " User-Name: " + user.getName)
                  println("Record " + keyName + " User-Email: " + user.getEmail)
                }
              }
              else if (value.isInstanceOf[Choice[_]]) println(keyName + ": " + value.asInstanceOf[Choice[_]].getValue)
              else if (value.isInstanceOf[RemindAt]) println(keyName + ": " + value.asInstanceOf[RemindAt].getAlarm)
              else if (value.isInstanceOf[RecurringActivity]) {
                println(keyName)
                println("RRULE" + ": " + value.asInstanceOf[RecurringActivity].getRrule)
              }
              else if (value.isInstanceOf[Consent]) {
                val consent = value.asInstanceOf[Consent]
                println("Record Consent ID: " + consent.getId)
                //Get the Owner User instance of each attachment
                val ownerOption = consent.getOwner
                if (ownerOption.isDefined) { //Get the name of the owner User
                  var owner = ownerOption.get
                  println("Record Consent Owner Name: " + owner.getName)
                  //Get the ID of the owner User
                  println("Record Consent Owner ID: " + owner.getId)
                  //Get the Email of the owner User
                  println("Record Consent Owner Email: " + owner.getEmail)
                }
                val consentCreatedByOption = consent.getCreatedBy
                if (consentCreatedByOption.isDefined) { //Get the name of the CreatedBy User
                  var consentCreatedBy = consentCreatedByOption.get
                  println("Record Consent CreatedBy Name: " + consentCreatedBy.getName)
                  //Get the ID of the CreatedBy User
                  println("Record Consent CreatedBy ID: " + consentCreatedBy.getId)
                  //Get the Email of the CreatedBy User
                  println("Record Consent CreatedBy Email: " + consentCreatedBy.getEmail)
                }
                val consentModifiedByOption = consent.getModifiedBy
                if (consentModifiedByOption.isDefined) { //Get the name of the ModifiedBy User
                  var consentModifiedBy = consentModifiedByOption.get
                  println("Record Consent ModifiedBy Name: " + consentModifiedBy.getName)
                  //Get the ID of the ModifiedBy User
                  println("Record Consent ModifiedBy ID: " + consentModifiedBy.getId)
                  //Get the Email of the ModifiedBy User
                  println("Record Consent ModifiedBy Email: " + consentModifiedBy.getEmail)
                }
                println("Record Consent CreatedTime: " + consent.getCreatedTime)
                println("Record Consent ModifiedTime: " + consent.getModifiedTime)
                println("Record Consent ContactThroughEmail: " + consent.getContactThroughEmail)
                println("Record Consent ContactThroughSocial: " + consent.getContactThroughSocial)
                println("Record Consent ContactThroughSurvey: " + consent.getContactThroughSurvey)
                println("Record Consent ContactThroughPhone: " + consent.getContactThroughPhone)
                println("Record Consent MailSentTime: " + consent.getMailSentTime.toString)
                println("Record Consent ConsentDate: " + consent.getConsentDate.toString)
                println("Record Consent ConsentRemarks: " + consent.getConsentRemarks)
                println("Record Consent ConsentThrough: " + consent.getConsentThrough)
                println("Record Consent DataProcessingBasis: " + consent.getDataProcessingBasis)
                //To get custom values
                println("Record Consent Lawful Reason: " + consent.getKeyValue("Lawful_Reason"))
              }
              else println(keyName + ": " + value)
            })
          }
        }
        else if (responseHandler.isInstanceOf[FileBodyWrapper]) {
          val fileBodyWrapper = responseHandler.asInstanceOf[FileBodyWrapper]
          //Get StreamWrapper instance from the returned FileBodyWrapper instance
          val streamWrapper = fileBodyWrapper.getFile.get
          //Create a file instance with the absolute_file_path
          val file = new File(destinationFolder + File.separatorChar + streamWrapper.getName.get)
          //Get InputStream from the response
          val is = streamWrapper.getStream.get
          //Create an OutputStream for the destination file
          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)) != -1
          }) { //write data to OutputStream
            os.write(buffer, 0, bytesRead)
          }
          //Close the InputStream
          is.close()
          //Flush and close the OutputStream
          os.flush()
          os.close()
        }
        else { //Check if the request returned an exception
          if (responseHandler.isInstanceOf[APIException]) { //Get the received APIException instance
            val exception = responseHandler.asInstanceOf[APIException]
            //Get the Status
            println("Status: " + exception.getStatus.getValue)
            //Get the Code
            println("Code: " + exception.getCode.getValue)
            println("Details: ")

            exception.getDetails.foreach(entry=>{
              println(entry._1 + ": " + entry._2)
            })
            //Get the Message
            println("Message: " + exception.getMessage.getValue)
          }
        }
      }
      else { //If response is not as expected
        //Get model object from response
        val responseObject = response.getModel
        //Get the response object's class
        val clas = responseObject.getClass
        //Get all declared fields of the response class
        val fields = clas.getDeclaredFields
        for (field <- fields) { //Get each value
          println(field.getName + ":" + field.get(responseObject))
        }
      }
    }
  }
}
 
Update Related Record Using External ID

              
package com.zoho.crm.sample.relatedrecords

import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
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.{Comment, Consent, FileDetails, InventoryLineItems, LineTax, Participants, PricingDetails, Record, RecurringActivity, RemindAt}
import com.zoho.crm.api.relatedrecords.FileBodyWrapper
import com.zoho.crm.api.relatedrecords.APIException
import com.zoho.crm.api.relatedrecords.ActionHandler
import com.zoho.crm.api.relatedrecords.ActionResponse
import com.zoho.crm.api.relatedrecords.ActionWrapper
import com.zoho.crm.api.relatedrecords.BodyWrapper
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.DelinkRecordsParam
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsParam
import com.zoho.crm.api.relatedrecords.ResponseHandler
import com.zoho.crm.api.relatedrecords.ResponseWrapper
import com.zoho.crm.api.relatedrecords.SuccessResponse
import com.zoho.crm.api.tags.Tag
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 Relatedrecord {
/**
   *  Update Related Record Using External Id 
   * This method is used to update the relation between the records and print the response.
   *
   * @param moduleAPIName      - The API Name of the module to update related record.
   * @param externalValue      -
   * @param relatedListAPIName - The API name of the related list. To get the API name of the related list.
   * @param externalFieldValue -
   * @throws Exception
   */
  @throws[Exception]
  def updateRelatedRecordUsingExternalId(moduleAPIName: String, externalValue: String, relatedListAPIName: String, externalFieldValue: String): Unit = {
    val xExternal = "Leads.External,Products.Products_External"
    val relatedRecordsOperations =new RelatedRecordsOperations(relatedListAPIName, moduleAPIName, Option(xExternal))
    val request = new BodyWrapper
    val records = new ArrayBuffer[Record]
    val record1 = new Record
    record1.addKeyValue("Note_Content", "asd")
    records.addOne(record1)
    request.setData(records)
    //Call updateRelatedRecordUsingExternalId method that takes externalFieldValue, externalValue and BodyWrapper instance as parameter.
    val responseOption = relatedRecordsOperations.updateRelatedRecordUsingExternalId(externalFieldValue, externalValue, request)
    if (responseOption.isDefined) {
      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 <- actionResponses) {
            if (actionResponse.isInstanceOf[SuccessResponse]) {
              val successResponse = actionResponse.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 (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 <- fields) {
          println(field.getName + ":" + field.get(responseObject))
        }
      }
    }
  }
}
 
Delete Related Record Using External ID

              
package com.zoho.crm.sample.relatedrecords

import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
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.{Comment, Consent, FileDetails, InventoryLineItems, LineTax, Participants, PricingDetails, Record, RecurringActivity, RemindAt}
import com.zoho.crm.api.relatedrecords.FileBodyWrapper
import com.zoho.crm.api.relatedrecords.APIException
import com.zoho.crm.api.relatedrecords.ActionHandler
import com.zoho.crm.api.relatedrecords.ActionResponse
import com.zoho.crm.api.relatedrecords.ActionWrapper
import com.zoho.crm.api.relatedrecords.BodyWrapper
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.DelinkRecordsParam
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsParam
import com.zoho.crm.api.relatedrecords.ResponseHandler
import com.zoho.crm.api.relatedrecords.ResponseWrapper
import com.zoho.crm.api.relatedrecords.SuccessResponse
import com.zoho.crm.api.tags.Tag
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 Relatedrecord {
/**
     *  Delete Related Record Using External Id 
   * This method is used to delete the association between modules and print the response.
   *
   * @param moduleAPIName      - The API Name of the module to delink related record.
   * @param externalValue      -
   * @param relatedListAPIName - The API name of the related list. To get the API name of the related list.
   * @param externalFieldValue -
   * @throws Exception
   */
  @throws[Exception]
  def deleteRelatedRecordUsingExternalId(moduleAPIName: String, externalValue: String, relatedListAPIName: String, externalFieldValue: String): Unit = {
    val xExternal = &quot;Leads.External,Products.Products_External&quot;
    val relatedRecordsOperations = new RelatedRecordsOperations(relatedListAPIName, moduleAPIName, Option(xExternal))
    //Call deleteRelatedRecordUsingExternalId method that takes relatedListId as parameter.
    val responseOption = relatedRecordsOperations.deleteRelatedRecordUsingExternalId(externalFieldValue, externalValue)
    if (responseOption.isDefined) {
      var response= responseOption.get
      println(&quot;Status Code: &quot; + response.getStatusCode)
      if (response.isExpected) {
        val actionHandler = response.getObject
        if (actionHandler.isInstanceOf[ActionWrapper]) {
          val actionWrapper = actionHandler.asInstanceOf[ActionWrapper]
          val actionResponses = actionWrapper.getData

          for (actionResponse &lt;- actionResponses) {
            if (actionResponse.isInstanceOf[SuccessResponse]) {
              val successResponse = actionResponse.asInstanceOf[SuccessResponse]
              println(&quot;Status: &quot; + successResponse.getStatus.getValue)
              println(&quot;Code: &quot; + successResponse.getCode.getValue)
              println(&quot;Details: &quot;)

              successResponse.getDetails.foreach(entry=&gt;{
                println(entry._1 + &quot;: &quot; + entry._2)
              })
              println(&quot;Message: &quot; + successResponse.getMessage.getValue)
            }
            else if (actionResponse.isInstanceOf[APIException]) {
              val exception = actionResponse.asInstanceOf[APIException]
              println(&quot;Status: &quot; + exception.getStatus.getValue)
              println(&quot;Code: &quot; + exception.getCode.getValue)
              println(&quot;Details: &quot;)

              exception.getDetails.foreach(entry=&gt;{
                println(entry._1 + &quot;: &quot; + entry._2)
              })
              println(&quot;Message: &quot; + exception.getMessage.getValue)
            }
          }
        }
        else if (actionHandler.isInstanceOf[APIException]) {
          val exception = actionHandler.asInstanceOf[APIException]
          println(&quot;Status: &quot; + exception.getStatus.getValue)
          println(&quot;Code: &quot; + exception.getCode.getValue)
          println(&quot;Details: &quot;)

          exception.getDetails.foreach(entry=&gt;{
            println(entry._1 + &quot;: &quot; + entry._2)
          })
          println(&quot;Message: &quot; + exception.getMessage.getValue)
        }
      }
      else {
        val responseObject = response.getModel
        val clas = responseObject.getClass
        val fields = clas.getDeclaredFields
        for (field &lt;- fields) {
          println(field.getName + &quot;:&quot; + field.get(responseObject))
        }
      }
    }
  }
}
 
Get a Related Record

              
package com.zoho.crm.sample.relatedrecords

import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
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.{Comment, Consent, FileDetails, InventoryLineItems, LineTax, Participants, PricingDetails, Record, RecurringActivity, RemindAt}
import com.zoho.crm.api.relatedrecords.FileBodyWrapper
import com.zoho.crm.api.relatedrecords.APIException
import com.zoho.crm.api.relatedrecords.ActionHandler
import com.zoho.crm.api.relatedrecords.ActionResponse
import com.zoho.crm.api.relatedrecords.ActionWrapper
import com.zoho.crm.api.relatedrecords.BodyWrapper
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.DelinkRecordsParam
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsParam
import com.zoho.crm.api.relatedrecords.ResponseHandler
import com.zoho.crm.api.relatedrecords.ResponseWrapper
import com.zoho.crm.api.relatedrecords.SuccessResponse
import com.zoho.crm.api.tags.Tag
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 Relatedrecord {
/**
   *  Get Related Record 
   * This method is used to get the single related list record and print the response.
   *
   * @param moduleAPIName      - The API Name of the module to get related record.
   * @param recordId           - The ID of the record to be get Related List.
   * @param relatedListAPIName - The API name of the related list. To get the API name of the related list.
   * @param relatedListId      - The ID of the related record.
   * @param destinationFolder  - The absolute path of the destination folder to store the file.
   * @throws Exception
   */
  @throws[Exception]
  def getRelatedRecord(moduleAPIName: String, recordId: Long, relatedListAPIName: String, relatedListId: Long, destinationFolder: String): Unit = { //Long relatedListId = 3477061994115l
    val relatedRecordsOperations = new RelatedRecordsOperations(relatedListAPIName, moduleAPIName)
    val headerInstance = new HeaderMap
    val startdatetime = OffsetDateTime.of(2019, 6, 1, 10, 0, 1, 0, ZoneOffset.of("+05:30"))
    headerInstance.add(new GetRelatedRecordHeader().IfModifiedSince, startdatetime)
    //Call getRelatedRecord method that takes headerInstance and relatedRecordId as parameter
    val responseOption = relatedRecordsOperations.getRelatedRecord(relatedListId, recordId, 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 Record instances
          val records = responseWrapper.getData

          for (record <- records) { //Get the ID of each Record
            println("Record ID: " + record.getId)
            //Get the createdBy User instance of each Record
            var createdByOption = record.getCreatedBy
            //Check if createdBy is not null
            if (createdByOption.isDefined) { //Get the ID of the createdBy User
              var createdBy = createdByOption.get
              println("Record Created By User-ID: " + createdBy.getId)
              //Get the name of the createdBy User
              println("Record Created By User-Name: " + createdBy.getName)
              //Get the Email of the createdBy User
              println("Record Created By User-Email: " + createdBy.getEmail)
            }
            //Get the CreatedTime of each Record
            println("Record CreatedTime: " + record.getCreatedTime)
            //Get the modifiedBy User instance of each Record
            var modifiedByOption = record.getModifiedBy
            //Check if modifiedBy is not null
            if (modifiedByOption.isDefined) { //Get the ID of the modifiedBy User
              var modifiedBy =modifiedByOption.get
              println("Record Modified By User-ID: " + modifiedBy.getId)
              //Get the name of the modifiedBy User
              println("Record Modified By User-Name: " + modifiedBy.getName)
              //Get the Email of the modifiedBy User
              println("Record Modified By User-Email: " + modifiedBy.getEmail)
            }
            //Get the ModifiedTime of each Record
            println("Record ModifiedTime: " + record.getModifiedTime)
            //Get the list of Tag instance each Record
            val tags = record.getTag
            //Check if tags is not null
            if (tags.length > 0) {

              for (tag <- tags) { //Get the Name of each Tag
                println("Record Tag Name: " + tag.getName)
                //Get the Id of each Tag
                println("Record Tag ID: " + tag.getId)
              }
            }
            //To get particular field value
            println("Record Field Value: " + record.getKeyValue("Last_Name")) // FieldApiName

            println("Record KeyValues: ")
            //Get the KeyValue map
            record.getKeyValues.foreach(entry=>{
              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 <- fileDetails) { //Get the Extn of each FileDetails
                    println("Record FileDetails Extn: " + fileDetail.getExtn)
                    //Get the IsPreviewAvailable of each FileDetails
                    println("Record FileDetails IsPreviewAvailable: " + fileDetail.getIsPreviewAvailable)
                    //Get the DownloadUrl of each FileDetails
                    println("Record FileDetails DownloadUrl: " + fileDetail.getDownloadUrl)
                    //Get the DeleteUrl of each FileDetails
                    println("Record FileDetails DeleteUrl: " + fileDetail.getDeleteUrl)
                    //Get the EntityId of each FileDetails
                    println("Record FileDetails EntityId: " + fileDetail.getEntityId)
                    //Get the Mode of each FileDetails
                    println("Record FileDetails Mode: " + fileDetail.getMode)
                    //Get the OriginalSizeByte of each FileDetails
                    println("Record FileDetails OriginalSizeByte: " + fileDetail.getOriginalSizeByte)
                    //Get the PreviewUrl of each FileDetails
                    println("Record FileDetails PreviewUrl: " + fileDetail.getPreviewUrl)
                    //Get the FileName of each FileDetails
                    println("Record FileDetails FileName: " + fileDetail.getFileName)
                    //Get the FileId of each FileDetails
                    println("Record FileDetails FileId: " + fileDetail.getFileId)
                    //Get the AttachmentId of each FileDetails
                    println("Record FileDetails AttachmentId: " + fileDetail.getAttachmentId)
                    //Get the FileSize of each FileDetails
                    println("Record FileDetails FileSize: " + fileDetail.getFileSize)
                    //Get the CreatorId of each FileDetails
                    println("Record FileDetails CreatorId: " + fileDetail.getCreatorId)
                    //Get the LinkDocs of each FileDetails
                    println("Record FileDetails LinkDocs: " + fileDetail.getLinkDocs)
                  }
                }
                else if (dataList(0).isInstanceOf[Choice[_]]) {
                  @SuppressWarnings(Array("unchecked")) val choiceList = dataList.asInstanceOf[(ArrayBuffer[Choice[_$1]]) forSome {type _$1}]
                  println(keyName)
                  println("values")

                  for (choice <- choiceList) {
                    println(choice.getValue)
                  }
                }
                else if (dataList(0).isInstanceOf[InventoryLineItems]) {
                  @SuppressWarnings(Array("unchecked")) val productDetails = value.asInstanceOf[ArrayBuffer[InventoryLineItems]]

                  for (productDetail <- productDetails) {
                    val lineItemProductOption = productDetail.getProduct
                    if (lineItemProductOption.isDefined) {
                      val lineItemProduct= lineItemProductOption.get
                      println("Record ProductDetails LineItemProduct ProductCode: " + lineItemProduct.getProductCode)
                      println("Record ProductDetails LineItemProduct Currency: " + lineItemProduct.getCurrency)
                      println("Record ProductDetails LineItemProduct Name: " + lineItemProduct.getName)
                      println("Record ProductDetails LineItemProduct Id: " + lineItemProduct.getId)
                    }
                    println("Record ProductDetails Quantity: " + productDetail.getQuantity.toString)
                    println("Record ProductDetails Discount: " + productDetail.getDiscount)
                    println("Record ProductDetails TotalAfterDiscount: " + productDetail.getTotalAfterDiscount.toString)
                    println("Record ProductDetails NetTotal: " + productDetail.getNetTotal.toString)
                    if (productDetail.getBook.isDefined) println("Record ProductDetails Book: " + productDetail.getBook.toString)
                    println("Record ProductDetails Tax: " + productDetail.getTax.toString)
                    println("Record ProductDetails ListPrice: " + productDetail.getListPrice.toString)
                    println("Record ProductDetails UnitPrice: " + productDetail.getUnitPrice)
                    println("Record ProductDetails QuantityInStock: " + productDetail.getQuantityInStock.toString)
                    println("Record ProductDetails Total: " + productDetail.getTotal.toString)
                    println("Record ProductDetails ID: " + productDetail.getId)
                    println("Record ProductDetails ProductDescription: " + productDetail.getProductDescription)
                    val lineTaxes = productDetail.getLineTax

                    for (lineTax <- lineTaxes) {
                      println("Record ProductDetails LineTax Percentage: " + lineTax.getPercentage.toString)
                      println("Record ProductDetails LineTax Name: " + lineTax.getName)
                      println("Record ProductDetails LineTax Id: " + lineTax.getId)
                      println("Record ProductDetails LineTax Value: " + lineTax.getValue.toString)
                    }
                  }
                }
                else if (dataList(0).isInstanceOf[Tag]) {
                  @SuppressWarnings(Array("unchecked")) val tagList = value.asInstanceOf[ArrayBuffer[Tag]]

                  for (tag <- tagList) {
                    println("Record Tag Name: " + tag.getName)
                    println("Record Tag ID: " + tag.getId)
                  }
                }
                else if (dataList(0).isInstanceOf[PricingDetails]) {
                  @SuppressWarnings(Array("unchecked")) val pricingDetails = value.asInstanceOf[ ArrayBuffer[PricingDetails]]

                  for (pricingDetail <- pricingDetails) {
                    println("Record PricingDetails ToRange: " + pricingDetail.getToRange.toString)
                    println("Record PricingDetails Discount: " + pricingDetail.getDiscount.toString)
                    println("Record PricingDetails ID: " + pricingDetail.getId)
                    println("Record PricingDetails FromRange: " + pricingDetail.getFromRange.toString)
                  }
                }
                else if(dataList(0).isInstanceOf[Participants])
                {
                  val participants = value.asInstanceOf[ ArrayBuffer[Participants]]
                  for (participant <- participants) {
                    println("Record Participants Name: " + participant.getName().toString)
                    println("Record Participants Invited: " + participant.getInvited().toString())
                    println("Record Participants ID: " + participant.getId().toString)
                    println("Record Participants Type: " + participant.getType().toString)
                    println("Record Participants Participant: " + participant.getParticipant().toString)
                    println("Record Participants Status: " + participant.getStatus().toString)
                  }
                }
                else if (dataList(0).isInstanceOf[Record]) {
                  @SuppressWarnings(Array("unchecked")) val recordList = dataList.asInstanceOf[ ArrayBuffer[Record]]

                  for (record1 <- recordList) { //Get the details map


                    record1.getKeyValues.foreach(entry=>{
                      println(entry._1 + ": " + entry._2)
                    })
                  }
                }
                else if (dataList(0).isInstanceOf[LineTax]) {
                  @SuppressWarnings(Array("unchecked")) val lineTaxes = dataList.asInstanceOf[ ArrayBuffer[LineTax]]

                  for (lineTax <- lineTaxes) {
                    println("Record ProductDetails LineTax Percentage: " + lineTax.getPercentage.toString)
                    println("Record ProductDetails LineTax Name: " + lineTax.getName)
                    println("Record ProductDetails LineTax Id: " + lineTax.getId)
                    println("Record ProductDetails LineTax Value: " + lineTax.getValue.toString)
                  }
                }
                else if (dataList(0).isInstanceOf[Comment]) {
                  @SuppressWarnings(Array("unchecked")) val comments = dataList.asInstanceOf[ ArrayBuffer[Comment]]

                  for (comment <- comments) {
                    println("Record Comment CommentedBy: " + comment.getCommentedBy)
                    println("Record Comment CommentedTime: " + comment.getCommentedTime.toString)
                    println("Record Comment CommentContent: " + comment.getCommentContent)
                    println("Record Comment Id: " + comment.getId)
                  }
                }
                else if (dataList(0).isInstanceOf[Attachment]) { //Get the list of obtained Attachment instances
                  @SuppressWarnings(Array("unchecked")) val attachments = dataList.asInstanceOf[ ArrayBuffer[Attachment]]


                  for (attachment <- attachments) { //Get the owner User instance of each attachment
                    val ownerOption = attachment.getOwner
                    //Check if owner is not null
                    if (ownerOption.isDefined) { //Get the Name of the Owner
                      var owner = ownerOption.get
                      println("Record Attachment Owner User-Name: " + owner.getName)
                      //Get the ID of the Owner
                      println("Record Attachment Owner User-ID: " + owner.getId)
                      //Get the Email of the Owner
                      println("Record Attachment Owner User-Email: " + owner.getEmail)
                    }
                    //Get the modified time of each attachment
                    println("Record Attachment Modified Time: " + attachment.getModifiedTime.toString)
                    //Get the name of the File
                    println("Record Attachment File Name: " + attachment.getFileName)
                    //Get the created time of each attachment
                    println("Record Attachment Created Time: " + attachment.getCreatedTime.toString)
                    //Get the Attachment file size
                    println("Record Attachment File Size: " + attachment.getSize.toString)
                    //Get the parentId Record instance of each attachment
                    val parentIdOption = attachment.getParentId
                    //Check if parentId is not null
                    if (parentIdOption.isDefined) { //Get the parent record Name of each attachment
                      var parentId =parentIdOption.get
                      println("Record Attachment parent record Name: " + parentId.getKeyValue("name"))
                      //Get the parent record ID of each attachment
                      println("Record Attachment parent record ID: " + parentId.getId)
                    }
                    //Get the attachment is Editable
                    println("Record Attachment is Editable: " + attachment.geteditable().toString)
                    //Get the file ID of each attachment
                    println("Record Attachment File ID: " + attachment.getfileId())
                    //Get the type of each attachment
                    println("Record Attachment File Type: " + attachment.gettype)
                    //Get the seModule of each attachment
                    println("Record Attachment seModule: " + attachment.getseModule())
                    //Get the modifiedBy User instance of each attachment
                    var modifiedByOption = attachment.getModifiedBy
                    if (modifiedByOption.isDefined) { //Get the Name of the modifiedBy User
                      var modifiedBy = modifiedByOption.get
                      println("Record Attachment Modified By User-Name: " + modifiedBy.getName)
                      println("Record Attachment Modified By User-ID: " + modifiedBy.getId)
                      println("Record Attachment Modified By User-Email: " + modifiedBy.getEmail)
                    }
                    //Get the state of each attachment
                    println("Record Attachment State: " + attachment.getstate)
                    //Get the ID of each attachment
                    println("Record Attachment ID: " + attachment.getId)
                    //Get the createdBy User instance of each attachment
                    var createdByOption = attachment.getCreatedBy
                    if (createdByOption.isDefined) {
                      var createdBy = modifiedByOption.get

                      println("Record Attachment Created By User-Name: " + createdBy.getName)
                      println("Record Attachment Created By User-ID: " + createdBy.getId)
                      println("Record Attachment Created By User-Email: " + createdBy.getEmail)
                    }
                    //Get the linkUrl of each attachment
                    println("Record Attachment LinkUrl: " + attachment.getlinkUrl())
                  }
                }
                else println(keyName + ": " + value)
              }
              else if (value.isInstanceOf[Record]) {
                val recordValue = value.asInstanceOf[Record]
                println("Record " + keyName + " ID: " + recordValue.getId)
                println("Record " + keyName + " Name: " + recordValue.getKeyValue("name"))
              }
              else if (value.isInstanceOf[Layout]) {
                val layout = value.asInstanceOf[Layout]
                if (layout != null) {
                  println("Record " + keyName + " ID: " + layout.getId)
                  println("Record " + keyName + " Name: " + layout.getName)
                }
              }
              else if (value.isInstanceOf[User]) {
                val user = value.asInstanceOf[User]
                if (user != null) {
                  println("Record " + keyName + " User-ID: " + user.getId)
                  println("Record " + keyName + " User-Name: " + user.getName)
                  println("Record " + keyName + " User-Email: " + user.getEmail)
                }
              }
              else if (value.isInstanceOf[Choice[_]]) println(keyName + ": " + value.asInstanceOf[Choice[_]].getValue)
              else if (value.isInstanceOf[RemindAt]) println(keyName + ": " + value.asInstanceOf[RemindAt].getAlarm)
              else if (value.isInstanceOf[RecurringActivity]) {
                println(keyName)
                println("RRULE" + ": " + value.asInstanceOf[RecurringActivity].getRrule)
              }
              else if (value.isInstanceOf[Consent]) {
                val consent = value.asInstanceOf[Consent]
                println("Record Consent ID: " + consent.getId)
                //Get the Owner User instance of each attachment
                val ownerOption = consent.getOwner
                if (ownerOption.isDefined) { //Get the name of the owner User
                  var owner = ownerOption.get
                  println("Record Consent Owner Name: " + owner.getName)
                  //Get the ID of the owner User
                  println("Record Consent Owner ID: " + owner.getId)
                  //Get the Email of the owner User
                  println("Record Consent Owner Email: " + owner.getEmail)
                }
                val consentCreatedByOption = consent.getCreatedBy
                if (consentCreatedByOption.isDefined) { //Get the name of the CreatedBy User
                  var consentCreatedBy = consentCreatedByOption.get
                  println("Record Consent CreatedBy Name: " + consentCreatedBy.getName)
                  //Get the ID of the CreatedBy User
                  println("Record Consent CreatedBy ID: " + consentCreatedBy.getId)
                  //Get the Email of the CreatedBy User
                  println("Record Consent CreatedBy Email: " + consentCreatedBy.getEmail)
                }
                val consentModifiedByOption = consent.getModifiedBy
                if (consentModifiedByOption.isDefined) { //Get the name of the ModifiedBy User
                  var consentModifiedBy = consentModifiedByOption.get
                  println("Record Consent ModifiedBy Name: " + consentModifiedBy.getName)
                  //Get the ID of the ModifiedBy User
                  println("Record Consent ModifiedBy ID: " + consentModifiedBy.getId)
                  //Get the Email of the ModifiedBy User
                  println("Record Consent ModifiedBy Email: " + consentModifiedBy.getEmail)
                }
                println("Record Consent CreatedTime: " + consent.getCreatedTime)
                println("Record Consent ModifiedTime: " + consent.getModifiedTime)
                println("Record Consent ContactThroughEmail: " + consent.getContactThroughEmail)
                println("Record Consent ContactThroughSocial: " + consent.getContactThroughSocial)
                println("Record Consent ContactThroughSurvey: " + consent.getContactThroughSurvey)
                println("Record Consent ContactThroughPhone: " + consent.getContactThroughPhone)
                println("Record Consent MailSentTime: " + consent.getMailSentTime.toString)
                println("Record Consent ConsentDate: " + consent.getConsentDate.toString)
                println("Record Consent ConsentRemarks: " + consent.getConsentRemarks)
                println("Record Consent ConsentThrough: " + consent.getConsentThrough)
                println("Record Consent DataProcessingBasis: " + consent.getDataProcessingBasis)
                //To get custom values
                println("Record Consent Lawful Reason: " + consent.getKeyValue("Lawful_Reason"))
              }
              else println(keyName + ": " + value)
            })
          }
        }
        else if (responseHandler.isInstanceOf[FileBodyWrapper]) {
          val fileBodyWrapper = responseHandler.asInstanceOf[FileBodyWrapper]
          //Get StreamWrapper instance from the returned FileBodyWrapper instance
          val streamWrapper = fileBodyWrapper.getFile.get
          //Create a file instance with the absolute_file_path
          val file = new File(destinationFolder + File.separatorChar + streamWrapper.getName.get)
          //Get InputStream from the response
          val is = streamWrapper.getStream.get
          //Create an OutputStream for the destination file
          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)) != -1
          }) { //write data to OutputStream
            os.write(buffer, 0, bytesRead)
          }
          //Close the InputStream
          is.close()
          //Flush and close the OutputStream
          os.flush()
          os.close()
        }
        else { //Check if the request returned an exception
          if (responseHandler.isInstanceOf[APIException]) { //Get the received APIException instance
            val exception = responseHandler.asInstanceOf[APIException]
            //Get the Status
            println("Status: " + exception.getStatus.getValue)
            //Get the Code
            println("Code: " + exception.getCode.getValue)
            println("Details: ")

            exception.getDetails.foreach(entry=>{
              println(entry._1 + ": " + entry._2)
            })
            //Get the Message
            println("Message: " + exception.getMessage.getValue)
          }
        }
      }
      else { //If response is not as expected
        //Get model object from response
        val responseObject = response.getModel
        //Get the response object's class
        val clas = responseObject.getClass
        //Get all declared fields of the response class
        val fields = clas.getDeclaredFields
        for (field <- fields) { //Get each value
          println(field.getName + ":" + field.get(responseObject))
        }
      }
    }
  }
}
 
Update a Related Record

              
package com.zoho.crm.sample.relatedrecords

import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
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.{Comment, Consent, FileDetails, InventoryLineItems, LineTax, Participants, PricingDetails, Record, RecurringActivity, RemindAt}
import com.zoho.crm.api.relatedrecords.FileBodyWrapper
import com.zoho.crm.api.relatedrecords.APIException
import com.zoho.crm.api.relatedrecords.ActionHandler
import com.zoho.crm.api.relatedrecords.ActionResponse
import com.zoho.crm.api.relatedrecords.ActionWrapper
import com.zoho.crm.api.relatedrecords.BodyWrapper
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.DelinkRecordsParam
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsHeader
import com.zoho.crm.api.relatedrecords.RelatedRecordsOperations.GetRelatedRecordsParam
import com.zoho.crm.api.relatedrecords.ResponseHandler
import com.zoho.crm.api.relatedrecords.ResponseWrapper
import com.zoho.crm.api.relatedrecords.SuccessResponse
import com.zoho.crm.api.tags.Tag
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 Relatedrecord {
/**
   *  Delink Record 
   * This method is used to delete the association between modules and print the response.
   *
   * @param moduleAPIName      - The API Name of the module to delink related record.
   * @param recordId           - The ID of the record to be obtained.
   * @param relatedListAPIName - The API name of the related list. To get the API name of the related list.
   * @param relatedListId      - The ID of the related record.
   * @throws Exception
   */
  @throws[Exception]
  def delinkRecord(moduleAPIName: String, recordId: Long, relatedListAPIName: String, relatedListId: Long): Unit = {
    val relatedRecordsOperations = new RelatedRecordsOperations(relatedListAPIName, moduleAPIName)
    //Call delinkRecord method that takes relatedListId as parameter.
    val responseOption = relatedRecordsOperations.delinkRecord(relatedListId, recordId)
    if (responseOption.isDefined) {
      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 <- actionResponses) {
            if (actionResponse.isInstanceOf[SuccessResponse]) {
              val successResponse = actionResponse.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 (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 <- fields) {
          println(field.getName + ":" + field.get(responseObject))
        }
      }
    }
  }
}