iOS SDK Samples - Records Operations

Get a List of Records with the "recordParam"
          
          
var recParam : ZCRMQuery.GetRecordParams = ZCRMQuery.GetRecordParams()
recParam.modifiedSince = "2018-08-17T04:34:35+05:30"
/*- Parameters:
        - recordParams :  Record parameters are given as an object.*/
// module is the object of getModuleDelegate()
$module.getRecords(recordParams: recParam) { ( result ) in
 switch result
   {
     case .success(let records, let response) :
        print ("ResponseJSON : \( response.responseJSON )")
      case .failure(let error) :
        print ( "Throws exception : \(error)" )
            }
}
 
Get a list of Records with "record", "cvId" and "filterId" params
          
          
/*- Parameters:
        - cvId : The custom view ID from which the records has to be fetched
        - filterId : The filterId to be applied to fetch the records
        - recordParams : Record parameters are given as an object.*/
var recParam : ZCRMQuery.GetRecordParams = ZCRMQuery.GetRecordParams()
        recParam.modifiedSince = "2018-08-17T04:34:35+05:30"
// module is the object of getModuleDelegate()
$module.getRecords(cvId : 778942575, filterId : 9944368964, recordParams: recParam) { ( result ) in
            switch result
            {
            case .success(let records, let response) :
                            print ("ResponseJSON : \( response.responseJSON )")
                        case .failure(let error) :
                            print ( "Throws exception : \(error)" )
            }
        }
 
Get a Record
          
          
// module is the object of getModuleDelegate()
$omdule.getRecord(id : 778942575) { ( result ) in
            switch result
            {
            case .success(let records, let response) :
                            print ("ResponseJSON : \( response.responseJSON )")
                        case .failure(let error) :
                            print ( "Throws exception : \(error)" )
            }
        }
 
Insert a Record
          
          
let record = ZCRMSDKUtil.getModuleDelegate(apiName: "leads").newRecord()
        record.setValue(ofFieldAPIName: "Last_Name", value: "Belly")
        record.setValue(ofFieldAPIName: "email", value: "ben@gmail.com")
        record.create { ( result ) in
           switch result
            {
              case .success(let data, let response ) :
              print ("ResponseJSON : \( response.responseJSON )")
               case .failure( let error ) :
               print ( "Throws exception : \(error)" )
            }
  }
 
Update Record with ID and without "triggers"
          
          
// module is the object of getModuleDelegate()
$module.updateRecords(recordIds : [8877310934, 87877631193, 763654138948], fieldAPIName : "name", value : "R&X records"){ ( result ) in
switch result
 {
  case .success( let records, let response ) :
    print ("ResponseJSON : \( response.responseJS$ON )")
  case .failure( let error ) :
    print ( "Throws exception : \(error)" )
  }
}
 
Update Record with ID and "triggers"
          
          
/*- Parameters:
        - triggers : list of Triggers.*/
// module is the object of getModuleDelegate()
$module.updateRecords(recordIds: [8877310934, 87877631193, 763654138948], fieldAPIName: "name", value: "CRM", triggers: [Trigger.approval, Trigger.bluePrint]) { ( result ) in
            switch result
            {
            case .success( let records, let response ) :
              print ("ResponseJSON : \( response.responseJSON )")
            case .failure( let error ) :
              print ( "Throws exception : \(error)" )
        }
    }
 
Update Record with object and without "triggers"
          
          
// module is the object of getModuleDelegate()
// records is an array of ZCRMRecord.
$module.updateRecords(records : records, fieldAPIName : "name", value : "R&X records"){ ( result ) in
switch result
 {
  case .success( let records, let response ) :
    print ("ResponseJSON : \( response.responseJS$ON )")
  case .failure( let error ) :
    print ( "Throws exception : \(error)" )
  }
}
 
Update Record with object and "triggers"
          
          
/*- Parameters:
        - triggers : list of Triggers.*/
// records is an array of ZCRMRecords.
// module is the object of getModuleDelegate()
$module.updateRecords(records: records, fieldAPIName: "name", value: "CRM", triggers: [Trigger.approval, Trigger.bluePrint]) { ( result ) in
            switch result
            {
            case .success( let records, let response ) :
              print ("ResponseJSON : \( response.responseJSON )")
            case .failure( let error ) :
              print ( "Throws exception : \(error)" )
        }
    }

 
