Scala SDK Samples - Pipeline Operations

Transfer and Delete Pipeline
              
              
package com.zoho.crm.sample.pipeline

import java.util
import com.zoho.crm.api.pipeline.{APIException, SuccessResponse, Stage, TransferActionWrapper, TransferAndDeleteWrapper, TransferPipeLine}
import com.zoho.crm.api.pipeline.ActionWrapper
import com.zoho.crm.api.pipeline.PickListValue
import com.zoho.crm.api.pipeline.BodyWrapper
import com.zoho.crm.api.pipeline.ResponseWrapper
import com.zoho.crm.api.pipeline.PipelineOperations
import scala.collection.mutable.ArrayBuffer

object Pipeline {
	/*
	 *   to Transfer And Delete 
	 * This method is used to Transfer And Delete
	 * @param LayoutID The id of the Layout
	 * @throws Exception
	 */
	@throws[Exception]
	def TransferAndDelete(LayoutID: Long) : Unit = {
		//Get instance of PipelineOperations Class
		val pipelineOperations = new PipelineOperations(Option(LayoutID))
		
		//Call transferAndDelete method that takes TransferAndDeleteWrapper instance  
		val request = new TransferAndDeleteWrapper()
		val transferPipelines = new ArrayBuffer[TransferPipeLine] 
		val transferPipeline = new TransferPipeLine()
		val pipeline = new com.zoho.crm.api.pipeline.Pipeline()
		pipeline.setFrom(Option(3652397000003712004L))
		pipeline.setTo(Option(3652397000003712004L))
		transferPipeline.setPipeline(Option(pipeline))
		val stages = new ArrayBuffer[Stage]
		val stage = new Stage()
		stage.setFrom(Option(3652397000000006817L))
		stage.setTo(Option(3652397000000006819L))
		stages.addOne(stage)
		transferPipeline.setStages(stages)
		transferPipelines.addOne(transferPipeline)
		request.setTransferPipeline(transferPipelines)
		val responseOption = pipelineOperations.transferAndDelete(request)
		if (responseOption.isDefined) {
			val response = responseOption.get
			println("Status Code: " + response.getStatusCode)
			if (response.isExpected) {
				//Get object from response
				val transferActionHandler = response.getObject
				
				transferActionHandler match {
					case transferActionWrapper: TransferActionWrapper =>

						val transferPipelines1 = transferActionWrapper.getTransferPipeline

						for (transferPipeline1 <- transferPipelines1) {
							//Check if the request is successful
							transferPipeline1 match {
								case _: SuccessResponse => //Get the received SuccessResponse instance
									val successResponse = transferPipeline1.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)
								case exception: 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)
								case _ =>
							}
						}
					case exception: 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)
					case _ =>
				}
			}
			else {
					val responseObject = response.getModel
					val clas = responseObject.getClass
					val fields = clas.getDeclaredFields
					for (field <- fields) {
							println(field.getName + ":" + field.get(responseObject))
					}
			}
		}
	}
}
class Pipeline {}

 
Get Pipelines
              
              
package com.zoho.crm.sample.pipeline

import java.util
import com.zoho.crm.api.pipeline.{APIException, SuccessResponse, Stage, TransferActionWrapper, TransferAndDeleteWrapper, TransferPipeLine}
import com.zoho.crm.api.pipeline.ActionWrapper
import com.zoho.crm.api.pipeline.PickListValue
import com.zoho.crm.api.pipeline.BodyWrapper
import com.zoho.crm.api.pipeline.ResponseWrapper
import com.zoho.crm.api.pipeline.PipelineOperations
import scala.collection.mutable.ArrayBuffer

