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
aaishaa19aaishaa19 

Button's Action in Page blocks

I have a VF page, with two page blocks in it Both blocks contain pageBlockButtons ,
 containing one button in each..
There are few field in each block which are populated on button click ...

The Problem is when I click on one button .. The action of the button invoked and populate and when I click
on 2nd nothing happen.. And vice versa..

At time only one button's action is invoked and other remain idle..


Please tell me where im going wrong.!!
Any kinda help will b appreciated


Regards;
Aisha

Best Answer chosen by Admin (Salesforce Developers) 
aaishaa19aaishaa19

omG after spending my hours on R&D and diagnosing the problem i finally revealed that i was entering a field date time which was bugging it somehow..

 

:S i finally resolve this issue .. loll.. thnx for ur support .. Thank u very much :)

All Answers

Going South.ax738Going South.ax738

Provide valid id values for pageblock sections, and in the apex line with action, add rerender to include this pageblock section id.

aaishaa19aaishaa19

I already did same , assign an id to  the page block ...

Still only one button's action calling at time ...

 

I even put them in a single block , in different sections .. But im still having same issue ...

 

:smileysad:

 

Disastered ;

Aish.. ~~

Going South.ax738Going South.ax738

How about adding 'rendered=true' added on each page block? I know SF takes true as default if nothing is given but, sometimes it seems to work.

 

Can you post the pageblocks that you are using that are with buttons to better understand replace it in my org and see if its local to you or not etc.

aaishaa19aaishaa19

 

Visual Force Page 

<apex:page controller="MergeClientsController"><h2>merge clients</h2> <apex:form > <apex:pageblock title="merge clients" id="client1" mode="edit"> <apex:pageblockbuttons > <apex:commandbutton value="save" action="{!save}" /> <apex:commandbutton value="close" action="{!close}" /> </apex:pageblockbuttons> <apex:pageblock title="first client"> <apex:pageblockbuttons > <apex:commandbutton value="get 1st client" action="{!GetClient1}" id="CL1"/> <apex:commandbutton value="get 2nd client" action="{!GetClient2}" id="CL2"/> </apex:pageblockbuttons> <apex:pageblocksection title="my content section" columns="2"> <apex:pageblocksectionitem > <apex:outputlabel > <h1>title:</h1> </apex:outputlabel> <apex:selectlist value="{!titles}" size="1"> <apex:selectoptions value="{!**bleep**}" /> </apex:selectlist> </apex:pageblocksectionitem> <apex:pageblocksectionitem > <apex:outputlabel > <h1>home phone:</h1> </apex:outputlabel> <apex:inputtext value="{!homePh}"/> </apex:pageblocksectionitem> <apex:pageblocksectionitem > <apex:outputlabel > <h1>first name:</h1> </apex:outputlabel> <apex:inputtext value="{!fname}"/> </apex:pageblocksectionitem> </apex:pageblocksection> <apex:pageblocksection title="my content section" columns="2"> <apex:pageblocksectionitem > <apex:outputlabel > <h1>title:</h1> </apex:outputlabel> <apex:selectlist value="{!titles}" size="1"> <apex:selectoptions value="{!**bleep**}" /> </apex:selectlist> </apex:pageblocksectionitem> <apex:pageblocksectionitem > <apex:outputlabel > <h1>home phone:</h1> </apex:outputlabel> <apex:inputtext value="{!homePh2}"/> </apex:pageblocksectionitem> <apex:pageblocksectionitem > <apex:outputlabel > <h1>first name:</h1> </apex:outputlabel> <apex:inputtext value="{!fname2}"/> </apex:pageblocksectionitem> </apex:pageblocksectionitem> </apex:pageblocksection> </apex:pageblock> </apex:pageblock> </apex:form> </apex:page>

 Apex Controller

