+ Start a Discussion
Pete RuddPete Rudd 

Reference custom fields on two different objects

I have been advised I need an Apex Trigger.

 

I have a custom field on both Accounts and Leads (text field) called Reg Num and I also have another custom field (check-box) on Leads called Reg Num matches an account.

I would like the check-box to show a tick if the Reg Num on the Lead matches the Reg Num of any account.

How / where do I do this?

Thanks in advance.

Shashikant SharmaShashikant Sharma

You need Two triggers

1) On Account :

     If the Reg Num changes then you need to check Reg Num in Lead and if matches then set Reg Num check box to true

2) On Lead

     If the Reg Num changes then you need to check Reg Num in Account and if matches then set Reg Num check box to true

 

you can read this to get help in writing trigger

 

http://forceschool.blogspot.com/2011/05/hi-all-triggers-are-very-essential-in.html

Ispita_NavatarIspita_Navatar

Hi,

 

You can try the following trigger on Lead

 

                trigger checkReg_Num  on Lead (before insert,before update)

                {

                                if(trigger.Isinsert)

                                {

                                                lead l1=trigger.new[0];

                                                list<account> a1=[select a.id from account a where  a.Reg_Num__c=:l1.Reg_Num__c];

                                                if(a1.size()>0)

                                                {

                                                                l1.Reg_Num_check__c=true;

                                                }

                                }

 

                }

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

Pete RuddPete Rudd

I really appreciate the help that has been given.