object Pipeline {
/*
	 *   Get Pipelines 
	 * This method is used to get Pipelines
	 * @param LayoutID The id of the Layout
	 * @throws Exception
	 */
	@throws[Exception]
	def getPipelines(LayoutID: Long): Unit = {
		//Get instance of PipelineOperations Class
		val pipelineOperations = new PipelineOperations(Option(LayoutID))
		
		//Call getPipeline method
		val responseOption = pipelineOperations.getPipelines()
		
		if (responseOption.isDefined) { //check response
			val response = responseOption.get
			println("Status Code: " + response.getStatusCode)
			if (util.Arrays.asList(204, 304).contains(response.getStatusCode)) {
				println(if (response.getStatusCode == 204) "No Content"
				else "Not Modified")
				return
			}

			//Check if expected response is received
			if (response.isExpected) { //Get object from response
				val responseHandler = response.getObject
				responseHandler match {
					case responseWrapper: ResponseWrapper => //Get the received ResponseWrapper instance

						//Get the list of obtained Pipeline instances
						val pipelines = responseWrapper.getPipeline

						for (pipeline <- pipelines) {
							//Get the ID of each Pipeline
							println("Pipeline ID: " + pipeline.getId())

							//Get the default of each Pipeline
							println("Pipeline default  : " + pipeline.getDefault())

							//Get the Display value of each Pipeline
							println("Pipeline Display value : " + pipeline.getDisplayValue())

							//Get the Actual value of each Pipeline
							println("Pipeline Actual value : " + pipeline.getActualValue())

							//Get the child available of each Pipeline
							println("Pipeline child available  : " + pipeline.getChildAvailable())

							val parentOption = pipeline.getParent()

							if (parentOption.isDefined) {
								val parent = parentOption.get
								//Get the ID of  parent
								println("Pipeline parent ID: " + parent.getId())
							}

							//Get the maps picklist value of each Pipeline
							val maps = pipeline.getMaps()

							for (map <- maps) {
								//Get PickListValue Display Value
								println("PickListValue Display Value" + map.getDisplayValue())
								//Get PickListValue sequence number
								println("PickListValue Sequence Number" + map.getSequenceNumber())

								//Get PickListValue Forecast Category
								val forecastCategoryOption = map.getForecastCategory()
								if (forecastCategoryOption.isDefined) {
									val forecastCategory = forecastCategoryOption.get
									//Get Forecast Category Name
									println("Forecast Category Name" + forecastCategory.getName())
									//Get Forecast Category id
									println("Forecast Category ID" + forecastCategory.getId())
								}

								//Get PickListValue Actual Value
								println("PickListValue Actual Value" + map.getActualValue())

								//Get PickListValue ID
								println("PickListValue ID" + map.getId())
								//Get PickListValue Forecast type
								println("PickListValue Forecast type" + map.getForecastType())
								//Get PickListValue delete
								println("PickListValue delete" + map.getDelete())
							}
						}
						case _ => //Check if the request returned an exception
							responseHandler match {
								case exception: APIException => //Get the received APIException instance
									//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)
								case _ =>
							}
					}
			}
			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))
				}
			}
		}
	}
}
class Pipeline {}
 
Create Pipelines
              
              
package com.zoho.crm.sample.pipeline

import java.util
import com.zoho.crm.api.pipeline.{APIException, SuccessResponse, Stage, TransferActionWrapper, TransferAndDeleteWrapper, TransferPipeLine}
import com.zoho.crm.api.pipeline.ActionWrapper
import com.zoho.crm.api.pipeline.PickListValue
import com.zoho.crm.api.pipeline.BodyWrapper
import com.zoho.crm.api.pipeline.ResponseWrapper
import com.zoho.crm.api.pipeline.PipelineOperations
import scala.collection.mutable.ArrayBuffer

