You need to sign in to do that
Don't have an account?
rmranjith8881.3927046400771116E12
Auto - Update Lookup field on Lead Object !!!
Hi All,
I have a Custom object called Branch__c, which has Region__c and Country__c picklist fields.
Branch__c is a Lookup on Lead object.
Lead also have Region__c and Country__c picklist fields,
So, I want to update the Branch__c Lookup field on Lead, If the Branch Region__c and Country__c fields matches with Lead Region__c and Country__c.
If Branch Region__c is null. update the Lead Region__c with Bangalore.
For this I wrote a Trigger below.
It is saving without errors, but it will not update the Lookup field on Lead.
Thanks in advance................
I have a Custom object called Branch__c, which has Region__c and Country__c picklist fields.
Branch__c is a Lookup on Lead object.
Lead also have Region__c and Country__c picklist fields,
So, I want to update the Branch__c Lookup field on Lead, If the Branch Region__c and Country__c fields matches with Lead Region__c and Country__c.
If Branch Region__c is null. update the Lead Region__c with Bangalore.
For this I wrote a Trigger below.
It is saving without errors, but it will not update the Lookup field on Lead.
trigger UpdateBranch on Lead (before insert, before update) { Set<Id> ids = trigger.newmap.keySet(); Lead ld; for (Lead lT:Trigger.new){ ld = lT; } try{ List<Branch__c> brList = [Select Id, Name, Country__c, Region__c, Email_ID__c from Branch__c where Id IN : ids]; Branch__c b = new Branch__c(); for (Branch__c br : brList){ if (brList .size() > 0 && ld.Country == br.Country__c && b.Region__c != Null){ ld.Branch_NAME__c = br.Id; ld.Region__c = br.Region__c; } else{ ld.Branch_NAME__c = null; ld.Region__c = 'Bangalore'; } } }catch(Exception e){ ld.addError('unable to find the Branch Name ' + e.getMessage()); } }
Thanks in advance................
Thanks for your reply,
The trigger is working fine now, after couple of changes.
Here is my Trigger:
Thanks
Ranjith
All Answers
Thanks for your reply,
The trigger is working fine now, after couple of changes.
Here is my Trigger:
Thanks
Ranjith