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'. Jan 10 '18 at 4:50
  • hi @AbhishekDaware, the error message persists, resultmsg is not defined
    – begginers
    Jan 10 '18 at 4:52
  • I hope you type resultMsg like this only Jan 10 '18 at 4:56
  • If you still facing an issue then paste your apex class code. I will verify and modify the same. Jan 10 '18 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
    Jan 10 '18 at 5:26
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
    Jan 10 '18 at 5:10
  • I have updated the code please check. Jan 10 '18 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
    Jan 10 '18 at 5:16

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.