function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jim EllisJim Ellis 

Creating a Lead from a 'Lost' Opportunity - Issue with First Name & Last Name

Hi All,

 

We have a process in our Enterprise edition of Salesforce, where our Sales Team need to create a Lead when an Opportunity is set to 'Closed Lost'.  


The reason for this, is that our Telemarketing team can then 'warm-up' those Leads depending on why the Opportunity was Lost in the first place.

I'm creating a button to do this, but am having difficulty getting the First Name and Last Name of the contact, specified in the Contact Role, pre-popuating in the new Lead.

 

My button code, which I was kindly given by another member of the Salesforce Community, is:

 

 

{!REQUIRESCRIPT('/soap/ajax/28.0/connection.js')} 

var contactRole = sforce.connection.query("SELECT Contact.FirstName, Contact.LastName FROM OpportunityContactRole WHERE OpportunityId='{!Opportunity.Id}' AND IsPrimary = TRUE"); 

var firstName; 
var lastName; 

if (contactRole.size == 1){ 
firstName = contactRole.records.Contact.FirstName; 
lastName = contactRole.records.Contact.LastName; 


location.href = '/00Q/e?lea3={!Opportunity.Account}&name_firstlea2=' + firstName + '&name_lastlea2=' + lastName + '&lea12={!Account.Website}&00N20000002X2tm={!Opportunity.Name}&00N20000003ZQZU={!Opportunity.New_Biz_Sales_person__c}&00N20000003GkTu={!Opportunity.OwnerFullName}&00N20000002X2tr={!Opportunity.Monthly_Value__c}&00N20000003GkTz={!Opportunity.LeadSource}&00N20000003GkU4={!Opportunity.CloseDate}&00N20000002X2tw={!Opportunity.Account}&00N20000002X2u1={!Opportunity.Description}&00N20000003GkUE={!Opportunity.Reason_For_Win_Loss__c}&00N20000003GkU9={!Opportunity.Notes_from_Lead__c}';

 

This only works when there is one Contact in the Opportunity Contact Roles section; if there are more than one Contact in the Contact Roles section, and even if only one of them is selected as Primary, an error message is received.

 

Can anybody assist with how I can amend this code to 'ignore' the other Contacts and just use the Primary Contact for the new Lead?  Please be aware that I am not a developer and, therefore, have limited knowledge of 'code' and what it does.

 

Any assistance would be greatfully received.

 

Thanks

JonathanBaltzJonathanBaltz

Can you please provide the error message? 

 

Also, can you please try to modify the following line of code and see if that works: 

 

From:  if (contactRole.size == 1){
To:    if (contactRole.size >= 1){

This may work, but we will know more if we can see what error you are receiving.

 

Jim EllisJim Ellis

Hi Jonathan,

 

Thanks for your reply.

 

I changed the code as you suggested, but I still receive the error message.  The error message is different dependent upon which browswer you are using:

 

Chrome - unexpected identifier

Firefox - missing ; before statement

IE - Expected ';'

 

I've been trying to discover what eadh of these mean, but, as I've mentioned, I'm not exactly a 'coder'.

 

Thanks for your assistance with this one.

Regards