object Pipeline {
/*
	 *   create Pipelines 
	 * This method is used to create Pipelines
	 * @param LayoutID The id of the Layout
	 * @throws Exception
	 */
	@throws[Exception]
	def createPipelines(LayoutID: Long): Unit = {
		//Get instance of PipelineOperations Class
		val pipelineOperations = new PipelineOperations(Option(LayoutID))

		val bodyWrapper = new BodyWrapper()
		val pipelines= new ArrayBuffer[com.zoho.crm.api.pipeline.Pipeline]
		val pipeLine = new com.zoho.crm.api.pipeline.Pipeline()
		pipeLine.setDisplayValue(Option("Adfasfs23d3ew122w313"))
		pipeLine.setDefault(Option(true))
		val maps = new ArrayBuffer[PickListValue]
		val pickListValue = new PickListValue()
		pickListValue.setSequenceNumber(Option(1))
		pickListValue.setId(Option(3477061000000006805l))
		pickListValue.setDisplayValue(Option("Closed Won"))
		maps.addOne(pickListValue)
		pipeLine.setMaps(maps)
		pipelines.addOne(pipeLine)
		
		bodyWrapper.setPipeline(pipelines)
		//Call createPipeline method that takes BodyWrapper instance as parameter 
		val responseOption = pipelineOperations.createPipelines(bodyWrapper)
		
		if (responseOption.isDefined) {
			val response = responseOption.get
			println("Status Code: " + response.getStatusCode)
			if (response.isExpected) {
				val actionHandler = response.getObject
				actionHandler match {
					case actionWrapper: ActionWrapper =>

						//Get the list of obtained ActionResponse instances
						val actionResponses = actionWrapper.getPipeline()

						for (actionResponse <- actionResponses) {
							actionResponse match {
								case successResponse: SuccessResponse => //Get the received SuccessResponse instance
									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)
								case exception: 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)
								case _ =>
							}
						}
					case exception: 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)
					case _ =>
				}
			}
			else {
					val responseObject = response.getModel
					val clas = responseObject.getClass
					val fields = clas.getDeclaredFields
					for (field <- fields) {
							println(field.getName + ":" + field.get(responseObject))
					}
			}
		}
	}
}
class Pipeline {}
 
Update Pipelines
              
              
package com.zoho.crm.sample.pipeline

import java.util
import com.zoho.crm.api.pipeline.{APIException, SuccessResponse, Stage, TransferActionWrapper, TransferAndDeleteWrapper, TransferPipeLine}
import com.zoho.crm.api.pipeline.ActionWrapper
import com.zoho.crm.api.pipeline.PickListValue
import com.zoho.crm.api.pipeline.BodyWrapper
import com.zoho.crm.api.pipeline.ResponseWrapper
import com.zoho.crm.api.pipeline.PipelineOperations
import scala.collection.mutable.ArrayBuffer

object Pipeline {
/*
	 *   update Pipelines 
	 * This method is used to update Pipelines
	 * @param LayoutID The id of the Layout
	 * @throws Exception
	 */
	@throws[Exception]
	def updatePipelines(LayoutID: Long): Unit = {
		val bodyWrapper = new BodyWrapper()
		val pipelines= new ArrayBuffer[com.zoho.crm.api.pipeline.Pipeline]
		val pipeLine = new com.zoho.crm.api.pipeline.Pipeline()
		pipeLine.setDisplayValue(Option("Pipeline222"))
		pipeLine.setDefault(Option(true))
		val maps = new ArrayBuffer[PickListValue]
		val pickListValue = new PickListValue()
		pickListValue.setSequenceNumber(Option(1))
		pickListValue.setId(Option(3477061000000006801l))
		pickListValue.setDisplayValue(Option("Closed Won"))
		maps.addOne(pickListValue )
		pipeLine.setMaps(maps)
		pipelines.addOne(pipeLine)
		pipeLine.setId(Option(3477061000009599012l))
		
		bodyWrapper.setPipeline(pipelines)
		//Get instance of PipelineOperations Class
		val pipelineOperations = new PipelineOperations(Option(LayoutID))
		
		//Call updatePipelines method that takes BodyWrapper instance as parameter 
		val responseOption = pipelineOperations.updatePipelines(bodyWrapper)
		
		if (responseOption.isDefined) {
			val response = responseOption.get
			println("Status Code: " + response.getStatusCode)
			if (response.isExpected) {
				val actionHandler = response.getObject
				actionHandler match {
					case actionWrapper: ActionWrapper =>

						//Get the list of obtained ActionResponse instances
						val actionResponses = actionWrapper.getPipeline

						for (actionResponse <- actionResponses) { //Check if the request is successful
							actionResponse match {
								case successResponse: SuccessResponse => //Get the received SuccessResponse instance
									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)
								case exception: 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)
								case _ =>
							}
						}
						case exception: 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)
						case _ =>
				}
			}
			else {
					val responseObject = response.getModel
					val clas = responseObject.getClass
					val fields = clas.getDeclaredFields
					for (field <- fields) {
					println(field.getName + ":" + field.get(responseObject))
					}
			}
		}
	}
}
class Pipeline {}
 
