You need to sign in to do that
Don't have an account?

Button when Clicked redirected to Contact Page with values
I have a requirement where I need to create a button on lead page when clicked it should redirect to Contact page with prepopulated values like Lead Company Name - Account Name, Lead Phone - Contact Phone and so on.(standard pages) dont want to create a VF Page. Any suggestions would be appreciated.
Remove the after insert from the trigger
Either do this
or you can do like this
Thanks
All Answers
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}
The requirement is it shoud create a new Lead all together nothing to update. Like i have a contact who actually reffered me another contact which we consider it as a lead. So i need to create a Custom Button on Contact on detail page when clicked it shoud take me to a standard Lead page (just like creating a new lead) but with populated values from that contact on which i clicked the reffered button. (Basic fields like Company Name in Lead should be prepopulated with Account Name of contact and so on). If this can we acheived by JS can you guide me to a program or some example code so that i can build on it. Its actually kinda urgent.
Thanks and truly appreciate your help
Create a custom button with the below code
window.open("https://salesforce domain url/00Q/e?retURL=00Q&lea3={!Account.Name}")
to open a lead edit page by pre populating the company name as contacts account name.
hope this helps.
Thanks.
1. Go to setup
2. Type Contact
3. Click on "Button and Links"
4. for Content Source slect "OnClick JavaScript"
Use the below code then:
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}
var contactObject = sforce.connection.query("SELECT Name, FROM Contact, WHERE Id = '{!Contact.Id}'");
records = contactObject.getArray("records");
var record = records[0];
var objLead = new sforce.SObject("Lead");
objLead.Name = record.Name; //Similarly you can map other values of Lead before inserting it.
var result = sforce.connection.create([objLead]);
if(result[0].success == "true")
{
window.open("/objLead.Id");
}
This would definitely help you.
Thanks for the help. But my problem persists.
I have alrady done with prepopulating certain values but that the problem is, i have a lookup / formula field created on user object where the present user id or account owner id should prepopulate. Not sure for some reason when i am creating a lookup / formula field on user its not getting a hyperlink its giving values but not like fields like owner id when u click your redirected to the user profile. I need this as i need to pull reports based on it.
Created formula field (Text) also tried with look up and with User.Id and below one both showing values but not as hyperlinks to the profile.
00N280000048Ny0={$User.FirstName + " "+ " " +$User.LastName}
Any help would be higly appreciated.
I got that pat covered, however my below code is completely wrong i guess as once i prepopulate the values and when i choose a user in the reffered lookup field mentioned in above post. After clicking Save button the lead should be saved and its lead owner should be the one selected in reffered lookup field. Currently when i click it saves current user as Lead Owner.
Hence i wrote a trigger for this before insert on Lead but seems to be completely wrong. RecordType id = 01228000000YtCD
Tried with trigger.new too but its failing.
Any help would be highly appreciated
If you want to change the owner id of the particular lead based on the record type values then the below code would help you.
The parameter that you are passing to the method isBeforeInsert must be triggwe.newMap.
So,
In the above code replace the record type name with your record type name.
Hope this helps
Thanks
I am getting the below error.
Error - Referedtest: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Class.LeadTriggerHelperClass2.isBeforeInsert: line 7, column 1
I think you have some problem with your recordType Id.
Is the name Refered is the correct name?
Run this two lines in developer console and see if you can able to print the ID
If you can able to print the Id then instead of passing trigger.newMap you can pass trigger.new.
So that,
Your trigger will be like
And your class wlll be
Thanks
Please find below is the error which is throwing up when i am trying to enter the Lead Record.
Error - Review all error messages below to correct your data.
Apex trigger Referedtest caused an unexpected exception, contact your administrator: Referedtest: execution of AfterInsert caused by: System.FinalException: Record is read-only: Class.LeadTriggerHelperClass2.isBeforeInsert: line 11, column 1
Remove the after insert from the trigger
Either do this
or you can do like this
Thanks
Lead is created but for reason Email is not firing.
Like i have created below code in the same class to send an email alert to the new lead owner.
Truly appreciate your help
Change the trigger like,
Hope this solves that too.
Thanks