0

I have created a custom button and i need to have a "Record created successfully" and redirect to the newly created record after clicking yes on the confirmation. I have returned the message from my class but it does not display. Anything that I might forget/overlooked? Thanks

Error message: Respond is not defined.

This is my custom button

confirm("Continue?");
var resultMsg = sforce.apex.execute("convertProject","OppId", 
{oID:"{!Opportunity2__c.Id}"});

alert(respond)
window.location.reload()

This is the snippet of class

Project__c newProj = new Project__c(
              Name = OppName +' - Project ',

              newProject.add(newProj);

              respond = 'Successfully created a new Project';
          }

          else{
              respond = 'You cannot create a project';
              return respond;
            }

         }

        if(newProject.size()>0){
           insert newProject;

         }      
          return respond;   
  }
6
  • change your alert from 'respond' to 'resultmsg'. Commented Jan 10, 2018 at 4:50
  • hi @AbhishekDaware, the error message persists, resultmsg is not defined
    – begginers
    Commented Jan 10, 2018 at 4:52
  • I hope you type resultMsg like this only Commented Jan 10, 2018 at 4:56
  • If you still facing an issue then paste your apex class code. I will verify and modify the same. Commented Jan 10, 2018 at 5:06
  • @AbhishekDaware I have created an if statement checking if resultmsg is null and alert(resultmsg) works. Is it possible to redirect to the newly created project record?
    – begginers
    Commented Jan 10, 2018 at 5:26

1 Answer 1

0

Please try below code to display message.

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

var retVal = confirm("Do you want to continue ?");
if (retVal == true)
{
    var resultMsg = sforce.apex.execute("convertProject","OppId", 
    {oID:"{!Opportunity2__c.Id}"});

    if( resultMsg != null) { 
       alert(resultMsg ); 
    } 
    return true;
} 
3
  • Hi, @ravikant, if I click Cancel, resultmsg still displays
    – begginers
    Commented Jan 10, 2018 at 5:10
  • I have updated the code please check. Commented Jan 10, 2018 at 5:14
  • Thanks for your help, I added if on IF(confirm("Do you want to continue ?") ){}. Is it possible to redirect to the newly created record?
    – begginers
    Commented Jan 10, 2018 at 5:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .