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
PraviPravi 

want to create utility class which access the data of Custom object with case

i want to write a utility class, class name: XYZ, Custom Object Name: ABC__c, Field Name: C_ABC__c
class XYZ access the data from ABC__c but for a Case(Case Object is lookup with field C_ABC__c)
My Understanding: if I want to access data of custom object related to case then i need to fetch the Case ID, if i fetch the Case Id then i get the data related with ABC__c
I Try this:
public class XYZ{ public static List<ABC__c> str(String Name){ List<ABC__c> alist = new List<ABC__c>(); //this line is just for try
List<ABC__c> alist = [Select Id From ABC__c];
} return alist; }

I am stuck, how i access the data ABC__c from Case
Best Answer chosen by Pravi
mukesh guptamukesh gupta
Hi Parvi

Please follow below code:-
 
List<Case> cList = [Select Id, (Select Id, Name from ABC(relationshipName) ) From Case ]
  
  
  for(ABC__c abc : cList.ABC){
   // you can access ABC__c object details from case
   // like abc.Id ,abc.Name etc
  
  }

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh

All Answers

mukesh guptamukesh gupta
Hi Parvi

Please follow below code:-
 
List<Case> cList = [Select Id, (Select Id, Name from ABC(relationshipName) ) From Case ]
  
  
  for(ABC__c abc : cList.ABC){
   // you can access ABC__c object details from case
   // like abc.Id ,abc.Name etc
  
  }

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh
This was selected as the best answer
PraviPravi
Hi Mukesh, 
Thank you for your help,
i want some more help, i don't understand 3rd point
i need to full fill those points
Input Parameter Case Id, Fetch C_ABC__c from Case using Case ID, Use the ID returned to get the row from ABC__c, Return the List 
 
mukesh guptamukesh gupta
Hi Pravi,



some thing like that:-
Set<Id> caseIds = new Set<Id>();

// you need to store case Id in 

caseIds.add(case.id);

List<Case> cList = [Select Id, (Select Id, Name from ABC(relationshipName) ) From Case Where Id IN: caseIds ]
  
  
  for(ABC__c abc : cList.ABC){
   // you can access ABC__c object details from case
   // like abc.Id ,abc.Name etc
  
  }


Thanks
Mukesh
PraviPravi
Thank you so much Mukesh,
PraviPravi
Hi Mukesh,
i write the following code,

public class Utility {
    public static List<ABC__c> CABC (String Name){
    
        Set<Id> caseIds = new Set<Id>(); // store case Id in 
        caseIds.add(case.id);

        List<Case> cList = [Select Id, (Select Id, Name from Vehicle__c(relationshipname) ) From Case Where Id IN: caseIds];
  
        for(ABC__c abc : cList.Vehicle__c) //access ABC__c object details from case
        {
          List<ABC__c> Vlist = abc.relationshipname;
   
          for(ABC__c abc : cList){
                System.debug('ccc : ' + Vlist.ccc__c + ); // like abc.Id ,abc.Name etc
           }
      } 
    }    
  }  

now i want to return some field in this utility method,
so i use
List<ABC__c> abc = new <List ABC__c>();

ABC__c pqr = new ABC__C;
pqr.Name = 'ram';
pqr.Year = '2000';

how i return fields without giving some manual data?