2

I have two objects:

  • object1__c, which has a text field called sds__c and a picklist field called sds_chek__c (values "Yes"/"No")
  • object2__c contain a text field called sds__c

Here, I want to compare both objects' sdc_c values. If any records match, then in the object1__c picklist field populate with "Yes". If not match even one record also, the picklist value should populate with "No".

Please any one can help me!

8
  • Can you share the code that you have tried?
    – Sam
    Commented Mar 6, 2014 at 11:49
  • Do you mean that, for example If value of sds_c = "text"(object1_c) and if there is any record containing "text" in object2_c then picklist field value on that record(object1_c) should be changed to "yes" ? Commented Mar 6, 2014 at 12:03
  • As pointed out already by Rahul, pls indicate the relationship between object1__c and object2__c Commented Mar 6, 2014 at 12:22
  • no relationship in between the objects both are different.
    – ravi
    Commented Mar 6, 2014 at 13:14
  • hi rahul yes that is my scenario what did u understand that is only
    – ravi
    Commented Mar 6, 2014 at 13:18

1 Answer 1

1

How about trigger compare? You must create 2 triggers make it work.

on object 2 you must have after insert/update (and before delete but I will skip it) actions in method:

Set<String> matchedFields = new Set<String>();
object_1__c[] obj1List = new object_1__c[]{};

for(object_2__c obj : Trigger.new){
    matchedFields.add(sds__c);
}

for(object_1__c obj : [SELECT Id, sds_chek__c
                       FROM object_1__c
                       WHERE sds__c IN : matchedFields]){

   if(obj.sds_chek__c == 'No'){
       obj.sds_chek__c = 'Yes';
       obj1List.add(obj)
   }
}

update obj1List;

You should also have trigger on before insert object_1__c that will check if in system already is some matching record

If you have any other question please let me know

7
  • thank you for giving reply. can we implement this same senario in batch apex? if it is passble please let me know i have to impliment this code in batch class only
    – ravi
    Commented Mar 7, 2014 at 7:13
  • In Batch you can implement it, but mayby better idea would be to use Object1__c as base... How many records each type you have? Commented Mar 7, 2014 at 7:45
  • 1000 records i have to upload into object1 every week on monday
    – ravi
    Commented Mar 7, 2014 at 8:37
  • how about object 2 - are those records deleted/created offten? Commented Mar 7, 2014 at 8:44
  • object2 data created
    – ravi
    Commented Mar 7, 2014 at 9:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .