How To Get Related Records Data Using Zoho CRM In ASP.NET MVC

Introduction

In this article, we will learn how to get related records data 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 Create Campaigns using Zoho CRM then I recommend you to see that first. in that article, I described how to Create campaigns using Zoho CRM.

C# Code Example

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

public void GetRelatedListData()
 {
     
     try
     {
         ZCRMModule moduleIns = ZCRMModule.GetInstance("leads"); //module api name
         BulkAPIResponse<ZCRMRecord> responseLead = moduleIns.GetRecords();
         List<ZCRMRecord> relatedLists = responseLead.BulkData;

         ZCRMRecord recordIns = ZCRMRecord.GetInstance("Leads", relatedLists[0].EntityId); //module api name with record id
         BulkAPIResponse<ZCRMRecord> response = recordIns.GetRelatedListRecords("campaigns"); //RelatedList api name
         List<ZCRMRecord> relatedRecordsLists = response.BulkData; //relatedRecordsLists - list of ZCRMRecord instance//relatedRecordsLists - list of ZCRMRecord instance
        
     }
     catch (Exception ex)
     {

        
     }
   
 }

 

Update Related Records 

public void UpdatedRelatedData()
{
    try
    {
        ZCRMModule module = ZCRMModule.GetInstance("Leads");
        BulkAPIResponse<ZCRMRecord> responseLead = module.GetRecords();
        List<ZCRMRecord> records = responseLead.BulkData;

        ZCRMRecord recordIns = ZCRMRecord.GetInstance("Leads", records[0].EntityId); //module api name with record id
        ZCRMModule modulecampaigns = ZCRMModule.GetInstance("Campaigns");
        BulkAPIResponse<ZCRMRecord> responseCampaigns = modulecampaigns.GetRecords();
        List<ZCRMRecord> recordsCampaigns = responseCampaigns.BulkData;
        ZCRMJunctionRecord relatedRecord = ZCRMJunctionRecord.GetInstance("Campaigns",Convert.ToInt64(recordsCampaigns[0].EntityId)); //RelatedList api name with RelatedList record id
        relatedRecord.SetRelatedDetails("Status", "active");
        APIResponse response = recordIns.AddRelation(relatedRecord);
        String recStatus = response.Status; //check status of the update relation
                                            //In the above example, lead with ID 337216400000 gets associated with the campaign with ID 33721640000001.
    }
    catch (Exception ex)
    {

       
    }
}

 

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

 

 

Submit a Comment

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

Subscribe

Select Categories