+ Start a Discussion
Mohan SFDC 25Mohan SFDC 25 

How to update the field value which is not direct related

I have a requirement. I have a object obj1 and another obj obj2 which are not direct related. 
obj1 is related to contact and contact is related to obj2. so now my requirement is 
suppose in obj1 if I am inserting a field f1 , then in obj 2 field2 should add the value which already exists and display the total value.
that means suppose in field f1 contains 100 value and obj2 field2 contains 200 values then it should update the field2 values by adding field1 value and display the total value.
Please try to help me.
Thanks in advance
Mohan SFDC 25Mohan SFDC 25
Note : I need to write an apex class not a trigger
Hi Mohan

You can use process builder to call the apex class when some event hs occured. so when you insert some value in field1 of obj1 you have to update the vlaue in the obj2 field 2. you can use process builder which will be invoked when you insert value in field 1 and obj1 and then you can call the apex class to do the update in obj2.

below is the link for your refernce.



Please mark this as a solution, if the above reply answered to your question.
Mohan SFDC 25Mohan SFDC 25
Thank you for the reply, but I have to devlop this in apex class itself. I am not suppose to use any process builder and all.
Mohan SFDC 25Mohan SFDC 25
I have already started a method in my already existing apex class but got stuck in middile.
public static void exapme(List<obj1> lstobj1){
		List<obj1> lstobj= new List<obj1>();
        Set<Id> set1= new Set<Id>();
        Set<Id> set2= new Set<Id>();
        List<obj2> lstobj2= new List<obj2>();
            for(obj1trans :lstobj1){
                if(lstobj1.contactfield!= null) 
		Map<id,obj1> mapobj = new Map<id,obj1>();
		for(obj1 obj: [Select id, (Select id, field1from obj1__r)from contact]){
		Decimal dollar = dollar+field1;
		update dollar;