How to get the name of Account as alert in visualforce page. I tried getting name of the user using below code.

<apex:page standardController="Account" recordSetVar="Accounts" sidebar="False" showHeader="false">
    <apex:form >
        <apex:pageBlock title="Hello {!$User.FirstName}!">
            <apex:pageBlockSection title="Details">
            <apex:pageBlockTable value="{!Accounts}" var="a">
                <apex:column value="{!a.name}"/>
                <apex:column value="{!a.type}"/>
                <apex:column value="{!a.Website}"/>
                <apex:column value="{!a.NumberOfEmployees}"/>
                <apex:column headerValue="Details">
                    <apex:commandButton value="Details" onClick="alert('{!$User.FirstName}')"/></apex:column>

Can anyone help me displaying Name of the Account on alert.


Try to use onClick="alert('{!a.name}')" instead of onClick="alert('{!$User.FirstName}')".

  • Thanks that's working :) – Sai Vineeth Maddula Feb 14 at 8:43
  • @SaiVineethMaddula If my answer helped resolve your issue, please mark the answer as accepted for the benefit of others. – Saroj Bera Feb 14 at 9:24

Also you can try like this for picklist, but you need the include jquery library

Like This:

<apex:includeScript value="{!$Resource.Jquery}"/>

Below Code VF Page:

<apex:page standardController="Account" extensions="DoesntMatterBro" standardStylesheets="false">

     <apex:selectList id="SelectedVal" value="{!Name}" size="1">
         <apex:selectOptions value="{!Options}"/>
     <apex:commandButton action="{!null}" reRender="noneurvey" value="Save" id="theButton"/>

Below code Jquery:

        $(document).ready(function() { 
            $(document).on("click", "[id$=theButton]", function() {

                a = $('.SelectedVal').val();


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.