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
ServionServion 

How to run a JavaScript

Hi Guys

      How to run a JavaScript After the 'contact Detail' page Load . Any sample or link to refer would help .

 

 

Thanks

Saran

 

Best Answer chosen by Admin (Salesforce Developers) 
Cory CowgillCory Cowgill

If you want Javascript to execute on load of a Standard Salesforce UI page, you can accomplish this via a Hompage Component.

 

Step 1. Create a Homepage Sidebar Component.

Setp 2. Inside Homepage Component, add the Javascipt via "Edit HTML Source" on the Component. Have the Javascript execute on window load.

Step 3. Add the Homepage Component to layout.

 

This is process I've used several times to execute javascript on load of a standard detail page. You can do things like remove elements from the page based on element names or ids from standard page layouts that you can't normally do without replacing with a VF page.

 

My only word of advice is be careful. Its a very "Hackish" workaround, and changes by Salesforce at any release could break the DOM model if you use Javascript.

 

Other than that, it's fine.

All Answers

VK86VK86

I used the below code to run Java Script on clicking a button.

Hope this helps.

 

/* This code allows the javascript to access the API and push data into the Org.*/ 
{!requireScript("/soap/ajax/10.0/connection.js")}; 
sforce.connection.session = "{!$Api.Session_ID}"; 
function updateContact( ) 
{ 
try 
{ 
var c = new sforce.SObject("Contact"); 
c.Id = "{!Contact.Id}"; 
c.LastName = c.LastName; 
c.Title = "Delete"; 
var result = sforce.connection.update([c]); 
if (result[0].getBoolean("success") == false ) 
{ 
alert(result[0].errors.message); 
return; 
} 
window.top.location.href=window.top.location.href; 
} 
catch (e) 
{ 
alert(e); 
}
} 

updateContact();

 

Thanks,

VK

Cory CowgillCory Cowgill

If you want Javascript to execute on load of a Standard Salesforce UI page, you can accomplish this via a Hompage Component.

 

Step 1. Create a Homepage Sidebar Component.

Setp 2. Inside Homepage Component, add the Javascipt via "Edit HTML Source" on the Component. Have the Javascript execute on window load.

Step 3. Add the Homepage Component to layout.

 

This is process I've used several times to execute javascript on load of a standard detail page. You can do things like remove elements from the page based on element names or ids from standard page layouts that you can't normally do without replacing with a VF page.

 

My only word of advice is be careful. Its a very "Hackish" workaround, and changes by Salesforce at any release could break the DOM model if you use Javascript.

 

Other than that, it's fine.

This was selected as the best answer
srinath tersrinath ter

Thanks. This was useful for me in one way. However, if I need to execute a javascript on Article page, where do I add? 
I could not see the sidebars getting loaded in the Article tab.

z_harika88z_harika88

Hi,

 

I would like to execute javascript code on article page.

Please help me if there are any workaround.

rajni bhagat 9rajni bhagat 9
I want to the link of java script result .how can i gethe output window of java script code