0

I want to update the Lead Owner based on Zip Code. I have created a Zip Code custom and imported the zipcodes in to custom object and assigned user for the Zip codes. Now i required to change the owner of the Lead record while creating the record form Force.com sites page. Can anyone help me over her.

Thanks in advance. Regards, raju.

1 Answer 1

0

This can be done through 2 ways.

  1. site page
  2. trigger

I have done through trigger.

trigger LeadTrigger on Lead (before insert) {
    Map<String,Id> zipCodeUserMap = new Map<String,Id>();
    for(customObject__c custom : [Select id,zipCode, user from customObject__c]) {
        zipCodeUserMap.put(custom.zipCode,custom.user);    
    }
    for(Lead l : Trigger.new) {
        if(zipCodeUserMap.containsKey(l.zipCode)) {
            l.Ownerid = zipCodeUserMap.get(l.zipcode)
        }

    }
}

same logic can be implemented in vf page if you need

2
  • I'm getting an error while creating an record form my site page. Error is as below Record ID: cannot specify Id in an insert call
    – raju kiran
    Commented Oct 3, 2016 at 13:02
  • how can we use for the event after insert...? Actualy i'm sending an email to User if the record is matched with zipcode.
    – raju kiran
    Commented Oct 3, 2016 at 13:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .