2022 Developer Survey is open! Take survey.

Hot answers tagged

6 votes
Accepted

Possible to call a javascript and action function from click

Yes, you can. You can use the onclick attribute like below. <apex:commandButton value="Search" action="{!objectCollection}" onclick="callJSFunc()" style="margin-left:10px" reRender="...
user avatar
  • 5,213
6 votes
Accepted

Cannot read property 'value' of null in this case

In this case, it was a simple typo: the ID value is cAsE-sEnSiTiVe. alert('called' + document.getElementById("thepage:theform:atextId").value); // ^ ...
user avatar
  • 430k
5 votes
Accepted

Adding One Year to Date Field Value Through Custom Button

It would look something like this: {!requireScript("/soap/ajax/37.0/connection.js")} var newRecords = []; var c = new sforce.SObject("Invoice_Statement__c"); c.id = "{!Invoice_Statement__c.Id}"; c....
user avatar
  • 430k
4 votes
Accepted

commandbutton on a vf page inside a section

Change your javascript function name from new() to something else say new_method() as new is a keyword. It will work.
user avatar
  • 490
4 votes
Accepted

Visualforce: Checkbox is not firing function onclick

The problem is reported in the console: Uncaught TypeError: checked is not a function It seems to be a name conflict but I can't see where. Changing the function name to e.g. isChecked works ...
user avatar
  • 129k
4 votes

Visualforce: Checkbox is not firing function onclick

The first thing you should always do when you face a Javascript error is open up the console. Here's how to do it on: Chrome Firefox Opera Safari IE If you had done so, you would have seen the ...
user avatar
  • 142k
4 votes
Accepted

Refresh Page After OnClick

This functionality works for me. If I include the below Visualforce Page in a Page Layout and click the button, it refreshes the whole page. <apex:page standardController="Case"> <apex:...
user avatar
  • 142k
4 votes
Accepted

Confirm Dialog Box On Detail Page

There is no exact and simple solution for this OK and CANCEL in Confirm Popup using javascript. But you can do this with the help of JQUERY. Try the below link to understand better... https://...
user avatar
  • 1,698
4 votes

OnComplete Javascript to pop up alert and Redirect to a record page

So when you create the script and use the binding the value of the binding is the what it was when the page loads. If all you wanted to do was redirect to the new case (without a message) that is ...
user avatar
  • 53.1k
4 votes
Accepted

How to detect showListButton/hideListButton being clicked on collapsible PageBlockSection?

Caution This code relies on the internal library, and so may break at any time. Use at your own risk. Basically, you can override the default method, which will allow you to do something based on ...
user avatar
  • 430k
4 votes
Accepted

How to get all buttons in my page from a controller javascript function(component, event, helper)?

Add an aura:id to the <ui:button /> component, then find the button by it. component: <ui:button aura:id="btn" label="A" press="{!c.disableMe}"/> <ui:button aura:id="btn" ...
user avatar
  • 10.1k
4 votes

Action failed: lightning:button$controller$handleClick [d.run is not a function]

In my case I was missing the exclamation point in action in the component definition: incorrect: onclick = "{ c.someEvent }" correct: onclick = "{! c.someEvent}"
user avatar
  • 41
4 votes
Accepted

Aura Iterate, get the aura:id of a span

When you're using normal HTML, you have a lot of flexibility in what you do with this. One solution not involving the use of id is to set a data attribute on the span: <aura:component> <...
user avatar
  • 430k
3 votes
Accepted

Query on Javascript get error Malformed_Query

update your query : sforce.connection.query("SELECT Id, Is_Picked__c,Last_Seen_By__c FROM Lead WHERE Id =\'"+records[0]+"\' LIMIT 1");
user avatar
3 votes
Accepted

Onclick javascript button click show available records of custom object

