function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Abhishek Sharma 527Abhishek Sharma 527 

Merge of 2 SOQL queries

Hello Dev, I'm trying to merge 2 SOQL queries into one. I don't know with which field it can be linked between case and event because when I'm trying with query -
Select Subject, Id, Facilities__c from event WHERE Event.WhatId = case.id 

it doesn't return anything. I believe with WhatId it can be linked but not getting proper way to implement this.
My 2 queries are - 
List<Event> nonBill = [Select Subject, Id, Facilities__c, Services__c, Appointment_Status__c, OwnerId, WhoId,ActivityDateTime, ActivityDate, WhatId,Facilities__r.Address_1__c,Facilities__r.City__c, Facilities__r.Name,Facilities__r.Country__c, Sup_Provider__c,Sup_Provider__r.Name, Owner.FirstName, Owner.MiddleName, Owner.LastName,EndDateTime, Facilities__r.State__c, Sup_Provider__r.Provider_Role__c FROM Event WHERE IsRecurrence = false AND Appointment_Status__c = 'Non-Billable'];
        
	List<Case> sessionRecords = [SELECT Id, CaseNumber, Type, RecordTypeId, Status, Reason, Origin, Subject, Priority, Description, CreatedDate, CreatedById, Comments, Duration__c, To_DOS__c, DC_Unit__c, First_Bill_Date__c, Last_Bill_Date__c, Appointment_End_Time__c, Balance__c, Billed_Amount__c, Appointment_Start_Time__c,Cal_Bal_Amt__c, Cal_Total_Patient_Bal__c,Practice_Insurance_Service__c, Client_Insurance__c, Sup_Provider__c, Claim_Number__c, Session_Summary__c, DOS__c, Labels__c,Enter_Bill_Amount__c, Total_Billed_Units__c, Total_Amounts__c, Session_Notes__c, Provider__c, Practice__c, Session_Note_Status__c, Unit__c, PA_NO_PA__c, Client_Name__c,Provider_Name__c, Location_Name__c, Insurance_Name__c, Authorization_Number__c, Self_Pay__c, Billable_Duration_in_Minutes__c, Non_Billable_Duration_in_Minutes__c,Non_Billable_Unit__c, Session_Completed_By__c FROM Case];

Please if anyone can guide on this. It will be great help !!
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Abshishek,

Regarding the first query do you have any events that are related to the Case object?

Because you said you are not getting results for query 1.

For the second once you said you want to combine two queries, Can you confirm what exactly do you need from those tqo queries. Do you need list of cases related to the Event ids ?

Thanks,
 
Abhishek Sharma 527Abhishek Sharma 527
Thanks for response Sai, basically these are not 2 different question but only 1 question and that requirement is to take result of those arrays and combine them to create new array I'm getting the array of records for each query in LWC and I want to merge that such that Case and it's corresponding Event should be shown. for 1 case there will be 1 Event only. kindly check the screenshot attached, these are 2 arrays i.e. cs and evt [image: image.png] Please suggest..
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Abhishek,

I don't see any attachment in your comment. Can you upload if possible.

Thanks,
 
Abhishek Sharma 527Abhishek Sharma 527
Hello Sai, kindly find the attachment. Regards, Abhishek