function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sarvesh001sarvesh001 

Javascript to call vf page on button click

Hi,
I amcalling vf page on button click through onclickjavascipt  for this i am using below scipt

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")} 
    {!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")} 
    var x;
    if (confirm("If Industry Analysis Records Already Exist Press Cancel If Not Press OK") == true) {
        x = "OK";
    } else {
        x = "Cancel";
    }
    if(x == 'OK'){ 
       window.location='/apex/Industry_Analysis?id={!Activities__c.Id}';
    }

My requirement is whether there is related list record is exist or not ,if not call the vf page . if related records exist there shoud show message like record already exist.

can any one help me out for this,
Regards,
Sarvesh.
 
Best Answer chosen by sarvesh001
Naveen Rahul 3Naveen Rahul 3
{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}

var r = confirm(" Are you sure to call the apex class ?");
if(r == true)
{

var getsomethingback = sforce.apex.execute("javasclass","check",{x:'this'});
alert("total count"+getsomethingback );
}
where javasclass  is an salesforce class and where x is an parameter value you were passing.you call any class and find if any related list available,if available then you can return any value. based on that  returing value you can redirect to any page you wish.

hope this is what you were expecting.


Thanks
D Naveen Rahul.

All Answers

Anoop yadavAnoop yadav
Try with the below code.
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")} 
    {!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")} 
    var x;
    if (confirm("If Industry Analysis Records Already Exist Press Cancel If Not Press OK") == true) {
        x = "OK";
    } else {
        x = "Cancel";
    }
    if(x == 'OK'){ 
       window.location.href = '/apex/Industry_Analysis?id={!Activities__c.Id}';
    }

 
sarvesh001sarvesh001
Hi Anoop yadav,
what i ahve posted that one is working fine but my requirement is whethere is related record are exist or not like
   var x;
    if ({!Industry_Analysis__c.Id}!= true) {
        x = "OK";
    } else {
        x = "Cancel";
    }
    if(x == 'OK'){ 
       window.location='/apex/Industry_Analysis?id={!Activities__c.Id}';


But the above one showing error..

regards,
sarvesh.
Naveen Rahul 3Naveen Rahul 3
{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}

var r = confirm(" Are you sure to call the apex class ?");
if(r == true)
{

var getsomethingback = sforce.apex.execute("javasclass","check",{x:'this'});
alert("total count"+getsomethingback );
}
where javasclass  is an salesforce class and where x is an parameter value you were passing.you call any class and find if any related list available,if available then you can return any value. based on that  returing value you can redirect to any page you wish.

hope this is what you were expecting.


Thanks
D Naveen Rahul.
This was selected as the best answer
sarvesh001sarvesh001
Hi Naveen Rahul 3,
yes this apoach is good i will try...