Please create a Custom button on the Object where you want to show all records and below is the Code for the custom button: {!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")} // Quering the database ...
user avatar
3 votes
Accepted

OnClick Javascript Button causing error on field with separate lines.

That's because you cannot have multiline strings in Javascript unless they are properly escaped. Try JSENCODE on the string: dog.colMrk__c = "{! JSENCODE(Birth_Record__c.Characteristics__c) }"; ...
user avatar
  • 58
3 votes
Accepted

Validating sObject fields in JavaScript Custom Button?

Replace: var currentProjectPhase = {!project_cloud__Project__c.Current_Project_Phase__c}; With: var currentProjectPhase = "{!project_cloud__Project__c.Current_Project_Phase__c}"; Also: if (...
user avatar
3 votes
Accepted

Using action and onclick together on command button

If you want to abort the action, return a value. If you do not want to abort the action, do not return a value. Example: <apex:commandButton value="Do Something" onclick="if(!...
user avatar
  • 430k
3 votes

Adding onclick to dynamically created button

I just did something like this the other day. Not sure if it meets all your needs but it at least illustrates the concept Component Controller ({ doinit: function(component,event,helper){ <...
user avatar
  • 53.1k
3 votes
Accepted

CommandButton oncomplete JS function not firing

The following works in my testing: <apex:commandButton value="Reject (Entry Criteria)" onclick="if(!confirm('Are you sure?')){return false};" action="{!debugSomething}" oncomplete="refreshPage();"...
user avatar
  • 53.1k
3 votes
Accepted

OnClick Javascript button error when merge field value is "St. John's"

You forgot the quotes on the outside: var encoded = "{!JSENCODE("St. John's")}"; This would render as: var encoded = "\"St. John\'s\"";
user avatar
  • 430k
2 votes
Accepted

Custom send email button: Only send once

Following code might help in updating a checkbox for that record. {!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")} var newRecords = []; var obj = new sforce.SObject("ObjectName"); obj.id ="{!...
user avatar
2 votes
Accepted

Custom Button to send email no working

SFDC_BigDog, please enable the apex class access and visualforce pages access for that profile and check it again. Setup->manageusers->profiles->scroll down and give acces to that particular pages ...
user avatar
  • 2,217
2 votes

Preventing a reload/refresh on form submit in Lightning

I got and answer on that.. i have used $("form").submit(function( event ) { event.preventDefault(); url = $form.attr( 'action' ); var posting = $....
user avatar
2 votes

Insert record to a different object cloning data from detail page

Looks like in your javascript you've missed {! } when referencing Form_Requests_abv__c.id Try this one: var query = "SELECT Account_abv__c ,Address_abv__c,Form_Request_abv__c, OwnerID, ...
user avatar
  • 2,111
2 votes
Accepted

VF Page on-click events for HTML elements

Simple way use for attribute of apex:ouputlabel and pass the id <apex:outputLabel value="Checkbox" for="theCheckbox"/> <apex:inputCheckbox value="{!inputValue}" id="theCheckbox"/> Let me ...
user avatar
2 votes

Call Public class method from onclick javascript

The input to the webservice is passed as a serialized JSON string. You need to accept a string as input to the webservice method and deserialize it in the method. So the definition of the webservice ...
user avatar
2 votes

OnClick Javascript attached to Custom button not working correctly

Your condition: if(!("{!Animal__c.RecordType}" != "2 – Invoice" || "{!Animal__c.Invoice_Status__c}" != "Credited")) will be executed only if condition inside parenthesis is false, meaning that both ...
user avatar
  • 4,057
2 votes
Accepted

Uncaught ReferenceError: callAF is not defined

Give your apex:param name attribute. So it will work. <apex:actionFunction name="callAF" action="{!checkActive}" reRender="pbt"> <apex:param name="apparam" id="accId" value="" assignTo="{!...
user avatar
2 votes
Accepted

If statement fails in Onclick javascript button

Can you please try below code, if the check value is coming as true from check=sforce.apex.execute("CheckAOCAccess","AOCAccess",{LoggedUser:"{!User.Id}"}); if(check=='true'){ // This line fails to ...
user avatar
  • 2,070

Only top scored, non community-wiki answers of a minimum length are eligible