How To Update And Delete Contact Using Zoho CRM In ASP.NET MVC

Introduction

In this article, we will learn how to update and delete contacts using Zoho CRM in ASP.NET MVC Web application.

Let’s begin

Please read this article first of all here.

If you have not seen How To Get All Contacts Data then I recommend you to see that first. in that article, I described how to get all contacts data using Zoho CRM

C# Code Example

Open the HomeController.cs file and add the below code in it.

Update Contact

public void UpdateContact()
 {
         ZCRMModule moduleInsAccounr = ZCRMModule.GetInstance("accounts"); //module api name
         BulkAPIResponse<ZCRMRecord> responseAccount = moduleInsAccounr.GetRecords();
         List<ZCRMRecord> relatedListsAccount = responseAccount.BulkData;

         List<ZCRMRecord> listRecord = new List<ZCRMRecord>();
         ZCRMRecord record;

         record = new ZCRMRecord("contacts"); //To get ZCRMRecord instance
         record.SetFieldValue("id", contact id);
         record.SetFieldValue("Email", "test@gmail.com"); //This method use to set FieldApiName and value similar to all other FieldApis and Custom field
         record.SetFieldValue(relatedListsAccount[0].CreatedBy.FullName, relatedListsAccount[0].CreatedBy.Id);
         record.SetFieldValue("Company", "KK1");
         record.SetFieldValue("Last_Name", "User1");
         record.SetFieldValue("First_Name", "test1");
         record.SetFieldValue("Phone", "02122020");

         listRecord.Add(record);
         ZCRMModule moduleInslead = ZCRMModule.GetInstance("contacts"); //To get the Module instance
         BulkAPIResponse<ZCRMRecord> responseIns = moduleInslead.UpdateRecords(listRecord); //To call the Update record method
         Console.WriteLine("HTTP Status Code:" + responseIns.HttpStatusCode);
 }

Delete Contact

public void DeleteContact()
  {
      ZCRMRecord record = ZCRMRecord.GetInstance("contacts", contact id);//module api name with record id
      APIResponse response1 = record.Delete();
  }

if you have any questions or issues about this article, please let me know and you can find more details here.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories