You need to sign in to do that
Don't have an account?
Ozymandias
Pre-populate New Lead fields
Hi folks. I have a requirement to pre-populate certain fields (phone, fax, mobile phone), based on the record type, when creating a new Lead. Currently, this is done through an s-control, but I intend to re-implement it using visualforce. Can anyone give me any pointers on how to do this? I can't seem to find any good examples for this particular case.
There's probably a reason you're not doing this but I figured I would ask -- why not a custom link on the originating page?
So if you wanted to populate it from an account, you could add this custom link to the account page
https://na7.salesforce.com/00Q/e?retURL=/00Q/o&lea8={!Account.Phone}
And that would prepopulate a new lead record's phone # field with the Account Phone number.
Record type differentiation might be the issue -- but if there were different page layouts for diff record types, maybe this would be a simple non-code solution.
Actually, what I'm trying to do is slightly different. Sorry, I should have put more details in my first post to give everyone a better picture.
Basically, our company has different Lead record types based on country (e.g. AU Lead, HK Lead, SG Lead, etc...). When a user creates a new Lead, the phone, mobile phone and fax fields should be pre-populated with the country code, which is derived from the record type. So, for example, a HK Lead should have "(+852)" already in the phone/mobile phone/fax field when the create Lead page comes out.
What the current S-control does, is that it overrides the New button, then performs some check on the Lead record type to determine what prefix to use. It then generates a URL similar to what you posted, where the phone prefix is included as a parameter in the URL.
I think I can implement the same thing in a visualforce controller by generating a PageReference like so:
PageReference createLeadPage = new PageReference('/00Q/e');
createLeadPage.getParameters().put('nooverride', '1');
createLeadPage.getParameters().put('lea10', countryCode);
createLeadPage.getParameters().put('lea9', countryCode);
...
...then use that PageReference in the action attribute of the visualforce page.
However, is there any other way to do this without manually creating the URL of the create Lead page? The standard controller has methods to navigate to view and edit, but doesn't seem to have any for create.
Why not use a trigger?
trigger prepopulateLead on Lead (before Insert){ for (Lead l:trigger.new){ if(l.countryCode=='USA'){ l.phone='011'+l.phone; } } }
Hi XYZ83,
I ended up using a Visualforce page for my Lead pre-populate requirement, though it should be possible to do the same thing with an S-control (I just chose not to use an S-control since they have been phased-out).
Here's what I did:
Visualforce page
Custom controller
Still not entirely happy with everything about it (particularly the part where I need to hardcode the field ids), but at least it works. If anybody knows of a better way, I'd appreciate your input.
Hope this helps you XYZ83.
ReidC,
Do you know of a listing of those lead parameters that begin with lea?
Thanks,Jesse.