• Jim Ellis
  • NEWBIE
  • 0 Points
  • Member since 2013
  • Compliance Manager
  • Adestra Ltd

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies

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

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 is here:

https://emea.salesforce.com/00Q/e?
lea3={!Opportunity.Account}&
name_firstlea2={!Contact.FirstName}&
name_lastlea2={!Contact.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}

Everything else pre-populates correctly in the Lead, but I'm stumped as to where/how I can access the necessary information for the Contact, specified in the Opportunity Contact Role.

If anybody has any ideas or can point me in the right direction, I'd greatly appreciate it.

 

Thanks

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