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
RajKumaR MRajKumaR M 

Can any one help me on this issue ASAP?

Hi,

I wrote a trigger that updates the field value from one object to another object. I need to reflect the filed value for all the object records if i entered the value in another object.

Object A - Custom Field 1
Object B - Custom Field 2.

I need to reflect "Custom Field 2" from the Object B to all the records in Object A - Custom Field 1.

How can i achive this?
RajKumaR MRajKumaR M
Can any one tried like this before?
SKolakanSKolakan
Hi,

You can use this generic function
public Static List<sObject> setFieldValue(List<sObject> oList,String fieldName,String fieldValue){   
       for(sObject o:oList)
       {
            o.put(fieldName,fieldValue);        
        }
        return oList; 
}


You can query and get your custom field2 and then you can query custom field1 like

List<customObjectA> cObjs = [Select Id, CustomField1 From customObjectA];
//assuming valueToReplace variable contains the value you extracted from custom field2 of object B
udpate setFieldValue(cObjs,'customField1', valueToReplace);