You need to sign in to do that
Don't have an account?
ebiki
compare th email and phone through trigger
Hi all,
I'm new to slaesforce can anyone help me to write a trigger to compare the email and phone number in leads with custom object while inserting, if bothe are same then I want to update the field in my custom object.
Thanks in advance.
Regards,
ebiz.
I'm new to slaesforce can anyone help me to write a trigger to compare the email and phone number in leads with custom object while inserting, if bothe are same then I want to update the field in my custom object.
Thanks in advance.
Regards,
ebiz.
try this code...
trigger leadDatavalidation on Lead (after insert) {
list<string> Email = new list<string> ();
list<string> phone = new list<string> ();
list<shobithapp__Test_Object__c> test = new list<shobithapp__Test_Object__c> ();
list<shobithapp__Test_Object__c> test1 = new list<shobithapp__Test_Object__c> ();
list<shobithapp__Test_Object__c> test2 = new list<shobithapp__Test_Object__c> ();
for(Lead L :trigger.new){
if (L.Email!= null){
Email.add(L.Email);
}
if (L.Phone!= null){
phone.add(L.Phone);
}
}
test1=[SELECT id,shobithapp__email__c,shobithapp__Phone__c,shobithapp__Record_Type__c FROM shobithapp__Test_Object__c WHERE shobithapp__email__c IN : Email ];
test=[select shobithapp__Phone__c,shobithapp__email__c,shobithapp__Record_Type__c from shobithapp__Test_Object__c where Id IN: test1];
system.debug('////'+test);
for(shobithapp__Test_Object__c t :test){
if(test.size()!=null){
t.shobithapp__Record_Type__c='duplicate';
test2.add(t);
}
else
{
t.shobithapp__Record_Type__c='original';
test2.add(t);
}
}
update test2;
}
In the last If condition ..you can change the condition upon your requirement....
hope this helps you..
thanks
Vishnu R
All Answers
can you explain it further because i am not getting your requirement
Add this code in custom object trigger .
Regards ,
Harish.R
I don't want to prevent the duplicate record, I want to verify the email and phone number of the Lead object is matching with any of the custom object email and phone number. If they are matched then update the picklist filed in my custom object.
So ucan modify last lines below code
If (id.size() != null )
{
cust.picklistapi = 'enter your values ' ;
}
Ask me any issue .
Reagrds ,
Harish.R
try this code..it is working for me....
trigger Datavalidationtrigger on shobithapp__Test_Object__c (before insert,before update) {
list<string> Email = new list<string> ();
list<string> phone = new list<string> ();
list<Id> ids = new list<Id> ();
for(shobithapp__Test_Object__c t :trigger.new){
if (t.shobithapp__email__c != null){ //shobithapp__email__c ---field in test object api name(shobithapp__Test_Object__c )
Email.add(t.shobithapp__email__c);
}
if (t.shobithapp__Phone__c != null){
phone.add(t.shobithapp__Phone__c); //shobithapp__Phone__c---field in test object api name(shobithapp__Test_Object__c )
}
If(Email.size() != null ){
for(Lead l : [SELECT Email FROM Lead WHERE Email IN : Email ]){
ids.add( l.id);
}
}
If(phone.size() != null ){
for(Lead le : [SELECT phone FROM Lead WHERE phone IN : Phone ]){
ids.add( le.id);
}
}
If (ids.size() != null )
{
t.shobithapp__Record_Type__c='duplicate';
}
else{t.shobithapp__Record_Type__c='original';
}
}
}
origal and duplicate are the picklist values (shobithapp__Record_Type__c is the piclist field api name)
mark it as best answer if it resolved your issue
thanks
vishnu R
Thanks for sharing the Code.But
I want to verify the Lead email and phone fields while inserting the Lead not the custom object, anyway i changed the code as per my scenario, but i want to update the picklist field in mycustom object not in the same object. Is it possible ..to update the field value in other object?
You are saying that if data is matched with lead data then picklist in the custom object is updating with duplicate accoring to your scenario. But i want to update the picklist value in the custom objectwhile inserting lead data, if data is matched with custom object data then i have to update the vlaue in the custom object data.
it is not my scenario..i just did for you.
your scenario is to check whether the phone and email are there in leads or not....if it is there you have to update a piclist in a custom object..right?
try this code...
trigger leadDatavalidation on Lead (after insert) {
list<string> Email = new list<string> ();
list<string> phone = new list<string> ();
list<shobithapp__Test_Object__c> test = new list<shobithapp__Test_Object__c> ();
list<shobithapp__Test_Object__c> test1 = new list<shobithapp__Test_Object__c> ();
list<shobithapp__Test_Object__c> test2 = new list<shobithapp__Test_Object__c> ();
for(Lead L :trigger.new){
if (L.Email!= null){
Email.add(L.Email);
}
if (L.Phone!= null){
phone.add(L.Phone);
}
}
test1=[SELECT id,shobithapp__email__c,shobithapp__Phone__c,shobithapp__Record_Type__c FROM shobithapp__Test_Object__c WHERE shobithapp__email__c IN : Email ];
test=[select shobithapp__Phone__c,shobithapp__email__c,shobithapp__Record_Type__c from shobithapp__Test_Object__c where Id IN: test1];
system.debug('////'+test);
for(shobithapp__Test_Object__c t :test){
if(test.size()!=null){
t.shobithapp__Record_Type__c='duplicate';
test2.add(t);
}
else
{
t.shobithapp__Record_Type__c='original';
test2.add(t);
}
}
update test2;
}
In the last If condition ..you can change the condition upon your requirement....
hope this helps you..
thanks
Vishnu R
check this code...
trigger LD_Check on Lead (After insert, After Update) {
list<Lead_Duplicate__c> LDlist =new List<Lead_Duplicate__c>();
LDlist =[Select Id,Name,LD_Email__c,LD_Phone__c,LD_Pick_List__c from Lead_Duplicate__c];
for(Lead l : Trigger.New){
for(Lead_Duplicate__c ld : LDlist){
if(l.Email == ld.LD_Email__c && l.Phone == ld.LD_Phone__c ){
ld.LD_Pick_List__c= 'LD true' ;
}
}
}
update LDlist;
}
thanks
Vishnu R
Thats worked like charm. Thank you.
And can we update the lookup filed through trigger...?
yes you can update a look up field via trigger..
check this link https://developer.salesforce.com/forums/ForumsMain?id=9060G000000XZd4QAG
hope this helps you
Thanks
Vishnu R
Can you help hoe to validate teh phoen number field in the custom page befor redirecting the page.