Skip to main content
Victoria Ukatu (Granicus) 님이 #Collaboration에 질문했습니다
Hello! :) 

 

I am very new to Salesforce (~ 3 weeks) and my experience is more with JavaScript. Currently I am working on creating a custom button. The function of this button is that, once it is clicked, the case Status will be changed to 'Closed' and the Sub Status and Case Reason will be changed to 'Spam.' In other words, after the button is clicked this should be the result:

 

How to incorporate URLFOR into JavaScript custom button

 

Previously, the button was simple, as shown below:

{!URLFOR("/apex/CaseBulkAction_MarkAsSpam", null, [ids=Case.Id])}

This button would then interact with my Visualforce page (called "CaseBulkAction_MarkAsSpam"), which would trigger the Apex Class which contained the actual logic to change the statuses. All of that was working fine, doing it all without the need of JavaScript.

 

However,the task I was given is to create a custom JavaScript button instead of using URL as the source. With this new button, I created it so that when it's clicked, a confirmation window pops up saying 'Are you sure that you want to close the case and mark it as spam?' When a user clicks OK, I want it to carry out what the URLFOR was previously doing: changing the case Status, Sub Status, and Case Reason as mentioned above. However, the problem is that I can't just copy paste the URLFOR from the original button and paste it into the JavaScript code. My question: Is there a way to maintain the functionality that the URLFOR-based button was doing, but somehow incorporate that into the code of the custom JavaScript button I am trying to build?

 

This is what my JavaScript button currently looks like. The line with window.open is where the issue is (I was just trying different things, I wasn't sure how to write it). 

 

 

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

{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}

var caseObj = new sforce.SObject("Case");

caseObj.Id = '{!Case.Id}';

caseObj.Status = '{!Case.Status}';

if (caseObj.Status == 'Closed'){

alert('This case is already closed.');

}else{

var doubleCheck = confirm('Are you sure you want to close this case and mark as spam?');

if(doubleCheck){

window.open("/apex/CaseBulkAction_MarkAsSpam?id={!Case.Id}");

}

}

location.reload(true);

 

Any help would be greatly appreciated! Thanks!
답변 5개
  1. 2020년 7월 21일 오후 6:43

    Hi Paul, I figured it out! I adjusted the following line, so now it works:

    window.location='./apex/CaseBulkAction_MarkAsSpam?ids={!Case.Id}';

    The rest of the code was fine. Thanks for your help!