public with sharing class MergeClientsController 
{
    String titles ; 
    String occupations ;
    String referrals ;
    String roles ;
    String sources ;
    String internals ;
    String flags ;
   
    public String fNAme {get; set;}
    public String title {get; set;}
    public String homePh {get; set;}
   
    //---------------------------------
    public String fNAme2 {get; set;}
    public String title2 {get; set;}
    public String homePh2 {get; set;}
    
    
    
    public PageReference MergeClientsController() 
    {
        return null;
    }
    
     public MergeClientsController() {
    }

    public MergeClientsController(ApexPages.StandardController controller)
    {
    }     
    
    public List<SelectOption> getTit() 
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('MR','Mr'));
        options.add(new SelectOption('MRS','Mrs'));
        options.add(new SelectOption('MS','Ms'));
        return options;
    }
    public String getTitles() 
    {
        return titles;
    }
    public void setTitles(String titles) 
    {
        this.titles = titles;
    }

    public List<SelectOption> getOcc() 
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('TEST1','testOccp1'));
        options.add(new SelectOption('TEST2','testOccp2'));
        options.add(new SelectOption('TEST3','testOccp3'));
        return options;
    }
    public String getOccupations() 
    {
        return occupations;
    }
    public void setOccupations(String occupations) 
    {
        this.occupations= occupations;
    }

    public List<SelectOption> getRef() 
    {
        List<SelectOption> options = new List<SelectOption>();
        for (Referral_Type__c RefType: [Select Active__c, Name, ReferralCode__c, ReferralID__c from Referral_Type__c])
             {
                  options.add(new SelectOption(RefType.Name,RefType.Name)); 
            }    
            return options;
    }
    public String getReferrals () 
    {
        return referrals ;
    }
    public void setReferrals (String referrals ) 
    {
        this.referrals = referrals ;
    }

    public List<SelectOption> getSrc() 
    {
    
      List<SelectOption> options = new List<SelectOption>();
        for (Source__c src1  : [Select Name, SourceID__c, Type__c from Source__c])
             {
                  options.add(new SelectOption(src1.Name,src1.Name)); 
            }     
        return options;
    }
    public String getSources () 
    {
        return sources ;
    }
    public void setSources (String sources ) 
    {
        this.sources = sources ;
    }

    public List<SelectOption> getInt() 
    {
        List<SelectOption> options = new List<SelectOption>();
        for (Consultant__c  internal1  : [Select Code__c, ExecutiveFlag__c, Level__c, Name from Consultant__c ])
             {
                  options.add(new SelectOption(internal1 .Name,internal1 .Name)); 
            }     
        return options;

    }
    public String getInternals () 
    {
        return internals ;
    }
    public void setInternals (String internals ) 
    {
        this.internals = internals ;
    }

    public List<SelectOption> getRole() 
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('TEST1','Sales Consultant'));
        options.add(new SelectOption('TEST2','OneLife Assistant'));
        options.add(new SelectOption('TEST3','Accounts'));
        options.add(new SelectOption('TEST4','Administration'));
        options.add(new SelectOption('TEST5','IT'));
        return options;
    }
    public String getRoles () 
    {
        return roles ;
    }
    public void setRoles (String roles ) 
    {
        this.roles = roles ;
    }

    public List<SelectOption> getFlag() 
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('TEST1','Any Refund'));
        options.add(new SelectOption('TEST2','Deed of Release'));
        options.add(new SelectOption('TEST3','Block Correspondonce'));
        options.add(new SelectOption('TEST4','Block SMS'));
        return options;
    }
    public String getFlags () 
    {
        return flags ;
    }
    public void setFlags (String flags) 
    {
        this.flags = flags ;
    }
    public void GetClient1() 
    {
      Account masterAcct = [   Select  Account_ID__c,  BestTimeToBeContacted__c,  Birthdate__c,  DriversLicenceNo__c,
                               Email__c,  Fax,  FirstName__c,  InternalConsultant__c,  InternalConsultant__r.Code__c,  InternalConsultant__r.CreatedById, 
                               InternalConsultant__r.CreatedDate,  InternalConsultant__r.ExecutiveFlag__c,  InternalConsultant__r.Id,  InternalConsultant__r.IsDeleted, 
                               InternalConsultant__r.LastModifiedById,  InternalConsultant__r.LastModifiedDate,  InternalConsultant__r.Level__c,  InternalConsultant__r.Name, 
                               InternalConsultant__r.OwnerId,  InternalConsultant__r.SystemModstamp,  LastName__c,  Mobile__c,  Notes__c,  NumberofLocations__c, 
                               Occupation__c,  OtherPhone__c,  PapCompanyID__c, Phone, 
                               ReferralClient__r.ClientID__c, ReferralClient__r.LastName__c, ReferralType__c,  
                               Salutation__c,  ShippingCity,  ShippingCountry,  ShippingPostalCode,  ShippingState,  ShippingStreet,  Source__c, 
                               Source__r.CreatedById,  Source__r.CreatedDate,  Source__r.Id,  Source__r.IsDeleted,  Source__r.LastModifiedById, 
                               Source__r.LastModifiedDate,  Source__r.Name,  Source__r.OwnerId,  Source__r.SourceID__c,  Source__r.SystemModstamp,  Source__r.Type__c, 
                               SpouseName__c from Account where name = 'Acme4' limit 1];
                                   
       fNAme= masterAcct.FirstName__c;     
       homePh = masterAcct.Phone; 
   
      /*  
       
               refType = masterAcct.ReferralType__c ; 
       source = masterAcct.Source__c; 
             role = masterAcct.FirstName__c; 
       */
                              
    }

    public void GetClient2() 
    {

        Account childAcct = [   Select  Account_ID__c,  BestTimeToBeContacted__c,  Birthdate__c,  DriversLicenceNo__c,
                                Email__c,  Fax,  FirstName__c,  InternalConsultant__c,  InternalConsultant__r.Code__c,  InternalConsultant__r.CreatedById, 
                                InternalConsultant__r.CreatedDate,  InternalConsultant__r.ExecutiveFlag__c,  InternalConsultant__r.Id,  InternalConsultant__r.IsDeleted, 
                                InternalConsultant__r.LastModifiedById,  InternalConsultant__r.LastModifiedDate,  InternalConsultant__r.Level__c,  InternalConsultant__r.Name, 
                                InternalConsultant__r.OwnerId,  InternalConsultant__r.SystemModstamp,  LastName__c,  Mobile__c,  Notes__c,  NumberofLocations__c, 
                                Occupation__c,  OtherPhone__c,  PapCompanyID__c, Phone, 
                                ReferralClient__r.ClientID__c, ReferralClient__r.LastName__c, ReferralType__c,  
                                Salutation__c,  ShippingCity,  ShippingCountry,  ShippingPostalCode,  ShippingState,  ShippingStreet,  Source__c, 
                                Source__r.CreatedById,  Source__r.CreatedDate,  Source__r.Id,  Source__r.IsDeleted,  Source__r.LastModifiedById, 
                                Source__r.LastModifiedDate,  Source__r.Name,  Source__r.OwnerId,  Source__r.SourceID__c,  Source__r.SystemModstamp,  Source__r.Type__c, 
                                SpouseName__c from Account where name = 'Naveed Anwar' limit 1];
                                    
        fNAme2= childAcct.FirstName__c; 
        homePh2 = childAcct.Phone; 
             
       /*  
         role2 = childAcct.FirstName__c; 
        */
                               
    }

    public void Save() 
    {
         Account account = new Account( FirstName__c='a'+ fNAme , 
                     Name='KINza');
                
                  try 
            {
               insert account;
            } 
            catch (DmlException e) 
            {
                // Process exception here  
                
            }


       //Now Delete Record
         Account masterAcct = [Select  id  from Account where name = 'KINza' limit 1];
         Account childAcct = [Select  id from Account where name = 'KINza' limit 1];
       
     try 
    {
        delete masterAcct ;
        delete childAcct ;
    } 
    catch (DmlException e) 
    {
        // Process exception here  
        
    }

     
     }



    public void Close() 
    {
    }

}

 

im able to get jus one client at time ... or either im able to call save method ..

i even make a single pageblock and two sectionblocks having two  client's data ...

 

 

n yea .. i knw really nothing much about salesForce ... lol :smileysad:

 

Aisha .. !!!

 

Going South.ax738Going South.ax738

Try the following:

                <apex:pageblockbuttons >
                    <apex:commandbutton value="get 1st client" action="{!GetClient1}" id="CL1" rerender="pb_cl1" />
                        
                        <apex:commandbutton value="get 2nd client" action="{!GetClient2}" id="CL2"  rerender="pb_cl2"/>
                </apex:pageblockbuttons>  

                <apex:pageblocksection title="my content section" id="pb_cl1" columns="2">
            ----------- blah blah ...columns for client 1

                                     </apex:pageblocksection>
               <apex:pageblocksection title="my content section"  id="pb_cl2" columns="2">
            ----------- blah blah ...columns for client 2

aaishaa19aaishaa19

omG after spending my hours on R&D and diagnosing the problem i finally revealed that i was entering a field date time which was bugging it somehow..

 

:S i finally resolve this issue .. loll.. thnx for ur support .. Thank u very much :)

This was selected as the best answer