Get Pipeline
              
              
package com.zoho.crm.sample.pipeline

import java.util
import com.zoho.crm.api.pipeline.{APIException, SuccessResponse, Stage, TransferActionWrapper, TransferAndDeleteWrapper, TransferPipeLine}
import com.zoho.crm.api.pipeline.ActionWrapper
import com.zoho.crm.api.pipeline.PickListValue
import com.zoho.crm.api.pipeline.BodyWrapper
import com.zoho.crm.api.pipeline.ResponseWrapper
import com.zoho.crm.api.pipeline.PipelineOperations
import scala.collection.mutable.ArrayBuffer

object Pipeline {
/*
	 *   Get Pipeline 
	 * This method is used to get single Pipeline
	 * @param LayoutID The id of the Layout
	 * @param pipelineID The id of the pipeline
	 * @throws Exception
	 */
	@throws[Exception]
	def getPipeline(LayoutID: Long, pipelineID: Long): Unit = {
		//Get instance of PipelineOperations Class
		val pipelineOperations = new PipelineOperations(Option(LayoutID))
		
		//Call getPipeline method
		val responseOption = pipelineOperations.getPipeline(pipelineID)
				
		if (responseOption.isDefined) { //check response
			val response = responseOption.get
			println("Status Code: " + response.getStatusCode)
			if (util.Arrays.asList(204, 304).contains(response.getStatusCode)) {
				println(if (response.getStatusCode == 204) "No Content"
				else "Not Modified")
				return
			}
			
			// Check if expected response is received
			if (response.isExpected) {
				// Get object from response
				val responseHandler = response.getObject

				responseHandler match {
					case responseWrapper: ResponseWrapper => //Get the received ResponseWrapper instance

						//Get the list of obtained Pipeline instances
						val pipelines = responseWrapper.getPipeline()

						for (pipeline <- pipelines) {
							//Get the ID of each Pipeline
							println("Pipeline ID: " + pipeline.getId())

							//Get the Display value of each Pipeline
							println("Pipeline Display value : " + pipeline.getDisplayValue())

							//Get the Actual value of each Pipeline
							println("Pipeline Actual value : " + pipeline.getActualValue())

							//Get the default of each Pipeline
							println("Pipeline default  : " + pipeline.getDefault())

							//Get the child available of each Pipeline
							println("Pipeline child available  : " + pipeline.getChildAvailable())

							val parentOption = pipeline.getParent()
							if (parentOption.isDefined) {
								val parent = parentOption.get
								//Get the ID of  parent
								println("Pipeline parent ID: " + parent.getId())
							}
							//Get the maps picklist value of each Pipeline
							val maps = pipeline.getMaps()

							for (map <- maps) {
								//Get PickListValue Actual Value
								println("PickListValue Actual Value" + map.getActualValue())
								//Get PickListValue delete
								println("PickListValue delete" + map.getDelete())
								//Get PickListValue Display Value
								println("PickListValue Display Value" + map.getDisplayValue())
								//Get PickListValue Forecast Category
								val forecastCategoryOption = map.getForecastCategory()
								if (forecastCategoryOption.isDefined) {
									val forecastCategory = forecastCategoryOption.get
									//Get Forecast Category Name
									println("Forecast Category Name" + forecastCategory.getName())
									//Get Forecast Category id
									println("Forecast Category ID" + forecastCategory.getId())
								}
								//Get PickListValue Forecast type
								println("PickListValue Forecast type" + map.getForecastType())
								//Get PickListValue ID
								println("PickListValue ID" + map.getId())
								//Get PickListValue sequence number
								println("PickListValue sequence number" + map.getSequenceNumber())
							}
						}
					case _ => //Check if the request returned an exception
						responseHandler match {
							case exception: APIException => //Get the received APIException instance
								//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)
							case _ =>
						}
				}
			}
			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))
				}
			}
		}
	}
}
class Pipeline {}
 