Upsert Records
          
          
let leadDetails = try upsertRecordDetails.getDictionary(key: "LeadDetails")
        let recordDetails = try leadDetails.getArrayOfDictionaries(key: "Records")
        guard let duplicateCheckFields = try leadDetails.getArray(key: "duplicateCheckFields") as? [ String ] else
        {
            print("Failed to get duplicateCheckFields")
            return
        }
        var records : [ ZCRMRecord ] = []
        for recordDetail in recordDetails
        {
            let record = ZCRMSDKUtil.getModuleDelegate(apiName: DefaultModuleAPINames.LEADS).newRecord()
            for ( key, value ) in recordDetail
            {
                record.setValue(ofFieldAPIName: key, value: value)
            }
            records.append( record )
        }
/*- Parameters:
        - triggers : list of Triggers.
        - records : list of ZCRMRecord objects to be upserted
        - duplicateCheckFields : list of Fields to be duplicate checked.*/
 $module.upsertRecords(triggers : [Trigger.workFlow, Trigger.approval], records: records, duplicateCheckFields: duplicateCheckFields) { ( result ) in
            switch result
            {
              case .success( let records, let response ) :
                print ("ResponseJSON : \( response.responseJSON )")
              case .failure( let error ) :
                print ( "Throws exception : \(error)" )
            }
        }
 
Delete a Record
          
          
// record is the object of getRecord()

      record.delete { ( result ) in
        switch result
          {
          case .success(let response) :
            print ("ResponseJSON : \( response.responseJSON )")
			 case .failure(let error) :
            print ( "Throws exception : \(error)" )
             }
            }
 
Delete Records
          
          
let deletedRecordIds : [ Int64 ] = [88xxx934, 87xxx193, 76xxx48]
// module is the object of getModuleDelegate()
$module.deleteRecords(byIds: deletedRecordIds) { result in
switch result
   {
   case .success(let record, let response) :
     print ("ResponseJSON : \( response.responseJSON )")
   case .failure(let error) :
     print ( "Throws exception : \(error)" )
    }
}
 
Get the Deleted Records
          
          
var params = ZCRMQuery.getRequestParams
        params.page = 1
        params.perPage = 10
        params.modifiedSince = "2020-08-06T16:23:24+05:30"
/*- Parameters:
        - ofType : Specify the type of deleted records to be fetched
            - all : All the deleted records
            - recycle : The deleted records that are in recycle bin
            - permanent : The records that are permanently deleted*/
$module.getTrashRecords(ofType: .all, withParams: params) { ( result ) in
            switch result
            {
            case .success(let record, let response) :
                  print ("ResponseJSON : \( response.responseJSON )")
                  case .failure(let error) :
                  print ( "Throws exception : \(error)" )
            }
        }
 
Search records by Text
          
          
// module is the object of getModuleDelegate()
$module.searchBy (text : " high priority" ){ ( result ) in
 switch result
   {
   case .success( let records, let response ) :
       print ("ResponseJSON : \( response.responseJSON )")
   case .failure(let error) :
       print ( "Throws exception : \(error)" )
      }
}
 
Search Records by Phone
          
          
// module is the object of getModuleDelegate()
$module.searchBy (phone : "567898765456" ){ ( result ) in
 switch result
   {
   case .success( let records, let response ) :
       print ("ResponseJSON : \( response.responseJSON )")
   case .failure(let error) :
       print ( "Throws exception : \(error)" )
      }
}
 
Search Records by Email
          
          
// module is the object of getModuleDelegate()
$module.searchBy (email : "CRM@zoho.com" ){ ( result ) in
 switch result
   {
   case .success( let records, let response ) :
       print ("ResponseJSON : \( response.responseJSON )")
   case .failure(let error) :
       print ( "Throws exception : \(error)" )
      }
}
 
Search Records by criteria, page and per_page
          
          
let criteria1 = ZCRMQuery.ZCRMCriteria(apiName: "Last_Name", comparator: .string(.equals)  , value: "Bob")
 let criteria2 = ZCRMQuery.ZCRMCriteria(apiName: "First_Name", comparator: .string(.contains)  , value: "Marx")
 criteria1.and(criteria: criteria2)
// module is the object of getModuleDelegate()
$module.searchBy(criteria: criteria1, page : 7, perPage: 25
) { ( result ) in
            switch result
            {
            case .success( let records, let response ) :
                   print ("ResponseJSON : \( response.responseJSON )")
               case .failure(let error) :
                   print ( "Throws exception : \(error)" )
        }
    }
 
Convert a Lead
          
          
let leadDetails = try recordDetails.getDictionary(key: "LeadDetails").getDictionary(key: "fieldValues")
// record is the object of getRecordDelegate()
        for ( key, value ) in leadDetails
        {
            $record.setValue(ofFieldAPIName: key, value: value)
        }
        $record.convert { ( result ) in
            switch result
            {
            case .success(let record, let response) :
                   print ("ResponseJSON : \( response.responseJSON )")
                   case .failure(let error) :
                   print ( "Throws exception : \(error)" )
            }
        }