You need to sign in to do that
Don't have an account?
Kim Moutes
Adding a Lookup Relationship field to a custom button
Hello-
I created a Custom Button to convert a Contact to a Lead. I know this is not the normal way but I have a client requesting it for a specific initiative. I created a Lookup Relationship field on the Lead object called Account_Lookup__c so that when I am on the Account page I can look at the Related List to see what Leads have been generated from that Account. I need to add this to the custom button I created so that it auto populates at the time of conversion and am not sure how to write that in. Any help would be appreciated.
Thanks,
Kim
I created a Custom Button to convert a Contact to a Lead. I know this is not the normal way but I have a client requesting it for a specific initiative. I created a Lookup Relationship field on the Lead object called Account_Lookup__c so that when I am on the Account page I can look at the Related List to see what Leads have been generated from that Account. I need to add this to the custom button I created so that it auto populates at the time of conversion and am not sure how to write that in. Any help would be appreciated.
Thanks,
Kim
if('{!Account.Number_of_DCs__c}' == '')
Lead.Number_of_DCs__c = null;
else
Lead.Number_of_DCs__c = '{!Account.Number_of_DCs__c}';
All Answers
Can you please explain more on your problem statement so that we can assist you for finding the solution? By going through the aforementioned statement, you have created a custom button on Contact(assuming the contact which has been created as a result of lead conversion). On click of this button, you want to associate the related Contact's Account with converted lead.
Please let me know if my understanding is correct.
Thank you for responding! Yes, when I look at the Account page I want to see what Leads have been generated from that Account. This is why I created the Lookup Relationship field. However, when I write it into the code in the button like this Lead.Account_LookupId__c = '{!Account.Id}'; I get this error faultcode:'sf:INVALID_FIELD', faultstring:'INVALID_FIELD:No such column 'Account_LookupID__c' on entity 'Lead'.
Can you please let me know where exactly your detail button is placed on contact detail page or on lead detail page? And if possible Can you please share your custom button code with us?
It is on the contact page. Here is the code. The last line Lead.Account_LookupId__c = '{!Account.Id}'; is the one causing the error, I believe.
{!REQUIRESCRIPT('/soap/ajax/27.0/connection.js')}
var Lead = new sforce.SObject('Lead');
Lead.Company = '{!Account.Name}';
Lead.FirstName = '{!Contact.FirstName}';
Lead.LastName = '{!Contact.LastName}';
Lead.Phone = '{!Contact.Phone}';
Lead.MobilePhone = '{!Contact.MobilePhone}';
Lead.LeadSource = 'Concept Services';
Lead.Email = '{!Contact.Email}';
Lead.Street = '{!Account.BillingStreet}';
Lead.City = '{!Account.BillingCity}';
Lead.PostalCode = '{!Account.BillingPostalCode}';
Lead.State = '{!Account.BillingState}';
Lead.Country = '{!Account.BillingCountry}';
Lead.Title = '{!Contact.Title}';
Lead.Description = '{!Contact.Description}';
Lead.OwnerId = '{!Account.OwnerId}';
Lead.Familiar_with_Company__c = '{!Account.Familiar_with_Company__c}';
Lead.Competition__c = '{!Account.Competition__c}';
Lead.Annual_Transportation_Spend__c = '{!Account.Annual_Transportation_Spend__c}';
Lead.Shipping_Methods__c = '{!Account.Shipping_Methods__c}';
Lead.Warehouse_Management_System_WMS__c = '{!Account.Warehouse_Management_System_WMS__c}';
Lead.Transportation_Management_System_TMS__c = '{!Account.Transportation_Management_System_TMS__c}';
Lead.Happy_with_Current_Provider__c = '{!Account.Happy_with_Current_Provider__c}';
Lead.Why_Why_Not_Happy_with_Current_Provider__c = '{!Account.Why_Why_Not_Happy_with_Current_Provider__c}';
Lead.DC_Locations__c = '{!Account.DC_Locations__c}';
Lead.Number_of_DCs__c = '{!Account.Number_of_DCs__c}';
Lead.CS_Lead_Write_up__c = '{!Contact.CS_Lead_Write_up__c}';
Lead.Account_LookupId__c = '{!Account.Id}';
result = sforce.connection.create([Lead]);
if(result[0].success == 'true'){
alert('A New Lead was Created Successfully by {!$User.FirstName} {!$User.LastName}.');
}
Can you please check the field level security for Account_LookupId__c? It should be set to visible.
Ideally, it should be visible to the profile which you are currently logged in with. Just for testing purpose, you can enable this for rest of the profiles as well and then try. If possible, check for the field api name once more.
I made it visible to all but still got the same error so I changed it back. I double checked the API name and I had been using the Account_LookupID__c field. This time, I just used the Account_Lookup__c field rather than the ID field and I am no longer getting that error but when I click the Create a Lead button nothing happens. Thoughts?
Failed to load resource: the server responded with a status of 404 (Not Found)
servlet.Integration:1 Font from origin 'https://na9.salesforce.com' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://postwire.na9.visual.force.com' is therefore not allowed access. The response had HTTP status code 404.
https://na9.salesforce.com/static/fonts/TradeGothic/tradegothicltstd-bd2-webfont.woff Failed to load resource: the server responded with a status of 404 (Not Found)
servlet.Integration:1 Font from origin 'https://na9.salesforce.com' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://postwire.na9.visual.force.com' is therefore not allowed access. The response had HTTP status code 404.
https://na9.salesforce.com/static/fonts/TradeGothic/tradegothicltstd-bd2-webfont.ttf Failed to load resource: the server responded with a status of 404 (Not Found)
{!REQUIRESCRIPT('/soap/ajax/32.0/connection.js')}
put alert(result) to see what comes after sforce.connection.create statement.
{!REQUIRESCRIPT('/soap/ajax/32.0/connection.js')}
var Lead = new sforce.SObject('Lead');
Lead.Company = '{!Account.Name}';
Lead.FirstName = '{!Contact.FirstName}';
Lead.LastName = '{!Contact.LastName}';
Lead.Phone = '{!Contact.Phone}';
Lead.MobilePhone = '{!Contact.MobilePhone}';
Lead.LeadSource = 'Concept Services';
Lead.Email = '{!Contact.Email}';
Lead.Street = '{!Account.BillingStreet}';
Lead.City = '{!Account.BillingCity}';
Lead.PostalCode = '{!Account.BillingPostalCode}';
Lead.State = '{!Account.BillingState}';
Lead.Country = '{!Account.BillingCountry}';
Lead.Title = '{!Contact.Title}';
Lead.Description = '{!Contact.Description}';
Lead.OwnerId = '{!Account.OwnerId}';
Lead.Familiar_with_Company__c = '{!Account.Familiar_with_Company__c}';
Lead.Competition__c = '{!Account.Competition__c}';
Lead.Annual_Transportation_Spend__c = '{!Account.Annual_Transportation_Spend__c}';
Lead.Shipping_Methods__c = '{!Account.Shipping_Methods__c}';
Lead.Warehouse_Management_System_WMS__c = '{!Account.Warehouse_Management_System_WMS__c}';
Lead.Transportation_Management_System_TMS__c = '{!Account.Transportation_Management_System_TMS__c}';
Lead.Happy_with_Current_Provider__c = '{!Account.Happy_with_Current_Provider__c}';
Lead.Why_Why_Not_Happy_with_Current_Provider__c = '{!Account.Why_Why_Not_Happy_with_Current_Provider__c}';
Lead.DC_Locations__c = '{!Account.DC_Locations__c}';
Lead.Number_of_DCs__c = '{!Account.Number_of_DCs__c}';
Lead.CS_Lead_Write_up__c = '{!Contact.CS_Lead_Write_up__c}';
Lead.Account_Lookup__c = '{!Account.Id}';
alert(result) = sforce.connection.create([Lead]);
if(result[0].success == 'true'){
alert('A New Lead was Created Successfully by {!$User.FirstName} {!$User.LastName}.');
}
{!REQUIRESCRIPT('/soap/ajax/32.0/connection.js')}
var Lead = new sforce.SObject('Lead');
Lead.Company = '{!Account.Name}';
Lead.FirstName = '{!Contact.FirstName}';
Lead.LastName = '{!Contact.LastName}';
Lead.Phone = '{!Contact.Phone}';
Lead.MobilePhone = '{!Contact.MobilePhone}';
Lead.LeadSource = 'Concept Services';
Lead.Email = '{!Contact.Email}';
Lead.Street = '{!Account.BillingStreet}';
Lead.City = '{!Account.BillingCity}';
Lead.PostalCode = '{!Account.BillingPostalCode}';
Lead.State = '{!Account.BillingState}';
Lead.Country = '{!Account.BillingCountry}';
Lead.Title = '{!Contact.Title}';
Lead.Description = '{!Contact.Description}';
Lead.OwnerId = '{!Account.OwnerId}';
Lead.Familiar_with_Company__c = '{!Account.Familiar_with_Company__c}';
Lead.Competition__c = '{!Account.Competition__c}';
Lead.Annual_Transportation_Spend__c = '{!Account.Annual_Transportation_Spend__c}';
Lead.Shipping_Methods__c = '{!Account.Shipping_Methods__c}';
Lead.Warehouse_Management_System_WMS__c = '{!Account.Warehouse_Management_System_WMS__c}';
Lead.Transportation_Management_System_TMS__c = '{!Account.Transportation_Management_System_TMS__c}';
Lead.Happy_with_Current_Provider__c = '{!Account.Happy_with_Current_Provider__c}';
Lead.Why_Why_Not_Happy_with_Current_Provider__c = '{!Account.Why_Why_Not_Happy_with_Current_Provider__c}';
Lead.DC_Locations__c = '{!Account.DC_Locations__c}';
Lead.Number_of_DCs__c = '{!Account.Number_of_DCs__c}';
Lead.CS_Lead_Write_up__c = '{!Contact.CS_Lead_Write_up__c}';
Lead.Account_LookupId__c = '{!Account.Id}';
result = sforce.connection.create([Lead]);
alert('=============='+result);
if(result[0].success == 'true'){
alert('A New Lead was Created Successfully by {!$User.FirstName} {!$User.LastName}.');
}
Anyways, this is not an error box, this is simply a javascript alert box to indicate the status to user so user can easily locate where the error is coming.
Lead.Contract_Expiration_Date__c = '{!Account.Contract_Expiration_Date__c}';
Please remove single quotes from the above mentioned statement:
Lead.Contract_Expiration_Date__c = {!Account.Contract_Expiration_Date__c};
Use this instead.
After removing the single quotes I received this error
{faultcode:'soapenv:Client', faultstring:"0.00004313319530710835' is not a valid value for the type xsd:date', }
Lead.Contract_Expiration_Date__c = new Date();
alert('{!Account.Contract_Expiration_Date__c}');
Lead.Contract_Expiration_Date__c = {!Account.Contract_Expiration_Date__c};
Are you on skype or fb? If possible, Can you connect with me?
Please use below mentioned code as we have fixed this problem. Let us know if you still see any issues with it:
{!REQUIRESCRIPT('/soap/ajax/32.0/connection.js')}
var Lead = new sforce.SObject('Lead');
Lead.Company = '{!Account.Name}';
Lead.FirstName = '{!Contact.FirstName}';
Lead.LastName = '{!Contact.LastName}';
Lead.Phone = '{!Contact.Phone}';
Lead.MobilePhone = '{!Contact.MobilePhone}';
Lead.LeadSource = 'Concept Services';
Lead.Email = '{!Contact.Email}';
Lead.Street = '{!Account.BillingStreet}';
Lead.City = '{!Account.BillingCity}';
Lead.PostalCode = '{!Account.BillingPostalCode}';
Lead.State = '{!Account.BillingState}';
Lead.Country = '{!Account.BillingCountry}';
Lead.Title = '{!Contact.Title}';
Lead.Description = '{!Contact.Description}';
Lead.OwnerId = '{!Account.OwnerId}';
Lead.Familiar_with_Company__c = '{!Account.Familiar_with_Company__c}';
Lead.Competition__c = '{!Account.Competition__c}';
Lead.Annual_Transportation_Spend__c = '{!Account.Annual_Transportation_Spend__c}';
Lead.Shipping_Methods__c = '{!Account.Shipping_Methods__c}';
Lead.Warehouse_Management_System_WMS__c = '{!Account.Warehouse_Management_System_WMS__c}';
Lead.Transportation_Management_System_TMS__c = '{!Account.Transportation_Management_System_TMS__c}';
Lead.Happy_with_Current_Provider__c = '{!Account.Happy_with_Current_Provider__c}';
Lead.Why_Why_Not_Happy_with_Current_Provider__c = '{!Account.Why_Why_Not_Happy_with_Current_Provider__c}';
Lead.DC_Locations__c = '{!Account.DC_Locations__c}';
Lead.Number_of_DCs__c = '{!Account.Number_of_DCs__c}';
Lead.CS_Lead_Write_up__c = '{!Contact.CS_Lead_Write_up__c}';
Lead.Account_LookupId__c = '{!Account.Id}';
Lead.Contract_Expiration_Date__c = fixDate('{!Account.Contract_Expiration_Date__c}');
result = sforce.connection.create([Lead]);
if(result[0].success == 'true'){
alert('A New Lead was Created Successfully by {!$User.FirstName} {!$User.LastName}.');
}
function fixDate(date){
if(date == '' || date == null)
return null;
var splittedDate = date.split('/');
var month = splittedDate[0] < 10 ? "0"+splittedDate[0] : splittedDate[0];
var day = splittedDate[1] < 10 ? "0"+splittedDate[1] : splittedDate[1];
return splittedDate[2] + "-" + month + "-" + day + "T00:00:00Z";
}
I had a scenario come up recently with the custom button you helped me create last month. One of the fields is a number field type and whenever we leave this field blank we receive a JavaScript error and it won't create the lead.
Field Line from Button: Lead.Number_of_DCs__c = '{!Account.Number_of_DCs__c}';
Error: {faultcode:'soapenv:Client', faultstring:''' is not valid for the type xsd:double', }
Any help you could provide would be much appreciated.
Thanks,
Kim
I have updated your script to fix this issue. Please use the same and make sure you create backup of the existing one before replacement:
{!REQUIRESCRIPT('/soap/ajax/32.0/connection.js')}
var Lead = new sforce.SObject('Lead');
Lead.Company = '{!Account.Name}';
Lead.FirstName = '{!Contact.FirstName}';
Lead.LastName = '{!Contact.LastName}';
Lead.Phone = '{!Contact.Phone}';
Lead.MobilePhone = '{!Contact.MobilePhone}';
Lead.LeadSource = 'Concept Services';
Lead.Email = '{!Contact.Email}';
Lead.Street = '{!Account.BillingStreet}';
Lead.City = '{!Account.BillingCity}';
Lead.PostalCode = '{!Account.BillingPostalCode}';
Lead.State = '{!Account.BillingState}';
Lead.Country = '{!Account.BillingCountry}';
Lead.Title = '{!Contact.Title}';
Lead.Description = '{!Contact.Description}';
Lead.OwnerId = '{!Account.OwnerId}';
Lead.Familiar_with_Company__c = '{!Account.Familiar_with_Company__c}';
Lead.Competition__c = '{!Account.Competition__c}';
Lead.Annual_Transportation_Spend__c = '{!Account.Annual_Transportation_Spend__c}';
Lead.Shipping_Methods__c = '{!Account.Shipping_Methods__c}';
Lead.Warehouse_Management_System_WMS__c = '{!Account.Warehouse_Management_System_WMS__c}';
Lead.Transportation_Management_System_TMS__c = '{!Account.Transportation_Management_System_TMS__c}';
Lead.Happy_with_Current_Provider__c = '{!Account.Happy_with_Current_Provider__c}';
Lead.Why_Why_Not_Happy_with_Current_Provider__c = '{!Account.Why_Why_Not_Happy_with_Current_Provider__c}';
Lead.DC_Locations__c = '{!Account.DC_Locations__c}';
Lead.Number_of_DCs__c = '{!Account.Number_of_DCs__c}';
Lead.CS_Lead_Write_up__c = '{!Contact.CS_Lead_Write_up__c}';
Lead.Account_LookupId__c = '{!Account.Id}';
Lead.Contract_Expiration_Date__c = fixDate('{!Account.Contract_Expiration_Date__c}');
if('{!Account.Number_of_DCs__c}' == '')
Lead.Number_of_DCs__c = null;
else
Lead.Number_of_DCs__c = {!Account.Number_of_DCs__c};
result = sforce.connection.create([Lead]);
if(result[0].success == 'true'){
alert('A New Lead was Created Successfully by {!$User.FirstName} {!$User.LastName}.');
}
function fixDate(date){
if(date == '' || date == null)
return null;
var splittedDate = date.split('/');
var month = splittedDate[0] < 10 ? "0"+splittedDate[0] : splittedDate[0];
var day = splittedDate[1] < 10 ? "0"+splittedDate[1] : splittedDate[1];
return splittedDate[2] + "-" + month + "-" + day + "T00:00:00Z";
}
Do I need to remove a semi-colon somewhere?
if('{!Account.Number_of_DCs__c}' == '')
Lead.Number_of_DCs__c = null;
else
Lead.Number_of_DCs__c = '{!Account.Number_of_DCs__c}';