1

I am trying to create a custom button that works for multiple different objects to all come back to my Data_Feasibility_Report__c custom object. I was trying to create the button to pull from the Lead standard object but I keep gettting an error that I am not sure how to fix. Any help would be appreciated. Here is the code that I am trying to write. I am trying to pull the Name from the Lead and the record type as well as a couple custom fields. When I go test the button I get "Unexpected Identifier".

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

var acct = new sforce.SObject(Data_Feasibility_Report__c);
acct.name = 'New Account';
acct.Related_To__c = 'Lead';
acct.Related_Lead__c = {!Lead.Name};

var result = sforce.connection.create([acct]);

if(result[0].getBoolean(“success”)){
window.location = “/” + result[0].id + “/e”;
}else{
alert(‘Could not create record ‘+result);
}

I tried a different way as well to see if I was going the wrong direction and I was getting "Invalid or unexpected token"

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

getDate = function(dateObj){ 
var day = dateObj.getDay() < 9 ? '0'+dateObj.getDay() : dateObj.getDay(); 
var month = dateObj.getMonth() < 9 ? '0'+dateObj.getMonth() : dateObj.getMonth(); 

return dateObj.getFullYear()+'-'+month+'-'+day; 
} 

var oppty = new sforce.SObject('Data_Feasibility_Report__c'); 

oppty.Related_Lead__c = '{!Lead.Name}; 
oppty.Related_To__c = 'Lead'; 
RecordType=0125C00000005jd; 

result = sforce.connection.create([oppty]); 

if(result[0].success == 'true'){ 
alert('An New Data Feasibility Report with Name - ' + oppty.Name + ' was Created Successfully.'); 
}

Anyone know what I am doing wrong?

2

Merge fields that are strings need to be quoted. Furthermore, it is strongly recommended that you also use JSENCODE if you're not sure that there may be ", ', \, or \n characters.

Specifically:

acct.Related_Lead__c = {!Lead.Name};

Should instead be:

acct.Related_Lead__c = "{!JSNECODE(Lead.Name)}";

(You may choose to use ' or " to surround the string, so long as they match.)

Also, I've noticed you copied some text from a Microsoft Office program; some of your code uses so-called "smart quotes", which look like the following: and . These won't work in JavaScript, so make sure you replace them with plain " or ' characters.

3
  • {faultcode:'sf:INVALID_TYPE', faultstring:'INVALID_TYPE: sObject type 'Data_Feasibility_Report__c' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.', detail:{InvalidSObjectFault:{exceptionCode:'INVALID_TYPE',
    – SoleHack
    Oct 3 '16 at 6:06
  • exceptionMessage:'sObject type 'Data_Feasibility_Report__c' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.', row:'-1', column:'-1', }, }, }"
    – SoleHack
    Oct 3 '16 at 6:06
  • @JoshuaAnderson I apologize, it appears I missed your comment. If you're getting this error, then either (a) you're missing the right API name, or (b) the user does not have "read" access to the object. If this object is part of a Managed Package, it should be something like "namespace__API_Name__c" rather than the usual "API_Name__c" syntax. For the second, make sure that the user's profile includes "Read Object: API_Name__c" (replacing for your own name, of course).
    – sfdcfox
    Oct 4 '16 at 6:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.