1

I've to Query a field(e.g X) from one object. Say I'm getting 20 records(LIST)

Now, I've to Query another object using result of above Query using field X (X field is common to both objects but has different names, say here Field1 and Field2) What is the easiest way to get data in Developer console ? is below correct

List<string> TP; 
List<ObjA > Ds1=  [Select id, name , TPID__C  
    from QRS_Quote_LOC_Plan_Bundle__c 
    where Field3 = '1111']; // Field3 is some another field

For(ObjA  b : Ds1 )
 TP.add(b.Field1); // storing common field data

List<ObjB> MasterD = [Select id, name from ObjB where Field2 in :TP ];
System.debug(MasterD );
2

You could use Relationship SOQL Queries. First you need to determine what type of relationship the two objects have child-to-parent relationship or vice-versa:

Child-to-parent

SELECT Id, Name, Widget__r.Id, Widget__r.Name
FROM Model__c
WHERE Widget__r.Name LIKE 'Ring%'

Parent-to-child

SELECT Name,
  (
    SELECT Name
    FROM Models__r
  )
FROM Widget__c

You can see more details here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.