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

PHP SDK Samples - Related Records Operations

Get Related Records
              
              
<?php
namespace com\zoho\crm\sample\relatedrecords;
use com\zoho\crm\api\HeaderMap;
use com\zoho\crm\api\ParameterMap;
use com\zoho\crm\api\layouts\Layout;
use com\zoho\crm\api\record\FileDetails;
use com\zoho\crm\api\record\InventoryLineItems;
use com\zoho\crm\api\record\LineTax;
use com\zoho\crm\api\record\PricingDetails;
use com\zoho\crm\api\relatedrecords\APIException;
use com\zoho\crm\api\relatedrecords\ActionWrapper;
use com\zoho\crm\api\relatedrecords\BodyWrapper;
use com\zoho\crm\api\relatedrecords\RelatedRecordsOperations;
use com\zoho\crm\api\relatedrecords\DelinkRecordsParam;
use com\zoho\crm\api\relatedrecords\GetRelatedRecordHeader;
use com\zoho\crm\api\relatedrecords\GetRelatedRecordsHeader;
use com\zoho\crm\api\relatedrecords\GetRelatedRecordsParam;
use com\zoho\crm\api\relatedrecords\ResponseWrapper;
use com\zoho\crm\api\relatedrecords\SuccessResponse;
use com\zoho\crm\api\tags\Tag;
use com\zoho\crm\api\users\User;
use com\zoho\crm\api\util\Choice;
use com\zoho\crm\api\record\Record;
use com\zoho\crm\api\record\Consent;
use com\zoho\crm\api\record\Comment;
use com\zoho\crm\api\record\Participants;
use com\zoho\crm\api\relatedrecords\FileBodyWrapper;
use com\zoho\crm\api\attachments\Attachment;
class RelatedRecords
{
/**
	 * 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
	 */
	public static function getRelatedRecords(string $moduleAPIName, string $recordId, string $relatedListAPIName)
	{
		//example
		//$moduleAPIName = "Leads";
		//$recordId = "34770615177002";
		//$relatedListAPIName = "Products";
		//Get instance of RelatedRecordsOperations Class that takes moduleAPIName, recordId and relatedListAPIName as parameter
	    $relatedRecordsOperations = new RelatedRecordsOperations( $relatedListAPIName,  $recordId,  $moduleAPIName);
		//Get instance of ParameterMap Class
		$paramInstance = new ParameterMap();
		$paramInstance->add(GetRelatedRecordsParam::page(), 1);
		$paramInstance->add(GetRelatedRecordsParam::perPage(), 2);
		//Get instance of HeaderMap Class
		$headerInstance = new HeaderMap();
		$datetime = date_create("2019-02-26T15:28:34+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get()));
		$headerInstance->add(GetRelatedRecordsHeader::IfModifiedSince(), $datetime);
		//Call getRelatedRecords method that takes paramInstance, headerInstance as parameter
		$response = $relatedRecordsOperations->getRelatedRecords($paramInstance, $headerInstance);
		if($response != null)
		{
            //Get the status code from response
            echo("Status code " . $response->getStatusCode() . "\n");
            if(in_array($response->getStatusCode(), array(204, 304)))
            {
                echo($response->getStatusCode() == 204? "No Content\n" : "Not Modified\n");
                return;
			}
			if($response->isExpected())
			{
				//Get object from response
				$responseHandler = $response->getObject();
				if($responseHandler instanceof ResponseWrapper)
				{
					//Get the received ResponseWrapper instance
					$responseWrapper = $responseHandler;
					//Get the obtained Record instance
					$records = $responseWrapper->getData();
					if($records != null)
					{
						foreach($records as $record)
						{					
							//Get the ID of each Record
							echo("RelatedRecord ID: " . $record->getId() . "\n");
							//Get the createdBy User instance of each Record
							$createdBy = $record->getCreatedBy();
							//Check if createdBy is not null
							if($createdBy != null)
							{
								//Get the ID of the createdBy User
								echo("RelatedRecord Created By User-ID: " . $createdBy->getId() . "\n");
								//Get the name of the createdBy User
								echo("RelatedRecord Created By User-Name: " . $createdBy->getName() . "\n");
								//Get the Email of the createdBy User
								echo("RelatedRecord Created By User-Email: " . $createdBy->getEmail() . "\n");
							}
							//Get the CreatedTime of each Record
							echo("RelatedRecord CreatedTime: ");
							print_r($record->getCreatedTime());
							echo("\n");
							//Get the modifiedBy User instance of each Record
							$modifiedBy = $record->getModifiedBy();
							//Check if modifiedBy is not null
							if($modifiedBy != null)
							{
								//Get the ID of the modifiedBy User
								echo("RelatedRecord Modified By User-ID: " . $modifiedBy->getId() . "\n");
								//Get the name of the modifiedBy User
								echo("RelatedRecord Modified By User-Name: " . $modifiedBy->getName() . "\n");
								//Get the Email of the modifiedBy User
								echo("RelatedRecord Modified By User-Email: " . $modifiedBy->getEmail() . "\n");
							}
							//Get the ModifiedTime of each Record
							echo("RelatedRecord ModifiedTime: ");
							print_r($record->getModifiedTime());
							echo("\n");
							//Get the list of Tag instance each Record
							$tags = $record->getTag();
							//Check if tags is not null
							if($tags != null)
							{
								foreach($tags as $tag)
								{
									//Get the Name of each Tag
									echo("RelatedRecord Tag Name: " . $tag->getName() . "\n");
									//Get the Id of each Tag
									echo("RelatedRecord Tag ID: " . $tag->getId() . "\n");
								}
							}
							//To get particular field value 
							echo("RelatedRecord Field Value: " . $record->getKeyValue("Last_Name") . "\n");// FieldApiName
							echo("RelatedRecord KeyValues : \n" );
							//Get the KeyValue map
							foreach($record->getKeyValues() as $keyName => $value)
							{
								if($value != null)
								{
									if((is_array($value) && sizeof($value) > 0) && isset($value[0]))
									{
										if($value[0] instanceof FileDetails)
										{
											$fileDetails = $value;
											foreach($fileDetails as $fileDetail)
											{
												//Get the Extn of each FileDetails
												echo("RelatedRecord FileDetails Extn: " . $fileDetail->getExtn() . "\n");
												//Get the IsPreviewAvailable of each FileDetails
												echo("RelatedRecord FileDetails IsPreviewAvailable: " . $fileDetail->getIsPreviewAvailable() . "\n");
												//Get the DownloadUrl of each FileDetails
												echo("RelatedRecord FileDetails DownloadUrl: " . $fileDetail->getDownloadUrl() . "\n");
												//Get the DeleteUrl of each FileDetails
												echo("RelatedRecord FileDetails DeleteUrl: " . $fileDetail->getDeleteUrl() . "\n");
												//Get the EntityId of each FileDetails
												echo("RelatedRecord FileDetails EntityId: " . $fileDetail->getEntityId() . "\n");
												//Get the Mode of each FileDetails
												echo("RelatedRecord FileDetails Mode: " . $fileDetail->getMode() . "\n");
												//Get the OriginalSizeByte of each FileDetails
												echo("RelatedRecord FileDetails OriginalSizeByte: " . $fileDetail->getOriginalSizeByte() . "\n");
												//Get the PreviewUrl of each FileDetails
												echo("RelatedRecord FileDetails PreviewUrl: " . $fileDetail->getPreviewUrl() . "\n");
												//Get the FileName of each FileDetails
												echo("RelatedRecord FileDetails FileName: " . $fileDetail->getFileName() . "\n");
												//Get the FileId of each FileDetails
												echo("RelatedRecord FileDetails FileId: " . $fileDetail->getFileId() . "\n");
												//Get the AttachmentId of each FileDetails
												echo("RelatedRecord FileDetails AttachmentId: " . $fileDetail->getAttachmentId() . "\n");
												//Get the FileSize of each FileDetails
												echo("RelatedRecord FileDetails FileSize: " . $fileDetail->getFileSize() . "\n");
												//Get the CreatorId of each FileDetails
												echo("RelatedRecord FileDetails CreatorId: " . $fileDetail->getCreatorId() . "\n");
												//Get the LinkDocs of each FileDetails
												echo("RelatedRecord FileDetails LinkDocs: " . $fileDetail->getLinkDocs() . "\n");
											}
										}
										else if($value[0] instanceof InventoryLineItems)
										{
											$productDetails = $value;
											foreach($productDetails as $productDetail)
											{
												$lineItemProduct = $productDetail->getProduct();
												if($lineItemProduct != null)
												{
													echo("RelatedRecord ProductDetails LineItemProduct ProductCode: " . $lineItemProduct->getProductCode() . "\n");
													echo("RelatedRecord ProductDetails LineItemProduct Currency: " . $lineItemProduct->getCurrency() . "\n");
													echo("RelatedRecord ProductDetails LineItemProduct Name: " . $lineItemProduct->getName() . "\n");
													echo("RelatedRecord ProductDetails LineItemProduct Id: " . $lineItemProduct->getId() . "\n");
												}
												echo("RelatedRecord ProductDetails Quantity: " . $productDetail->getQuantity(). "\n");
												echo("RelatedRecord ProductDetails Discount: " . $productDetail->getDiscount() . "\n");
												echo("RelatedRecord ProductDetails TotalAfterDiscount: " . $productDetail->getTotalAfterDiscount(). "\n");
												echo("RelatedRecord ProductDetails NetTotal: " . $productDetail->getNetTotal(). "\n");
												if($productDetail->getBook() != null)
												{
													echo("RelatedRecord ProductDetails Book: " . $productDetail->getBook(). "\n");
												}
												echo("RelatedRecord ProductDetails Tax: " . $productDetail->getTax(). "\n");
												echo("RelatedRecord ProductDetails ListPrice: " . $productDetail->getListPrice(). "\n");
												echo("RelatedRecord ProductDetails UnitPrice: " . $productDetail->getUnitPrice(). "\n");
												echo("RelatedRecord ProductDetails QuantityInStock: " . $productDetail->getQuantityInStock(). "\n");
												echo("RelatedRecord ProductDetails Total: " . $productDetail->getTotal(). "\n");
												echo("RelatedRecord ProductDetails ID: " . $productDetail->getId() . "\n");
												echo("RelatedRecord ProductDetails ProductDescription: " . $productDetail->getProductDescription() . "\n");
												$lineTaxes = $productDetail->getLineTax();
												foreach($lineTaxes as $lineTax)
												{
													echo("RelatedRecord ProductDetails LineTax Percentage: " . $lineTax->getPercentage(). "\n");
													echo("RelatedRecord ProductDetails LineTax Name: " . $lineTax->getName() . "\n");
													echo("RelatedRecord ProductDetails LineTax Id: " . $lineTax->getId() . "\n");
													echo("RelatedRecord ProductDetails LineTax Value: " . $lineTax->getValue(). "\n");
												}
											}
										}
										else if($value[0] instanceof Tag)
										{
											$tagList = $value;
											foreach($tagList as $tag)
											{
												//Get the Name of each Tag
												echo("RelatedRecord Tag Name: " . $tag->getName() . "\n");
												//Get the Id of each Tag
												echo("RelatedRecord Tag ID: " . $tag->getId() . "\n");
											}
										}
										else if($value[0] instanceof PricingDetails)
										{
											$pricingDetails = $value;
											foreach($pricingDetails as $pricingDetail)
											{
												echo("RelatedRecord PricingDetails ToRange: " . $pricingDetail->getToRange(). "\n");
												echo("RelatedRecord PricingDetails Discount: " . $pricingDetail->getDiscount(). "\n");
												echo("RelatedRecord PricingDetails ID: " . $pricingDetail->getId() . "\n");
												echo("RelatedRecord PricingDetails FromRange: " . $pricingDetail->getFromRange(). "\n");
											}
										}
										else if($value[0] instanceof Participants)
										{
											$participants = $value;
											foreach($participants as $participant)
											{
												echo("RelatedRecord Participants Name: " . $participant->getName() . "\n");
												echo("RelatedRecord Participants Invited: " . $participant->getInvited() . "\n");
												echo("RelatedRecord Participants ID: " . $participant->getId() . "\n");
												echo("RelatedRecord Participants Type: " . $participant->getType() . "\n");
												echo("RelatedRecord Participants Participant: " . $participant->getParticipant() . "\n");
												echo("RelatedRecord Participants Status: " . $participant->getStatus() . "\n");
											}
										}
										else if($value[0] instanceof Record)
										{
											$recordList = $value;
											foreach($recordList as $record1)
											{
												//Get the details map
												foreach($record1->getKeyValues() as $key => $value1)
												{
													//Get each value in the map
													echo($key . " : " );
													print_r($value1);
													echo("\n");
												}
											}
										}
										else if($value[0] instanceof LineTax)
										{
											$lineTaxes = $value;
											foreach($lineTaxes as $lineTax)
											{
												echo("RelatedRecord ProductDetails LineTax Percentage: " . $lineTax->getPercentage(). "\n");
												echo("RelatedRecord ProductDetails LineTax Name: " . $lineTax->getName() . "\n");
												echo("RelatedRecord ProductDetails LineTax Id: " . $lineTax->getId() . "\n");
												echo("RelatedRecord ProductDetails LineTax Value: " . $lineTax->getValue(). "\n");
											}
										}
										else if($value[0] instanceof Choice)
										{
											$choice = $value;
											foreach($choice as $choiceValue)
											{
												echo("RelatedRecord " . $keyName . " : " . $choiceValue->getValue() . "\n");
											}
										}
										else if($value[0] instanceof Comment)
										{
											$comments = $value;
											foreach($comments as $comment)
											{
												echo("Record Comment CommentedBy: " . $comment->getCommentedBy() . "\n");
												echo("Record Comment CommentedTime: ");
												print_r($comment->getCommentedTime());
												echo("\n");
												echo("Record Comment CommentContent: " . $comment->getCommentContent(). "\n");
												echo("Record Comment Id: " . $comment->getId() . "\n");
											}
										}
										else if($value[0] instanceof Attachment)
										{
											$attachments = $value;
											foreach ($attachments as $attachment)
											{
												//Get the owner User instance of each attachment
												$owner = $attachment->getOwner();
												//Check if owner is not null
												if($owner != null)
												{
													//Get the Name of the Owner
													echo("RelatedRecord Attachment Owner User-Name: " . $owner->getName() . "\n");
													//Get the ID of the Owner
													echo("RelatedRecord Attachment Owner User-ID: " . $owner->getId() . "\n");
													//Get the Email of the Owner
													echo("RelatedRecord Attachment Owner User-Email: " . $owner->getEmail() . "\n");
												}
												//Get the modified time of each attachment
												echo("RelatedRecord Attachment Modified Time: ");
												print_r($attachment->getModifiedTime());
												echo("\n");
												//Get the name of the File
												echo("RelatedRecord Attachment File Name: " . $attachment->getFileName() . "\n");
												//Get the created time of each attachment
												echo("RelatedRecord Attachment Created Time: " );
												print_r($attachment->getCreatedTime());
												echo("\n");
												//Get the Attachment file size
												echo("RelatedRecord Attachment File Size: " . $attachment->getSize() . "\n");
												//Get the parentId Record instance of each attachment
												$parentId = $attachment->getParentId();
												//Check if parentId is not null
												if($parentId != null)
												{	
													//Get the parent record Name of each attachment
													echo("RelatedRecord Attachment parent record Name: " . $parentId->getKeyValue("name") . "\n");
													//Get the parent record ID of each attachment
													echo("RelatedRecord Attachment parent record ID: " . $parentId->getId() . "\n");
												}
												//Get the attachment is Editable
												echo("RelatedRecord Attachment is Editable: " . $attachment->getEditable() . "\n");
												//Get the file ID of each attachment
												echo("RelatedRecord Attachment File ID: " . $attachment->getFileId() . "\n");
												//Get the type of each attachment
												echo("RelatedRecord Attachment File Type: " . $attachment->getType() . "\n");
												//Get the seModule of each attachment
												echo("RelatedRecord Attachment seModule: " . $attachment->getSeModule() . "\n");
												//Get the modifiedBy User instance of each attachment
												$modifiedBy = $attachment->getModifiedBy();
												//Check if modifiedBy is not null
												if($modifiedBy != null)
												{
													//Get the Name of the modifiedBy User
													echo("RelatedRecord Attachment Modified By User-Name: " . $modifiedBy->getName() . "\n");
													//Get the ID of the modifiedBy User
													echo("RelatedRecord Attachment Modified By User-ID: " . $modifiedBy->getId() . "\n");
													//Get the Email of the modifiedBy User
													echo("RelatedRecord Attachment Modified By User-Email: " . $modifiedBy->getEmail() . "\n");
												}
												//Get the state of each attachment
												echo("RelatedRecord Attachment State: " . $attachment->getState() . "\n");
												//Get the ID of each attachment
												echo("RelatedRecord Attachment ID: " . $attachment->getId() . "\n");
												//Get the createdBy User instance of each attachment
												$createdBy = $attachment->getCreatedBy();
												//Check if createdBy is not null
												if($createdBy != null)
												{
													//Get the name of the createdBy User
													echo("RelatedRecord Attachment Created By User-Name: " . $createdBy->getName() . "\n");
													//Get the ID of the createdBy User
													echo("RelatedRecord Attachment Created By User-ID: " . $createdBy->getId() . "\n");
													//Get the Email of the createdBy User
													echo("RelatedRecord Attachment Created By User-Email: " . $createdBy->getEmail() . "\n");
												}
												//Get the linkUrl of each attachment
												echo("RelatedRecord Attachment LinkUrl: " . $attachment->getLinkUrl() . "\n");
											}
										}
										else
										{
											echo($keyName . " : ");
											print_r($value);
											echo("\n");
										}
									}
									else if($value instanceof Layout)
									{
										$layout = $value;
										if($layout != null)
										{
											echo("RelatedRecord " . $keyName. " ID: " . $layout->getId() . "\n");
											echo("RelatedRecord " . $keyName . " Name: " . $layout->getName() . "\n");
										}
									}
									else if($value instanceof User)
									{
										$user = $value;
										if($user != null)
										{
											echo("RelatedRecord " . $keyName . " User-ID: " . $user->getId() . "\n");
											echo("RelatedRecord " . $keyName . " User-Name: " . $user->getName() . "\n");
											echo("RelatedRecord " . $keyName . " User-Email: " . $user->getEmail() . "\n");
										}
									}
									else if($value instanceof Choice)
									{
										$choiceValue = $value;
										echo("RelatedRecord " . $keyName . " : " . $choiceValue->getValue() . "\n");
									}
									else if($value instanceof Record)
									{
										$recordValue = $value;
										echo("RelatedRecord " . $keyName . " ID: " . $recordValue->getId() . "\n");
										echo("RelatedRecord " . $keyName . " Name: " . $recordValue->getKeyValue("name") . "\n");
									}
									else if($value instanceof Consent)
									{
										$consent = $value;
										echo("RelatedRecord Consent ID: " . $consent->getId());
										//Get the Owner User instance of each attachment
										$owner = $consent->getOwner();
										//Check if owner is not null
										if($owner != null)
										{
											//Get the name of the owner User
											echo("RelatedRecord Consent Owner Name: " . $owner->getName());
											//Get the ID of the owner User
											echo("RelatedRecord Consent Owner ID: " . $owner->getId());
											//Get the Email of the owner User
											echo("RelatedRecord Consent Owner Email: " . $owner->getEmail());
										}
										$consentCreatedBy = $consent->getCreatedBy();
										//Check if createdBy is not null
										if($consentCreatedBy != null)
										{
											//Get the name of the CreatedBy User
											echo("RelatedRecord Consent CreatedBy Name: " . $consentCreatedBy->getName());
											//Get the ID of the CreatedBy User
											echo("RelatedRecord Consent CreatedBy ID: " . $consentCreatedBy->getId());
											//Get the Email of the CreatedBy User
											echo("RelatedRecord Consent CreatedBy Email: " . $consentCreatedBy->getEmail());
										}
										$consentModifiedBy = $consent->getModifiedBy();
										//Check if createdBy is not null
										if($consentModifiedBy != null)
										{
											//Get the name of the ModifiedBy User
											echo("RelatedRecord Consent ModifiedBy Name: " . $consentModifiedBy->getName());
											//Get the ID of the ModifiedBy User
											echo("RelatedRecord Consent ModifiedBy ID: " . $consentModifiedBy->getId());
											//Get the Email of the ModifiedBy User
											echo("RelatedRecord Consent ModifiedBy Email: " . $consentModifiedBy->getEmail());
										}
										echo("RelatedRecord Consent CreatedTime: " . $consent->getCreatedTime());
										echo("RelatedRecord Consent ModifiedTime: " . $consent->getModifiedTime());
										echo("RelatedRecord Consent ContactThroughEmail: " . $consent->getContactThroughEmail());
										echo("RelatedRecord Consent ContactThroughSocial: " . $consent->getContactThroughSocial());
										echo("RelatedRecord Consent ContactThroughSurvey: " . $consent->getContactThroughSurvey());
										echo("RelatedRecord Consent ContactThroughPhone: " . $consent->getContactThroughPhone());
										echo("RelatedRecord Consent MailSentTime: " . $consent->getMailSentTime().toString());
										echo("RelatedRecord Consent ConsentDate: " . $consent->getConsentDate().toString());
										echo("RelatedRecord Consent ConsentRemarks: " . $consent->getConsentRemarks());
										echo("RelatedRecord Consent ConsentThrough: " . $consent->getConsentThrough());
										echo("RelatedRecord Consent DataProcessingBasis: " . $consent->getDataProcessingBasis());
										//To get custom values
										echo("RelatedRecord Consent Lawful Reason: " . $consent->getKeyValue("Lawful_Reason"));
									}
									else
									{
										//Get each value in the map
										echo($keyName . " : ");
										print_r($value);
										echo("\n");
									}
								}
							}
						}
					}
					//Get the Object obtained Info instance
					$info = $responseWrapper->getInfo();
					//Check if info is not null
					if($info != null)
					{
						if($info->getPerPage() != null)
						{
							//Get the PerPage of the Info
							echo("RelatedRecord Info PerPage: " . $info->getPerPage(). "\n");
						}
						if($info->getCount() != null)
						{
							//Get the Count of the Info
							echo("RelatedRecord Info Count: " . $info->getCount(). "\n");
						}
						if($info->getPage() != null)
						{
							//Get the Page of the Info
							echo("RelatedRecord Info Page: " . $info->getPage(). "\n");
						}
						if($info->getMoreRecords() != null)
						{
							//Get the MoreRecords of the Info
							echo("RelatedRecord Info MoreRecords: " . $info->getMoreRecords(). "\n");
						}
					}
				}
				//Check if the request returned an exception
				else if($responseHandler instanceof APIException)
				{
					//Get the received APIException instance
					$exception = $responseHandler;
					//Get the Status
					echo("Status: " . $exception->getStatus()->getValue() . "\n");
					//Get the Code
					echo("Code: " . $exception->getCode()->getValue() . "\n");
					if($exception->getDetails() != null)
					{
						echo("Details: " );
						//Get the details map
						foreach($exception->getDetails() as $key => $value)
						{
							//Get each value in the map
							echo($key . " : " . $value . "\n");
						}
						//Get the Message
						echo("Message: " . $exception->getMessage()->getValue() . "\n");
					}
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}
 
Update Related Records
              
              
<?php
namespace com\zoho\crm\sample\relatedrecords;
use com\zoho\crm\api\HeaderMap;
use com\zoho\crm\api\ParameterMap;
use com\zoho\crm\api\layouts\Layout;
use com\zoho\crm\api\record\FileDetails;
use com\zoho\crm\api\record\InventoryLineItems;
use com\zoho\crm\api\record\LineTax;
use com\zoho\crm\api\record\PricingDetails;
use com\zoho\crm\api\relatedrecords\APIException;
use com\zoho\crm\api\relatedrecords\ActionWrapper;
use com\zoho\crm\api\relatedrecords\BodyWrapper;
use com\zoho\crm\api\relatedrecords\RelatedRecordsOperations;
use com\zoho\crm\api\relatedrecords\DelinkRecordsParam;
use com\zoho\crm\api\relatedrecords\GetRelatedRecordHeader;
use com\zoho\crm\api\relatedrecords\GetRelatedRecordsHeader;
use com\zoho\crm\api\relatedrecords\GetRelatedRecordsParam;
use com\zoho\crm\api\relatedrecords\ResponseWrapper;
use com\zoho\crm\api\relatedrecords\SuccessResponse;
use com\zoho\crm\api\tags\Tag;
use com\zoho\crm\api\users\User;
use com\zoho\crm\api\util\Choice;
use com\zoho\crm\api\record\Record;
use com\zoho\crm\api\record\Consent;
use com\zoho\crm\api\record\Comment;
use com\zoho\crm\api\record\Participants;
use com\zoho\crm\api\relatedrecords\FileBodyWrapper;
use com\zoho\crm\api\attachments\Attachment;
class RelatedRecords
{
	/**
	 * 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
	 */
	public static function updateRelatedRecords(string $moduleAPIName, string $recordId, string $relatedListAPIName)
	{
		//API Name of the module to update record
		//$moduleAPIName = "Leads";
		//$recordId = "34770615177002";
		//$relatedListAPIName = "Products";
		//Get instance of RelatedRecordsOperations Class that takes moduleAPIName, recordId and relatedListAPIName as parameter
	    $relatedRecordsOperations = new RelatedRecordsOperations($relatedListAPIName,  $recordId,  $moduleAPIName);
		//Get instance of BodyWrapper Class that will contain the request body
		$request = new BodyWrapper();
		//List of Record instances
		$records = array();
		//Get instance of Record Class
		$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", "34770615919001");
		$record1->addKeyValue("list_price", 50.56);
		//Add Record instance to the list
		array_push($records, $record1);
		//Get instance of Record Class
		$record2 = new Record();
		/*
		 * Call addKeyValue method that takes two arguments
		 * 1 -> A string that is the Field's API Name
		 * 2 -> Value
		 */
		$record2->addKeyValue("id", "34770615917011");
		$record2->addKeyValue("list_price", 50.56);
		//Add Record instance to the list
		array_push($records, $record2);
		//Set the list to Records in BodyWrapper instance
		$request->setData($records);
		//Call updateRecord method that takes BodyWrapper instance as parameter.
		$response = $relatedRecordsOperations->updateRelatedRecords($request);
		if($response != null)
		{
			//Get the status code from response
			echo("Status Code: " . $response->getStatusCode() . "\n");
			if($response->isExpected())
			{
				//Get object from response
				$actionHandler = $response->getObject();
				if($actionHandler instanceof ActionWrapper)
				{
					//Get the received ActionWrapper instance
					$actionWrapper = $actionHandler;
					//Get the list of obtained ActionResponse instances
					$actionResponses = $actionWrapper->getData();
					foreach($actionResponses as $actionResponse)
					{
						//Check if the request is successful
						if($actionResponse instanceof SuccessResponse)
						{
							//Get the received SuccessResponse instance
							 $successResponse = $actionResponse;
							//Get the Status
							echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
							//Get the Code
							echo("Code: " . $successResponse->getCode()->getValue() . "\n");
							echo("Details: " );
							//Get the details map
							foreach($successResponse->getDetails() as $key => $value)
							{
								//Get each value in the map
								echo($key . " : " . $value . "\n");
							}
							//Get the Message
							echo("Message: " . $successResponse->getMessage()->getValue() . "\n");
						}
						//Check if the request returned an exception
						else if($actionResponse instanceof APIException)
						{
							//Get the received APIException instance
							$exception = $actionResponse;
							//Get the Status
							echo("Status: " . $exception->getStatus()->getValue() . "\n");
							//Get the Code
							echo("Code: " . $exception->getCode()->getValue() . "\n");
							echo("Details: " );
							//Get the details map
							foreach($exception->getDetails() as $key => $value)
							{
								//Get each value in the map
								echo($key . " : " . $value . "\n");
							}
							//Get the Message
							echo("Message: " . $exception->getMessage()->getValue() . "\n");
						}
					}
				}
				//Check if the request returned an exception
				else if($actionHandler instanceof APIException)
				{
					//Get the received APIException instance
					$exception = $actionHandler;
					//Get the Status
					echo("Status: " . $exception->getStatus()->getValue() . "\n");
					//Get the Code
					echo("Code: " . $exception->getCode()->getValue() . "\n");
					echo("Details: " );
					//Get the details map
					foreach($exception->getDetails() as $key => $value)
					{
						//Get each value in the map
						echo($key . " : " . $value . "\n");
					}
					//Get the Message
					echo("Message: " . $exception->getMessage()->getValue() . "\n");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}
 
              
              
<?php
namespace com\zoho\crm\sample\relatedrecords;
use com\zoho\crm\api\HeaderMap;
use com\zoho\crm\api\ParameterMap;
use com\zoho\crm\api\layouts\Layout;
use com\zoho\crm\api\record\FileDetails;
use com\zoho\crm\api\record\InventoryLineItems;
use com\zoho\crm\api\record\LineTax;
use com\zoho\crm\api\record\PricingDetails;
use com\zoho\crm\api\relatedrecords\APIException;
use com\zoho\crm\api\relatedrecords\ActionWrapper;
use com\zoho\crm\api\relatedrecords\BodyWrapper;
use com\zoho\crm\api\relatedrecords\RelatedRecordsOperations;
use com\zoho\crm\api\relatedrecords\DelinkRecordsParam;
use com\zoho\crm\api\relatedrecords\GetRelatedRecordHeader;
use com\zoho\crm\api\relatedrecords\GetRelatedRecordsHeader;
use com\zoho\crm\api\relatedrecords\GetRelatedRecordsParam;
use com\zoho\crm\api\relatedrecords\ResponseWrapper;
use com\zoho\crm\api\relatedrecords\SuccessResponse;
use com\zoho\crm\api\tags\Tag;
use com\zoho\crm\api\users\User;
use com\zoho\crm\api\util\Choice;
use com\zoho\crm\api\record\Record;
use com\zoho\crm\api\record\Consent;
use com\zoho\crm\api\record\Comment;
use com\zoho\crm\api\record\Participants;
use com\zoho\crm\api\relatedrecords\FileBodyWrapper;
use com\zoho\crm\api\attachments\Attachment;
class RelatedRecords
{
	/**
	 * 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 list IDs.
	 * @throws Exception
	 */
	public static function delinkRecords(string $moduleAPIName, string $recordId, string $relatedListAPIName, array $relatedListIds)
	{
		//API Name of the module to update record
		//$moduleAPIName = "Leads";
		//$recordId = "34770615177002";
		//$relatedListAPIName = "Products";
		//Get instance of RelatedRecordsOperations Class that takes moduleAPIName, recordId and relatedListAPIName as parameter
	    $relatedRecordsOperations = new RelatedRecordsOperations($relatedListAPIName,  $recordId,  $moduleAPIName);
		//Get instance of ParameterMap Class
		$paramInstance = new ParameterMap();
		foreach($relatedListIds as $relatedListId)
		{
			$paramInstance->add(DelinkRecordsParam::ids(), $relatedListId);
		}
		//Call delinkRecords method that takes paramInstance instance as parameter.
		$response = $relatedRecordsOperations->delinkRecords($paramInstance);
		if($response != null)
		{
			//Get the status code from response
			echo("Status Code: " . $response->getStatusCode() . "\n");
			if($response->isExpected())
			{
				//Get object from response
				$actionHandler = $response->getObject();
				if($actionHandler instanceof ActionWrapper)
				{
					//Get the received ActionWrapper instance
					$actionWrapper = $actionHandler;
					//Get the list of obtained ActionResponse instances
					$actionResponses = $actionWrapper->getData();
					foreach($actionResponses as $actionResponse)
					{
						//Check if the request is successful
						if($actionResponse instanceof SuccessResponse)
						{
							//Get the received SuccessResponse instance
							$successResponse = $actionResponse;
							//Get the Status
							echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
							//Get the Code
							echo("Code: " . $successResponse->getCode()->getValue() . "\n");
							echo("Details: " );
							//Get the details map
							foreach($successResponse->getDetails() as $key => $value)
							{
								//Get each value in the map
								echo($key . " : " . $value . "\n");
							}
							//Get the Message
							echo("Message: " . $successResponse->getMessage()->getValue() . "\n");
						}
						//Check if the request returned an exception
						else if($actionResponse instanceof APIException)
						{
							//Get the received APIException instance
							$exception = $actionResponse;
							//Get the Status
							echo("Status: " . $exception->getStatus()->getValue() . "\n");
							//Get the Code
							echo("Code: " . $exception->getCode()->getValue() . "\n");
							echo("Details: " );
							//Get the details map
							foreach($exception->getDetails() as $key => $value)
							{
								//Get each value in the map
								echo($key . " : " . $value . "\n");
							}
							//Get the Message
							echo("Message: " . $exception->getMessage()->getValue() . "\n");
						}
					}
				}
				//Check if the request returned an exception
				else if($actionHandler instanceof APIException)
				{
					//Get the received APIException instance
					$exception = $actionHandler;
					//Get the Status
					echo("Status: " . $exception->getStatus()->getValue() . "\n");
					//Get the Code
					echo("Code: " . $exception->getCode()->getValue() . "\n");
					echo("Details: " );
					//Get the details map
					foreach($exception->getDetails() as $key => $value)
					{
						//Get each value in the map
						echo($key . " : " . $value . "\n");
					}
					//Get the Message
					echo("Message: " . $exception->getMessage()->getValue() . "\n");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}
 
Get a Related Record
              
              
<?php
namespace com\zoho\crm\sample\relatedrecords;
use com\zoho\crm\api\HeaderMap;
use com\zoho\crm\api\ParameterMap;
use com\zoho\crm\api\layouts\Layout;
use com\zoho\crm\api\record\FileDetails;
use com\zoho\crm\api\record\InventoryLineItems;
use com\zoho\crm\api\record\LineTax;
use com\zoho\crm\api\record\PricingDetails;
use com\zoho\crm\api\relatedrecords\APIException;
use com\zoho\crm\api\relatedrecords\ActionWrapper;
use com\zoho\crm\api\relatedrecords\BodyWrapper;
use com\zoho\crm\api\relatedrecords\RelatedRecordsOperations;
use com\zoho\crm\api\relatedrecords\DelinkRecordsParam;
use com\zoho\crm\api\relatedrecords\GetRelatedRecordHeader;
use com\zoho\crm\api\relatedrecords\GetRelatedRecordsHeader;
use com\zoho\crm\api\relatedrecords\GetRelatedRecordsParam;
use com\zoho\crm\api\relatedrecords\ResponseWrapper;
use com\zoho\crm\api\relatedrecords\SuccessResponse;
use com\zoho\crm\api\tags\Tag;
use com\zoho\crm\api\users\User;
use com\zoho\crm\api\util\Choice;
use com\zoho\crm\api\record\Record;
use com\zoho\crm\api\record\Consent;
use com\zoho\crm\api\record\Comment;
use com\zoho\crm\api\record\Participants;
use com\zoho\crm\api\relatedrecords\FileBodyWrapper;
use com\zoho\crm\api\attachments\Attachment;
class RelatedRecords
{
	/**
	 * 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
	 */
	public static function getRelatedRecord(string $moduleAPIName, string $recordId, string $relatedListAPIName, string $relatedListId, string $destinationFolder)
	{
		//example
		//$moduleAPIName = "Leads";
		//$recordId = "34770615177002";
		//$relatedListAPIName = "Products";
		//$relatedRecordId = "3477061994115";
		//$destinationFolder = "/Users/user_name/Desktop";
		//Get instance of RelatedRecordsOperations Class that takes moduleAPIName, recordId and relatedListAPIName as parameter
	    $relatedRecordsOperations = new RelatedRecordsOperations($relatedListAPIName,  $recordId,  $moduleAPIName);
		$headerInstance = new HeaderMap();
		$ifmodifiedsince = date_create("2020-07-15T17:58:47+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get()));
		$headerInstance->add(GetRelatedRecordHeader::IfModifiedSince(), $ifmodifiedsince);
		//Call getRelatedRecord method that takes headerInstance and relatedRecordId as parameter
		$response = $relatedRecordsOperations->getRelatedRecord($relatedListId,$headerInstance );
		if($response != null)
		{
            //Get the status code from response
            echo("Status code " . $response->getStatusCode() . "\n");
            if(in_array($response->getStatusCode(), array(204, 304)))
            {
                echo($response->getStatusCode() == 204? "No Content\n" : "Not Modified\n");
                return;
			}
			if($response->isExpected())
			{
				//Get object from response
				$responseHandler = $response->getObject();
				if($responseHandler instanceof ResponseWrapper)
				{
					$responseWrapper = $responseHandler;
					//Get the obtained Record instance
					$records = $responseWrapper->getData();
					foreach($records as $record)
					{					
						//Get the ID of each Record
						echo("RelatedRecord ID: " . $record->getId() . "\n");
						//Get the createdBy User instance of each Record
						$createdBy = $record->getCreatedBy();
						//Check if createdBy is not null
						if($createdBy != null)
						{
							//Get the ID of the createdBy User
							echo("RelatedRecord Created By User-ID: " . $createdBy->getId() . "\n");
							//Get the name of the createdBy User
							echo("RelatedRecord Created By User-Name: " . $createdBy->getName() . "\n");
							//Get the Email of the createdBy User
							echo("RelatedRecord Created By User-Email: " . $createdBy->getEmail() . "\n");
						}
						//Get the CreatedTime of each Record
						echo("RelatedRecord CreatedTime: ");
						print_r($record->getCreatedTime());
						echo("\n");
						//Get the modifiedBy User instance of each Record
						$modifiedBy = $record->getModifiedBy();
						//Check if modifiedBy is not null
						if($modifiedBy != null)
						{
							//Get the ID of the modifiedBy User
							echo("RelatedRecord Modified By User-ID: " . $modifiedBy->getId() . "\n");
							//Get the name of the modifiedBy User
							echo("RelatedRecord Modified By User-Name: " . $modifiedBy->getName() . "\n");
							//Get the Email of the modifiedBy User
							echo("RelatedRecord Modified By User-Email: " . $modifiedBy->getEmail() . "\n");
						}
						//Get the ModifiedTime of each Record
						echo("RelatedRecord ModifiedTime: ");
						print_r($record->getModifiedTime());
						echo("\n");
						//Get the list of Tag instance each Record
						$tags = $record->getTag();
						//Check if tags is not null
						if($tags != null)
						{
							foreach($tags as $tag)
							{
								//Get the Name of each Tag
								echo("RelatedRecord Tag Name: " . $tag->getName() . "\n");
								//Get the Id of each Tag
								echo("RelatedRecord Tag ID: " . $tag->getId() . "\n");
							}
						}
						//To get particular field value 
						echo("RelatedRecord Field Value: " . $record->getKeyValue("Last_Name") . "\n");// FieldApiName
						echo("RelatedRecord KeyValues : \n" );
						//Get the KeyValue map
						foreach($record->getKeyValues() as $keyName => $value)
						{
							if($value != null)
							{
								if((is_array($value) && sizeof($value) > 0) && isset($value[0]))
								{
									if($value[0] instanceof FileDetails)
									{
										$fileDetails = $value;
										foreach($fileDetails as $fileDetail)
										{
											//Get the Extn of each FileDetails
											echo("RelatedRecord FileDetails Extn: " . $fileDetail->getExtn() . "\n");
											//Get the IsPreviewAvailable of each FileDetails
											echo("RelatedRecord FileDetails IsPreviewAvailable: " . $fileDetail->getIsPreviewAvailable() . "\n");
											//Get the DownloadUrl of each FileDetails
											echo("RelatedRecord FileDetails DownloadUrl: " . $fileDetail->getDownloadUrl() . "\n");
											//Get the DeleteUrl of each FileDetails
											echo("RelatedRecord FileDetails DeleteUrl: " . $fileDetail->getDeleteUrl() . "\n");
											//Get the EntityId of each FileDetails
											echo("RelatedRecord FileDetails EntityId: " . $fileDetail->getEntityId() . "\n");
											//Get the Mode of each FileDetails
											echo("RelatedRecord FileDetails Mode: " . $fileDetail->getMode() . "\n");
											//Get the OriginalSizeByte of each FileDetails
											echo("RelatedRecord FileDetails OriginalSizeByte: " . $fileDetail->getOriginalSizeByte() . "\n");
											//Get the PreviewUrl of each FileDetails
											echo("RelatedRecord FileDetails PreviewUrl: " . $fileDetail->getPreviewUrl() . "\n");
											//Get the FileName of each FileDetails
											echo("RelatedRecord FileDetails FileName: " . $fileDetail->getFileName() . "\n");
											//Get the FileId of each FileDetails
											echo("RelatedRecord FileDetails FileId: " . $fileDetail->getFileId() . "\n");
											//Get the AttachmentId of each FileDetails
											echo("RelatedRecord FileDetails AttachmentId: " . $fileDetail->getAttachmentId() . "\n");
											//Get the FileSize of each FileDetails
											echo("RelatedRecord FileDetails FileSize: " . $fileDetail->getFileSize() . "\n");
											//Get the CreatorId of each FileDetails
											echo("RelatedRecord FileDetails CreatorId: " . $fileDetail->getCreatorId() . "\n");
											//Get the LinkDocs of each FileDetails
											echo("RelatedRecord FileDetails LinkDocs: " . $fileDetail->getLinkDocs() . "\n");
										}
									}
									else if($value[0] instanceof InventoryLineItems)
									{
										$productDetails = $value;
										foreach($productDetails as $productDetail)
										{
											$lineItemProduct = $productDetail->getProduct();
											if($lineItemProduct != null)
											{
												echo("RelatedRecord ProductDetails LineItemProduct ProductCode: " . $lineItemProduct->getProductCode() . "\n");
												echo("RelatedRecord ProductDetails LineItemProduct Currency: " . $lineItemProduct->getCurrency() . "\n");
												echo("RelatedRecord ProductDetails LineItemProduct Name: " . $lineItemProduct->getName() . "\n");
												echo("RelatedRecord ProductDetails LineItemProduct Id: " . $lineItemProduct->getId() . "\n");
											}
											echo("RelatedRecord ProductDetails Quantity: " . $productDetail->getQuantity(). "\n");
											echo("RelatedRecord ProductDetails Discount: " . $productDetail->getDiscount() . "\n");
											echo("RelatedRecord ProductDetails TotalAfterDiscount: " . $productDetail->getTotalAfterDiscount(). "\n");
											echo("RelatedRecord ProductDetails NetTotal: " . $productDetail->getNetTotal(). "\n");
											if($productDetail->getBook() != null)
											{
												echo("RelatedRecord ProductDetails Book: " . $productDetail->getBook(). "\n");
											}
											echo("RelatedRecord ProductDetails Tax: " . $productDetail->getTax(). "\n");
											echo("RelatedRecord ProductDetails ListPrice: " . $productDetail->getListPrice(). "\n");
											echo("RelatedRecord ProductDetails UnitPrice: " . $productDetail->getUnitPrice(). "\n");
											echo("RelatedRecord ProductDetails QuantityInStock: " . $productDetail->getQuantityInStock(). "\n");
											echo("RelatedRecord ProductDetails Total: " . $productDetail->getTotal(). "\n");
											echo("RelatedRecord ProductDetails ID: " . $productDetail->getId() . "\n");
											echo("RelatedRecord ProductDetails ProductDescription: " . $productDetail->getProductDescription() . "\n");
											$lineTaxes = $productDetail->getLineTax();
											foreach($lineTaxes as $lineTax)
											{
												echo("RelatedRecord ProductDetails LineTax Percentage: " . $lineTax->getPercentage(). "\n");
												echo("RelatedRecord ProductDetails LineTax Name: " . $lineTax->getName() . "\n");
												echo("RelatedRecord ProductDetails LineTax Id: " . $lineTax->getId() . "\n");
												echo("RelatedRecord ProductDetails LineTax Value: " . $lineTax->getValue(). "\n");
											}
										}
									}
									else if($value[0] instanceof Tag)
									{
										$tagList = $value;
										foreach($tagList as $tag)
										{
											//Get the Name of each Tag
											echo("RelatedRecord Tag Name: " . $tag->getName() . "\n");
											//Get the Id of each Tag
											echo("RelatedRecord Tag ID: " . $tag->getId() . "\n");
										}
									}
									else if($value[0] instanceof PricingDetails)
									{
										$pricingDetails = $value;
										foreach($pricingDetails as $pricingDetail)
										{
											echo("RelatedRecord PricingDetails ToRange: " . $pricingDetail->getToRange(). "\n");
											echo("RelatedRecord PricingDetails Discount: " . $pricingDetail->getDiscount(). "\n");
											echo("RelatedRecord PricingDetails ID: " . $pricingDetail->getId() . "\n");
											echo("RelatedRecord PricingDetails FromRange: " . $pricingDetail->getFromRange(). "\n");
										}
									}
									else if($value[0] instanceof Participants)
									{
										$participants = $value;
										foreach($participants as $participant)
										{
											echo("RelatedRecord Participants Name: " . $participant->getName() . "\n");
											echo("RelatedRecord Participants Invited: " . $participant->getInvited() . "\n");
											echo("RelatedRecord Participants ID: " . $participant->getId() . "\n");
											echo("RelatedRecord Participants Type: " . $participant->getType() . "\n");
											echo("RelatedRecord Participants Participant: " . $participant->getParticipant() . "\n");
											echo("RelatedRecord Participants Status: " . $participant->getStatus() . "\n");
										}
									}
									else if($value[0] instanceof Record)
									{
										$recordList = $value;
										foreach($recordList as $record1)
										{
											//Get the details map
											foreach($record1->getKeyValues() as $key => $value1)
											{
												//Get each value in the map
												echo($key . " : " );
												print_r($value1);
												echo("\n");
											}
										}
									}
									else if($value[0] instanceof LineTax)
									{
										$lineTaxes = $value;
										foreach($lineTaxes as $lineTax)
										{
											echo("RelatedRecord ProductDetails LineTax Percentage: " . $lineTax->getPercentage(). "\n");
											echo("RelatedRecord ProductDetails LineTax Name: " . $lineTax->getName() . "\n");
											echo("RelatedRecord ProductDetails LineTax Id: " . $lineTax->getId() . "\n");
											echo("RelatedRecord ProductDetails LineTax Value: " . $lineTax->getValue(). "\n");
										}
									}
									else if($value[0] instanceof Choice)
									{
										$choice = $value;
										foreach($choice as $choiceValue)
										{
											echo("RelatedRecord " . $keyName . " : " . $choiceValue->getValue() . "\n");
										}
									}
									else if($value[0] instanceof Comment)
									{
										$comments = $value;
										foreach($comments as $comment)
										{
											echo("Record Comment CommentedBy: " . $comment->getCommentedBy() . "\n");
											echo("Record Comment CommentedTime: ");
											print_r($comment->getCommentedTime());
											echo("\n");
											echo("Record Comment CommentContent: " . $comment->getCommentContent(). "\n");
											echo("Record Comment Id: " . $comment->getId() . "\n");
										}
									}
									else if($value[0] instanceof Attachment)
									{
										$attachments = $value;
										foreach ($attachments as $attachment)
										{
											//Get the owner User instance of each attachment
											$owner = $attachment->getOwner();
											//Check if owner is not null
											if($owner != null)
											{
												//Get the Name of the Owner
												echo("RelatedRecord Attachment Owner User-Name: " . $owner->getName() . "\n");
												//Get the ID of the Owner
												echo("RelatedRecord Attachment Owner User-ID: " . $owner->getId() . "\n");
												//Get the Email of the Owner
												echo("RelatedRecord Attachment Owner User-Email: " . $owner->getEmail() . "\n");
											}
											//Get the modified time of each attachment
											echo("RelatedRecord Attachment Modified Time: ");
											print_r($attachment->getModifiedTime());
											echo("\n");
											//Get the name of the File
											echo("RelatedRecord Attachment File Name: " . $attachment->getFileName() . "\n");
											//Get the created time of each attachment
											echo("RelatedRecord Attachment Created Time: " );
											print_r($attachment->getCreatedTime());
											echo("\n");
											//Get the Attachment file size
											echo("RelatedRecord Attachment File Size: " . $attachment->getSize() . "\n");
											//Get the parentId Record instance of each attachment
											$parentId = $attachment->getParentId();
											//Check if parentId is not null
											if($parentId != null)
											{	
												//Get the parent record Name of each attachment
												echo("RelatedRecord Attachment parent record Name: " . $parentId->getKeyValue("name") . "\n");
												//Get the parent record ID of each attachment
												echo("RelatedRecord Attachment parent record ID: " . $parentId->getId() . "\n");
											}
											//Get the attachment is Editable
											echo("RelatedRecord Attachment is Editable: " . $attachment->getEditable() . "\n");
											//Get the file ID of each attachment
											echo("RelatedRecord Attachment File ID: " . $attachment->getFileId() . "\n");
											//Get the type of each attachment
											echo("RelatedRecord Attachment File Type: " . $attachment->getType() . "\n");
											//Get the seModule of each attachment
											echo("RelatedRecord Attachment seModule: " . $attachment->getSeModule() . "\n");
											//Get the modifiedBy User instance of each attachment
											$modifiedBy = $attachment->getModifiedBy();
											//Check if modifiedBy is not null
											if($modifiedBy != null)
											{
												//Get the Name of the modifiedBy User
												echo("RelatedRecord Attachment Modified By User-Name: " . $modifiedBy->getName() . "\n");
												//Get the ID of the modifiedBy User
												echo("RelatedRecord Attachment Modified By User-ID: " . $modifiedBy->getId() . "\n");
												//Get the Email of the modifiedBy User
												echo("RelatedRecord Attachment Modified By User-Email: " . $modifiedBy->getEmail() . "\n");
											}
											//Get the state of each attachment
											echo("RelatedRecord Attachment State: " . $attachment->getState() . "\n");
											//Get the ID of each attachment
											echo("RelatedRecord Attachment ID: " . $attachment->getId() . "\n");
											//Get the createdBy User instance of each attachment
											$createdBy = $attachment->getCreatedBy();
											//Check if createdBy is not null
											if($createdBy != null)
											{
												//Get the name of the createdBy User
												echo("RelatedRecord Attachment Created By User-Name: " . $createdBy->getName() . "\n");
												//Get the ID of the createdBy User
												echo("RelatedRecord Attachment Created By User-ID: " . $createdBy->getId() . "\n");
												//Get the Email of the createdBy User
												echo("RelatedRecord Attachment Created By User-Email: " . $createdBy->getEmail() . "\n");
											}
											//Get the linkUrl of each attachment
											echo("RelatedRecord Attachment LinkUrl: " . $attachment->getLinkUrl() . "\n");
										}
									}
									else
									{
										echo($keyName . " : ");
										print_r($value);
										echo("\n");
									}
								}
								else if($value instanceof Record)
								{
									$recordValue = $value;
									echo("RelatedRecord " . $keyName . " ID: " . $recordValue->getId() . "\n");
									echo("RelatedRecord " . $keyName . " Name: " . $recordValue->getKeyValue("name") . "\n");
								}
								else if($value instanceof Layout)
								{
									$layout = $value;
									if($layout != null)
									{
										echo("RelatedRecord " . $keyName. " ID: " . $layout->getId() . "\n");
										echo("RelatedRecord " . $keyName . " Name: " . $layout->getName() . "\n");
									}
								}
								else if($value instanceof User)
								{
									$user = $value;
									if($user != null)
									{
										echo("RelatedRecord " . $keyName . " User-ID: " . $user->getId() . "\n");
										echo("RelatedRecord " . $keyName . " User-Name: " . $user->getName() . "\n");
										echo("RelatedRecord " . $keyName . " User-Email: " . $user->getEmail() . "\n");
									}
								}
								else if($value instanceof Choice)
								{
									$choiceValue = $value;
									echo("RelatedRecord " . $keyName . " : " . $choiceValue->getValue() . "\n");
								}
								else if($value instanceof Consent)
								{
									$consent = $value;
									echo("RelatedRecord Consent ID: " . $consent->getId());
									//Get the Owner User instance of each attachment
									$owner = $consent->getOwner();
									//Check if owner is not null
									if($owner != null)
									{
										//Get the name of the owner User
										echo("RelatedRecord Consent Owner Name: " . $owner->getName());
										//Get the ID of the owner User
										echo("RelatedRecord Consent Owner ID: " . $owner->getId());
										//Get the Email of the owner User
										echo("RelatedRecord Consent Owner Email: " . $owner->getEmail());
									}
									$consentCreatedBy = $consent->getCreatedBy();
									//Check if createdBy is not null
									if($consentCreatedBy != null)
									{
										//Get the name of the CreatedBy User
										echo("RelatedRecord Consent CreatedBy Name: " . $consentCreatedBy->getName());
										//Get the ID of the CreatedBy User
										echo("RelatedRecord Consent CreatedBy ID: " . $consentCreatedBy->getId());
										//Get the Email of the CreatedBy User
										echo("RelatedRecord Consent CreatedBy Email: " . $consentCreatedBy->getEmail());
									}
									$consentModifiedBy = $consent->getModifiedBy();
									//Check if createdBy is not null
									if($consentModifiedBy != null)
									{
										//Get the name of the ModifiedBy User
										echo("RelatedRecord Consent ModifiedBy Name: " . $consentModifiedBy->getName());
										//Get the ID of the ModifiedBy User
										echo("RelatedRecord Consent ModifiedBy ID: " . $consentModifiedBy->getId());
										//Get the Email of the ModifiedBy User
										echo("RelatedRecord Consent ModifiedBy Email: " . $consentModifiedBy->getEmail());
									}
									echo("RelatedRecord Consent CreatedTime: " . $consent->getCreatedTime());
									echo("RelatedRecord Consent ModifiedTime: " . $consent->getModifiedTime());
									echo("RelatedRecord Consent ContactThroughEmail: " . $consent->getContactThroughEmail());
									echo("RelatedRecord Consent ContactThroughSocial: " . $consent->getContactThroughSocial());
									echo("RelatedRecord Consent ContactThroughSurvey: " . $consent->getContactThroughSurvey());
									echo("RelatedRecord Consent ContactThroughPhone: " . $consent->getContactThroughPhone());
									echo("RelatedRecord Consent MailSentTime: " . $consent->getMailSentTime().toString());
									echo("RelatedRecord Consent ConsentDate: " . $consent->getConsentDate().toString());
									echo("RelatedRecord Consent ConsentRemarks: " . $consent->getConsentRemarks());
									echo("RelatedRecord Consent ConsentThrough: " . $consent->getConsentThrough());
									echo("RelatedRecord Consent DataProcessingBasis: " . $consent->getDataProcessingBasis());
									//To get custom values
									echo("RelatedRecord Consent Lawful Reason: " . $consent->getKeyValue("Lawful_Reason"));
								}
								else
								{
									//Get each value in the map
									echo($keyName . " : ");
									print_r($value);
									echo("\n");
								}
							}
						}
					}
				}
				else if($responseHandler instanceof FileBodyWrapper)
				{
					//Get object from response
					$fileBodyWrapper = $responseHandler;
					//Get StreamWrapper instance from the returned FileBodyWrapper instance
					$streamWrapper = $fileBodyWrapper->getFile();
					//Create a file instance with the absolute_file_path
					$fp = fopen($destinationFolder."/".$streamWrapper->getName(), "w");
					//Get stream from the response
					$stream = $streamWrapper->getStream();
					fputs($fp, $stream);
					fclose($fp);	
				}
				else if($responseHandler instanceof APIException)
				{
					//Get the received APIException instance
					$exception = $responseHandler;
					//Get the Status
					echo("Status: " . $exception->getStatus()->getValue() . "\n");
					//Get the Code
					echo("Code: " . $exception->getCode()->getValue() . "\n");
					echo("Details: " );
					//Get the details map
					foreach($exception->getDetails() as $key => $value)
					{
						//Get each value in the map
						echo($key . " : " . $value . "\n");
					}
					//Get the Message
					echo("Message: " . $exception->getMessage()->getValue() . "\n");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}
 
Update a Related Record
              
              
<?php
namespace com\zoho\crm\sample\relatedrecords;
use com\zoho\crm\api\HeaderMap;
use com\zoho\crm\api\ParameterMap;
use com\zoho\crm\api\layouts\Layout;
use com\zoho\crm\api\record\FileDetails;
use com\zoho\crm\api\record\InventoryLineItems;
use com\zoho\crm\api\record\LineTax;
use com\zoho\crm\api\record\PricingDetails;
use com\zoho\crm\api\relatedrecords\APIException;
use com\zoho\crm\api\relatedrecords\ActionWrapper;
use com\zoho\crm\api\relatedrecords\BodyWrapper;
use com\zoho\crm\api\relatedrecords\RelatedRecordsOperations;
use com\zoho\crm\api\relatedrecords\DelinkRecordsParam;
use com\zoho\crm\api\relatedrecords\GetRelatedRecordHeader;
use com\zoho\crm\api\relatedrecords\GetRelatedRecordsHeader;
use com\zoho\crm\api\relatedrecords\GetRelatedRecordsParam;
use com\zoho\crm\api\relatedrecords\ResponseWrapper;
use com\zoho\crm\api\relatedrecords\SuccessResponse;
use com\zoho\crm\api\tags\Tag;
use com\zoho\crm\api\users\User;
use com\zoho\crm\api\util\Choice;
use com\zoho\crm\api\record\Record;
use com\zoho\crm\api\record\Consent;
use com\zoho\crm\api\record\Comment;
use com\zoho\crm\api\record\Participants;
use com\zoho\crm\api\relatedrecords\FileBodyWrapper;
use com\zoho\crm\api\attachments\Attachment;
class RelatedRecords
{
	/**
	 * Update Related Record
	 * 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 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
	 */
	public static function updateRelatedRecord(string $moduleAPIName, string $recordId, string $relatedListAPIName, string $relatedListId)
	{
		//API Name of the module to update record
		//$moduleAPIName = "Leads";
		//$recordId = "34770615177002";
		//$relatedListAPIName = "Products";
		//$relatedRecordId = "34770614994115";
		//Get instance of RelatedRecordsOperations Class that takes moduleAPIName, recordId and relatedListAPIName as parameter
	    $relatedRecordsOperations = new RelatedRecordsOperations( $relatedListAPIName,  $recordId,  $moduleAPIName);
		//Get instance of BodyWrapper Class that will contain the request body
		$request = new BodyWrapper();
		//List of Record instances
		$records = array();
		//Get instance of Record Class
		$record1 = new Record();
		/*
		 * Call addKeyValue method that takes two arguments
		 * 1 -> A string that is the Field's API Name
		 * 2 -> Value
		 */
		$record1->addKeyValue("list_price", 50.56);
		//Add Record instance to the list
		array_push($records, $record1);
		//Set the list to Records in BodyWrapper instance
		$request->setData($records);
		//Call updateRecord method that takes BodyWrapper instance, relatedRecordId as parameter.
		$response = $relatedRecordsOperations->updateRelatedRecord($relatedListId,$request);
		if($response != null)
		{
			//Get the status code from response
			echo("Status Code: " . $response->getStatusCode() . "\n");
			if($response->isExpected())
			{
				//Get object from response
				$actionHandler = $response->getObject();
				if($actionHandler instanceof ActionWrapper)
				{
					//Get the received ActionWrapper instance
					$actionWrapper = $actionHandler;
					//Get the list of obtained ActionResponse instances
					$actionResponses = $actionWrapper->getData();
					foreach($actionResponses as $actionResponse)
					{
						//Check if the request is successful
						if($actionResponse instanceof SuccessResponse)
						{
							//Get the received SuccessResponse instance
							 $successResponse = $actionResponse;
							//Get the Status
							echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
							//Get the Code
							echo("Code: " . $successResponse->getCode()->getValue() . "\n");
							echo("Details: " );
							//Get the details map
							foreach($successResponse->getDetails() as $key => $value)
							{
								//Get each value in the map
								echo($key . " : " . $value . "\n");
							}
							//Get the Message
							echo("Message: " . $successResponse->getMessage()->getValue() . "\n");
						}
						//Check if the request returned an exception
						else if($actionResponse instanceof APIException)
						{
							//Get the received APIException instance
							$exception = $actionResponse;
							//Get the Status
							echo("Status: " . $exception->getStatus()->getValue() . "\n");
							//Get the Code
							echo("Code: " . $exception->getCode()->getValue() . "\n");
							echo("Details: " );
							//Get the details map
							foreach($exception->getDetails() as $key => $value)
							{
								//Get each value in the map
								echo($key . " : " . $value . "\n");
							}
							//Get the Message
							echo("Message: " . $exception->getMessage()->getValue() . "\n");
						}
					}
				}
				//Check if the request returned an exception
				else if($actionHandler instanceof APIException)
				{
					//Get the received APIException instance
					$exception = $actionHandler;
					//Get the Status
					echo("Status: " . $exception->getStatus()->getValue() . "\n");
					//Get the Code
					echo("Code: " . $exception->getCode()->getValue() . "\n");
					echo("Details: " );
					//Get the details map
					foreach($exception->getDetails() as $key => $value)
					{
						//Get each value in the map
						echo($key . " : " . $value . "\n");
					}
					//Get the Message
					echo("Message: " . $exception->getMessage()->getValue() . "\n");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}