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
Nagarjuna Reddy NandireddyNagarjuna Reddy Nandireddy 

How to write a trigger to compare two fields from two different objects in salesforce?

Hi,

SObject1--> Num1(number field)
SObject2--> Num2(number field)
Here Num1value> Num2value i want show an error at Num1 field

Num1value <=Num2 value i dont want to show an error

will you please help me for this 



Thanks,
NANDIREDDY NAGARJUNA REDDY
VamsiVamsi
Hi NAGARJUNA ,

Does these objects have relationship...!!
VamsiVamsi
when You want to validated the data while entering into object 1 or object 2 , If object 2 means then u can achieve with validations
Anupam Bansal (Capgemini)Anupam Bansal (Capgemini)
Hi Nagarjuna,

You dont need a trigger for this. If you create a validation rule on Objx

Objx.Num1 > Objx.ObjY.Num2

Where Objy is the parent object and Objx is the child object and you can create this rule on the Objx. So whenever the value of Num1 is greater than Num2 whether you create a new ObjY record and associate to the Objx record or update Num1 on Objx or Num2 on Objy, will fire.

Thanks
Anupam Bansal
 
Nagarjuna Reddy NandireddyNagarjuna Reddy Nandireddy
Sorry Yarr there is no relation between two objects