1

I am creating JavaScript button for creating a new record of a custom object my code looks as follow.

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/support/console/31.0/integration.js")} 

var newFollowUp= new sforce.SObject("Follow_up__c");
newFollowUp.name = 'New FollowUp';
newFollowUp.Case__C = {!Case.Id};
var result = sforce.connection.create([newFollowUp]);

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

when I click on this button I get error saying

Invalid or unexpected token

0
1

Following changes will work for you.

Instead of using window.location, use window.location.href to navigate to Edit page.

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/support/console/31.0/integration.js")} 

var newFollowUp= new sforce.SObject("Follow_up__c");
newFollowUp.name = 'New FollowUp';
newFollowUp.Case__C = "{!Case.Id}";
var result = sforce.connection.create([newFollowUp]);

if(result[0].success == 'true'){
    window.location.href = "/" + result[0].id + "/e"; //for console use srcUp("/" + result[0].id + "/e")
}else{
    alert('Could not create record '+result);
}
9
  • Thank you for the answer Santanu. I see this button creates the record now but doesn't open the edit screen. I have window.location = "/" + result[0].id + "/e";
    – Aman
    Jun 7 '17 at 15:57
  • you have to use window.location.href, updated my ans Jun 7 '17 at 16:06
  • Hmm I have changed that with href still no luck.
    – Aman
    Jun 7 '17 at 16:08
  • whats result[0].id is retunring? Jun 7 '17 at 16:09
  • I have checked that , window.location.href = "/" + '{!Case.Id}' + "/e"; is working fine for me at my DE, so it should work syntaxually Jun 7 '17 at 16:11

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.