Update Pipeline
              
              
package com.zoho.crm.sample.pipeline

import java.util
import com.zoho.crm.api.pipeline.{APIException, SuccessResponse, Stage, TransferActionWrapper, TransferAndDeleteWrapper, TransferPipeLine}
import com.zoho.crm.api.pipeline.ActionWrapper
import com.zoho.crm.api.pipeline.PickListValue
import com.zoho.crm.api.pipeline.BodyWrapper
import com.zoho.crm.api.pipeline.ResponseWrapper
import com.zoho.crm.api.pipeline.PipelineOperations
import scala.collection.mutable.ArrayBuffer

object Pipeline {
/*
	 *   update Pipeline 
	 * This method is used to update Pipeline
	 * @param LayoutID The id of the Layout
	 * @param pipelineID The id of the pipeline
	 * @throws Exception
	 */
	@throws[Exception]
	def updatePipeline(LayoutID: Long, pipelineID: Long) : Unit = {
		val bodyWrapper = new BodyWrapper()
		val pipelines= new ArrayBuffer[com.zoho.crm.api.pipeline.Pipeline]()
		val pipeLine = new com.zoho.crm.api.pipeline.Pipeline()
		pipeLine.setDisplayValue(Option("Adfasfsad112"))
		pipeLine.setDefault(Option(true))
		val maps = new ArrayBuffer[PickListValue]
		val pickListValue = new PickListValue()
		pickListValue.setSequenceNumber(Option(1))
		pickListValue.setId(Option(3477061000000006801l))
		pickListValue.setDisplayValue(Option("Adfasfsad112"))
		maps.addOne(pickListValue )
		pipeLine.setMaps(maps)
		pipelines.addOne(pipeLine)
		
		bodyWrapper.setPipeline(pipelines)
		//Get instance of PipelineOperations Class
		val pipelineOperations = new PipelineOperations(Option(LayoutID))
		
		//Call updatePipeline method that takes BodyWrapper instance as parameter 
		val responseOption = pipelineOperations.updatePipeline(pipelineID, bodyWrapper)
		
		if (responseOption.isDefined) {
			val response = responseOption.get
			println("Status Code: " + response.getStatusCode)
			//Check if expected response is received
			if (response.isExpected) {
				val actionHandler = response.getObject
				actionHandler match {
					case actionWrapper: ActionWrapper =>

						//Get the list of obtained ActionResponse instances
						val actionResponses = actionWrapper.getPipeline()

						for (actionResponse <- actionResponses) { //Check if the request is successful
							actionResponse match {
								case successResponse: SuccessResponse => //Get the received SuccessResponse instance
									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)
								case exception: 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)
								case _ =>
							}
						}
					case exception: 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)
					case _ =>
				}
			}
			else {
					val responseObject = response.getModel
					val clas = responseObject.getClass
					val fields = clas.getDeclaredFields
					for (field <- fields) {
					println(field.getName + ":" + field.get(responseObject))
					}
			}
		}
	}
}
class Pipeline {}