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
sushanth s 2sushanth s 2 

How to match two different object fields for getting the record details?

Hi all,

Could anyone help me to matching the field with two different objects
1.I Have two objects 1.Case 2.custom object Integration__c.here i'm tring to get
the matching the some fields of both objects.

2.Case object fields for matching AccountName and IntegrationTo__c and Integration__c object fields are account__c,integrationwith__c.

3.if the both object fields are matching then get the record details from Integration__c custom object.
for that i have developed a trigger as after insert on Case object.

trigger IntegrationType on Case (after Insert) {
List<ID> cIds = new List<ID>(); //List<Integration__c> integ = new List<Integration__c>();
for(Case cObj : Trigger.new){
if(cObj.Account.Name != null && cObj.IntegrationTo__c != null){
cIds.add(cObj.Id); //add case ids.
}
}
List<Integration__c> ll = [SELECT id,name,username__c,password__c,URL__c,account__c,integrationwith__c FROM Integration__c WHERE Id=:cIds];
for(Integration__c lst : ll){
if(!cIds.isEmpty()){

//help me here how to match the fields

String uname = lst.username__c;
String pwd= lst.password__c;
String url= lst.URL__c;
System.debug('Username :' +uname);
System.debug('Username :' +pwd);
System.debug('Username :' +url);
}
}
}
NagendraNagendra (Salesforce Developers) 
Hi Sushanth,


I would assume that Integration__c object has a lookup field relating to Case (Case__c).

You can filter the list based on SOQL query and that will be easy to achieve like this:
for(Case cObj : Trigger.new){
      if(cObj.Account.Name != null && cObj.IntegrationTo__c != null){
        cIds.add(cObj.Id); //add case ids.
    } 
}

List<Integration__c> ll  =  [SELECT id,name,username__c,password__c,URL__c,account__c,integrationwith__c 
                            FROM Integration__c  
                            WHERE Case__c IN:cIds
                            AND Case__r.AccountId = account__c
                            AND Case__r.IntegrationTo__c = integrationwith__c ]; 


 for(Integration__c lst : ll){
        //do your stuff here

    }
Hope this helps.

Please mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others.

Regards,
Nagendra.
 
Pranav ChitransPranav Chitrans
Hi Sushanth,

You have to just add two more filter condition uing the and operand in your SOQL queryand then u can that list data in your further logic
 
List<Integration__c> ll = [SELECTid,name,username__c,password__c,URL__c,account__c,integrationwith__c FROM Integration__c WHEREId=:cIds
AND Case__r.AccountId = account__c
AND Case__r.IntegrationTo__c = integrationwith__c ];
Thanks
Pranav