• Sanjay Vinayak T
  • NEWBIE
  • 60 Points
  • Member since 2022

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 10
    Replies
Hi Devs,
I have a requirement that i need a search button in my visualforcepage, and i have two  Course master(Parent) object has Master detail relation ship with Training deal object(Child). 
If  i search Course_Name__c(Parent field) in search button it needs to display all the deals done in training_deal__c(Child)  object. 
Fileds in Course_Master__c object : Course_Name__c (Parent)
fields in Training_Deal__c  object : Course_Master__c (MDR), Deal_Risk_Status__c,Discount__c,Email_of_student__c i want to show these fields if i search for Course_Name__c. 
please help me with this and thanks in advance.
Hi,

I have a requirement to enter input fields on one Visualforce page and show the output of the same field on another visual force page.

below are my Visualforce page code and apex code.

Visualforce page 1:
<apex:page standardController="Vendors_Detail__c" extensions="Vendorhandler" id="page" >
        <!-- Javascript -->
    <script type="text/javascript">
    
    function nameValidation(id)
    {
         if(id == 'page:form:pb:pdf'){
        this.clickMe();
        }
         if(id == 'page:form:pb:save'){
        this.amtValidation();
        }
        
        var n = document.getElementById('{!$Component.page.form.pb.pbs.name}');
        var a = document.getElementById('{!$Component.page.form.pb.pbs.amtevent}');
         var c = document.getElementById('{!$Component.page.form.pb.pbs.city}');
        var b = document.getElementById('{!$Component.page.form.pb.pbs.country}');
        
        if(n.value == "")
        {
            alert("Name is mandatory");
            return false;
        }
        else if (a.value == ""){
            amtValidation();
            return false;
            }
            else if (b.value == "" || c.value == ""){
            clickMe();
            return false;
            }
                 
        }
    
  function amtValidation()
    {
        var a = document.getElementById('{!$Component.page.form.pb.pbs.amtevent}');
        var savebtn = document.querySelector("[id$='save']");
        
        if(a.value == "" )
        {
            alert("Enter Amount to show Send Email Button");
            savebtn.style.visibility = 'hidden';
            return false;
        }
        else
        {
            save();   
        }
        }
    
function clickMe()
     {
        var a = document.getElementById('{!$Component.page.form.pb.pbs.city}');
        var b = document.getElementById('{!$Component.page.form.pb.pbs.country}');
        var pdfbtn = document.querySelector("[id$='pdf']");
        
        if(a.value == "" )
        {
            alert("Enter state to show Generate Pdf Button");
            pdfbtn.style.visibility = 'hidden';
            return false;
          
        }
        else if(b.value == "")
        {
            alert("Enter Country to show Generate Pdf Button");
            pdfbtn.style.visibility = 'hidden';
            return false;
       
        }
        else
        {
            clickme();
        }
    }
   
    </script>
<!-- Javascript -->
    
    <apex:form id="form">
     <apex:pageBlock id="pb" >
        <apex:actionFunction action="{!save}" name="save" reRender="form"/>
        <apex:actionFunction action="{!clickme}" name="clickme" reRender="form"/>
        <apex:actionFunction name="toggleButton" reRender="op"/>
         <apex:param name = "paramName" value = "Value To be pass"/>
      <apex:pageBlockSection id="pbs" title="Vendor Registration Form" columns="2">
          <apex:inputText id="name" value="{!vendor.Vendor_Company_Name__c}" label="Vendor Company Name" required="true"/>
          <apex:inputText id="cperson" value="{!vendor.Vendor_Contact_Person__c}" label="Vendor Contact Person"/>
          <apex:inputText id="amtevent" value="{!vendor.Amount_Per_Event__c}" label="Amount Per Event" onchange="toggleButton()"/>
          <apex:inputText id="city" value="{!vendor.City__c}" label="City" onchange="toggleButton()"/>
          <apex:inputText id="country" value="{!vendor.Country__c}" label="Country" onchange="toggleButton()"/>
      </apex:pageBlockSection>
        
        <apex:outputPanel id="op">
        <apex:commandButton id="save" action="{!save}" value="Send Email" onclick="return nameValidation(this.id);"/>
        <apex:commandButton id="reset" action="{!reset}" value="Reset"  ></apex:commandButton>
        <apex:commandButton id="pdf" action="{!clickme}" value="Generate PDF" onclick="return nameValidation(this.id);"/>
        </apex:outputPanel>
        
     </apex:pageBlock>
    </apex:form>
   
</apex:page>
Apex Code:
public with sharing class Vendorhandler {
    public Vendors_Detail__c vendor {get; set;}
    
    public Vendorhandler(ApexPages.StandardController std) {
        vendor = (Vendors_Detail__c) std.getRecord();
    }   

    public PageReference save(){
        
        insert vendor;
        
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {'sasanjayt@gmail.com'};
        mail.setToAddresses(toAddresses);
        String emailSub = 'Vendor Registration Details';
                mail.setSubject(emailSub);
        String content = 'Vendor Company name = ' + vendor.Vendor_Company_Name__c + ',<br/><br/>'+ 
                              ' Vendor Contact person = ' + vendor.Vendor_Contact_Person__c + ',<br/><br/>' + 
                              'Amount per Event = ' + vendor.Amount_Per_Event__c + ',<br/><br/>' + 
                              'City = '+ vendor.City__c + ',<br/><br/>'+
                              'Country = '+ vendor.Country__c + '.<br/><br/>'+
                              '<br/><br/>Thank you <br/><br/>';
        mail.setHtmlBody(content);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
       
        return null;
        
    }
    public PageReference reset() {
        PageReference newpage = new PageReference(System.currentPageReference().getURL());
        newpage.getParameters().clear();
        newpage.setRedirect(true);
        return newpage;
    }
    
     public PageReference clickme(){
         insert vendor;
         PageReference newpage = Page.Vendor_Regidtration_form_pdf;
         newpage.setRedirect(true);
        //Vendors_Detail__c v = new Vendors_Detail__c();
        // v.Vendor_Company_Name__c = vendor.Vendor_Company_Name__c;
         //v.Vendor_Contact_Person__c = vendor.Vendor_Contact_Person__c;
         //v.Amount_Per_Event__c = vendor.Amount_Per_Event__c;
         //v.City__c = vendor.City__c;
         //v.Country__c = vendor.Country__c;
         return newpage;
         
         
    }
    
}

VisualFrce page 2:
<apex:page standardController="Vendors_Detail__c" extensions="Vendorhandler" renderAs="PDF">
    <apex:form>
        <apex:pageBlock title="Vendor Registration Form" >
            <apex:pageBlockSection>
                <apex:outputField value="{!vendor.Vendor_Company_Name__c}" label="Vendor Company Name"/>
            </apex:pageBlockSection>
 
        </apex:pageBlock>
    </apex:form>
</apex:page>

Kindly help me in accessing the values of input fields of page 1 to output field of page 2.

Thanks & Regards,
Sanjay Vinayak T

 
Hi All,

I wanted to show a custom error message on the Visualforce page for the below code.

Kindly help me in fixing the code and show the error message.
 
Trigger: 
trigger StudentRecordTrigger on Student_Details__c (after insert) {
    if(Trigger.isinsert || Trigger.isafter ){
        StudentRecordTriggerHandler.checkStudentStatus(Trigger.new);
    }
}

-----------------------------------------------------------------------------------------------

Trigger HandlerClass:

public class StudentRecordTriggerHandler {
    List<Student_Master__c> studentToUpdate {get; set;}
    public static void checkStudentStatus(List<Student_Master__c> newStudent){
        try{
            Set<Id> StuId = new Set<id>();
            
            if(newStudent!=null){
                for(Student_Master__c stu : newStudent){
                    StuId.add(stu.Id);
                }
            }
            
            List<Student_Master__c> studentToUpdate = new List<Student_Master__c>();
            studentToUpdate = [Select id, Background_Check_Status__c, PAN_Card_Number__c, Phone_Number__c from Student_Master__c where id in : StuId];
            
            if(StuId!=null){
                List<Black_Listed_Candidate__c> blackListedStu = [Select id from Black_Listed_Candidate__c where PAN__c = :studentToUpdate[0].PAN_Card_Number__c limit 1];
                if(blackListedStu!=null){
                    blackListedStu[0].Phone__c = studentToUpdate[0].Phone_Number__c;
                    update blackListedStu;
                    studentToUpdate[0].Background_Check_Status__c = 'Candidate is blacklisted! We cannot Hire.';
                    
                    update studentToUpdate;
                }
              if (studentToUpdate[0].Background_Check_Status__c !=null){
                  ApexPages.addmessage(new apexPages.Message(ApexPages.severity.WARNING,'<h1 style="color : red;"> Student is blacklisted.'));
              }  
            }
        }
        catch(Exception e){
            system.debug('failed to update');
        }
        
    }
}

--------------------------------------------------------------

Visualforce page:
<apex:page Controller="StudentRecordTriggerHandler">
  <apex:form >
   <apex:pageBlock >
      <apex:pageMessages id="Message" escape="False"></apex:pageMessages>
    </apex:pageBlock>
     </apex:form>
</apex:page>

Thank you.
Hi All,

I have created a batch class to update the fields. 
i want the count of the field updated based on the condition.
Global class BatchUpdateTrainer implements Database.Batchable<Sobject> {
    
    
    Global database.QueryLocator start(database.BatchableContext BC){
        return Database.getQueryLocator('Select id, Background_Check_Done__c, LinkedIn_Profile__c, Verification_Status__c from Trainer_Master__c);
    }
    
    Global void execute(database.BatchableContext BC, List<Trainer_Master__c> Scope){
	list<Trainer_Master__c> lstTM = new list<Trainer_Master__c>();
        for (Trainer_Master__c trainer : Scope){
		system.debug('Background Check Done >>>> ' + trainer.Background_Check_Done__c);
		system.debug('LinkedIn Profile >>>> ' + trainer.LinkedIn_Profile__c);
            if(trainer.Background_Check_Done__c =='No' && trainer.LinkedIn_Profile__c == null){
                trainer.Verification_Status__c = 'Details Needed';
				system.debug('Verification_Status__c1 ' + trainer.Verification_Status__c);
            }
            else if(trainer.Background_Check_Done__c =='No' && trainer.LinkedIn_Profile__c!= null){
                trainer.Verification_Status__c = 'Non Verified';
				system.debug('Verification_Status__c2 ' + trainer.Verification_Status__c);
            }
            else if(trainer.Background_Check_Done__c =='Yes' && trainer.LinkedIn_Profile__c!= null){
                trainer.Verification_Status__c = 'Verified';
				system.debug('Verification_Status__c3 ' + trainer.Verification_Status__c);
            }
			lstTM.add(trainer);
        }
        
        if(!lstTM.IsEmpty()){
		update lstTM;
		}
    }
    Global void finish(database.BatchableContext BC){
        
    }
}


TO Execute
BatchUpdateTrainer M = new BatchUpdateTrainer (); 
Database.executeBatch(M);

Above is my Batch class code and I want to count the number of records with the Verification_Status__c = 'Non Verified'.

Kindly help me in enhancing the code.

Thanks in advance.

Regards,
Sanjay Vinayak T
Hi All,

I'm trying to create a visual force page to enter vendor details and perform actions based on the details.

But I'm unable to generate Pdf upon clicking on the Botton on the Visual force page.
and need to validate some conditions to perform the action, but unable to validate.
Validation conditions are:
1. If the amount is blank, cannot click on the "Send Email" button.
2. Generating a PDF is not possible when the city and Country are not mentioned. 

Below are my Visual force page code and Controller code:
<apex:page standardController = "Vendors_Detail__c" extensions="Vendorhandler">
        <!-- Javascript -->
    <script type="text/javascript">

    function validate()
    {
        if(document.getElementById('{!$Component.form.pb.pbs.cname}').value == '')
        {
            alert("Vendor name is mandatory");
        }
        if(document.getElementById('{!$Component.form.pb.pbs.amtevent}').value == '')
        {
            document.getElementById('{!$Component.form.pb.pbs.save}').disabled = true;
        }
        if(document.getElementById('{!$Component.form.pb.pbs.city}').value == '' && 
           document.getElementById('{!$Component.form.pb.pbs.country}').value == '')
        {
           document.getElementById('{!$Component.form.pb.pbs.pdf}').disabled = true;
        }
    }
   
    </script>
<!-- Javascript -->
    
    <apex:form id="form">
    <apex:pageBlock id="pb">
        
    <apex:pageBlockButtons > 
        <apex:commandButton id="save" action="{!save}" value="Send Email" onclick="validate();"/>
        <apex:commandButton id="reset" action="{!reset}" value="Reset" onclick="validate();" ></apex:commandButton>
        <apex:commandButton id="pdf" action="{!generatePDF}" value="Generate PDF" onclick="validate();" />

    </apex:pageBlockButtons>
        
      <apex:pageBlockSection id="pbs" title="Vendor Registration Form" columns="2">
          
          <apex:inputText id="cname" value="{!vendor.Vendor_Company_Name__c}" label="Vendor Company Name" required="true"/>
          <apex:inputText id="cperson" value="{!vendor.Vendor_Contact_Person__c}" label="Vendor Contact Person"/>
          <apex:inputText id="amtevent" value="{!vendor.Amount_Per_Event__c}" label="Amount Per Event"/>
          <apex:inputText id="city" value="{!vendor.City__c}" label="City"/>
          <apex:inputText id="country" value="{!vendor.Country__c}" label="Country"/>
   
     </apex:pageBlockSection>
     </apex:pageBlock>
    </apex:form>
</apex:page>
public class Vendorhandler {
    public Vendors_Detail__c vendor {get; set;}
    
    public Vendorhandler(ApexPages.StandardController std) {
        this.vendor = (Vendors_Detail__c) std.getRecord();
    }   

    public PageReference save(){
        
        insert vendor;
        
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {'sasanjayt@gmail.com'};
        mail.setToAddresses(toAddresses);
        String emailSub = 'Vendor Registration Details';
                mail.setSubject(emailSub);
        String content = 'Vendor Company name = ' + vendor.Vendor_Company_Name__c + ',<br/><br/>'+ 
                              ' Vendor Contact person = ' + vendor.Vendor_Contact_Person__c + ',<br/><br/>' + 
                              'Amount per Event = ' + vendor.Amount_Per_Event__c + ',<br/><br/>' + 
                              'City = '+ vendor.City__c + ',<br/><br/>'+
                              'Country = '+ vendor.Country__c + '.<br/><br/>'+
                              '<br/><br/>Thank you <br/><br/>';
        mail.setHtmlBody(content);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        
        PageReference pr = new PageReference(System.currentPageReference().getURL());
        return pr;
        
    }
    public PageReference reset() {
        PageReference newpage = new PageReference(System.currentPageReference().getURL());
        newpage.getParameters().clear();
        newpage.setRedirect(true);
        return newpage;
    }
    
     public PageReference generatePDF(){
         PageReference newpage = new PageReference(System.currentPageReference().getURL());
        Vendors_Detail__c v = new Vendors_Detail__c();
         v.Vendor_Company_Name__c = vendor.Vendor_Company_Name__c;
         v.Vendor_Contact_Person__c = vendor.Vendor_Contact_Person__c;
         v.Amount_Per_Event__c = vendor.Amount_Per_Event__c;
         v.City__c = vendor.City__c;
         v.Country__c = vendor.Country__c;
         return newpage;
         
    }
    
}

Tried adding renderAs= "pdf" but visual force will be rendered as pdf and unable to enter the values.
User-added image

Kindly help me in fixing the code to achieve the desired output.

Thanks in advance.

Regards,
Sanjay Vinayak T 

 
Hi,

I want to update the fields in a custom object based on the condition using the Batch class. 
I have written a code on batch class but I'm unable to update the fields.

Below is the code which I have worked, 

Global class BatchUpdateTrainer implements Database.Batchable<Sobject> {
    
    
    Global database.QueryLocator start(database.BatchableContext BC){
        return Database.getQueryLocator('Select id, Background_Check_Done__c, LinkedIn_Profile__c, Verification_Status__c from Trainer_Master__c where id!=null');
    }
    
    Global void execute(database.BatchableContext BC, List<Trainer_Master__c> Scope){
        for (Trainer_Master__c trainer : Scope){
            if(trainer.Background_Check_Done__c =='No' && trainer.LinkedIn_Profile__c == null){
                trainer.Verification_Status__c = 'Details Needed';
            }
            else if(trainer.Background_Check_Done__c =='No' && trainer.LinkedIn_Profile__c!= null){
                trainer.Verification_Status__c = 'Non Verified';
            }
            else if(trainer.Background_Check_Done__c =='Yes' && trainer.LinkedIn_Profile__c!= null){
                trainer.Verification_Status__c = 'Verified';
            }
        }
        system.debug('verification status' + scope);
        Database.update(Scope);
    }
    Global void finish(database.BatchableContext BC){
        
    }
}

Kindly Help me to fix the code.

Thank You..!!

Regards,
Sanjay Vinayak T
Hi All,
 
There are 2 objects - 
Object 1- Student Details with Field 1- Pan Number, Field 2- Background status, Field 3-Phone number, 
Object 2- Backlisted candidates with Field 1 - Pan number and Field 2- Phone number. 
 
My requirement is: 
When a record is created/inserted in Object 1- Student Details.
 If Field 1- Pan Number of  Object 1- Student Details is equal to Field 1 - Pan number of Object 2- Backlisted candidates. 
Then update Field 2- Background status of Object 1- Student Details with a message as Student is blacklisted, and also update Field 2- Phone number of Object 2- Backlisted candidates with Field 3-Phone number of Object 1- Student Details.
I have tried with Flows but am unable to fetch the fields to compare.
 
So tried APEX Class and Triggers, but unable to update the fields.
 
Below is the Apex code and Trigger I worked on:
 
APEX Class:
 User-added image
Trigger: 
 User-added image
Kindly help me to improvise the code and work on it.
 
Or What should be the new approach for this problem using Apex and Trigger?
Hi Devs,
I have a requirement that i need a search button in my visualforcepage, and i have two  Course master(Parent) object has Master detail relation ship with Training deal object(Child). 
If  i search Course_Name__c(Parent field) in search button it needs to display all the deals done in training_deal__c(Child)  object. 
Fileds in Course_Master__c object : Course_Name__c (Parent)
fields in Training_Deal__c  object : Course_Master__c (MDR), Deal_Risk_Status__c,Discount__c,Email_of_student__c i want to show these fields if i search for Course_Name__c. 
please help me with this and thanks in advance.
Hi All,

I have created a batch class to update the fields. 
i want the count of the field updated based on the condition.
Global class BatchUpdateTrainer implements Database.Batchable<Sobject> {
    
    
    Global database.QueryLocator start(database.BatchableContext BC){
        return Database.getQueryLocator('Select id, Background_Check_Done__c, LinkedIn_Profile__c, Verification_Status__c from Trainer_Master__c);
    }
    
    Global void execute(database.BatchableContext BC, List<Trainer_Master__c> Scope){
	list<Trainer_Master__c> lstTM = new list<Trainer_Master__c>();
        for (Trainer_Master__c trainer : Scope){
		system.debug('Background Check Done >>>> ' + trainer.Background_Check_Done__c);
		system.debug('LinkedIn Profile >>>> ' + trainer.LinkedIn_Profile__c);
            if(trainer.Background_Check_Done__c =='No' && trainer.LinkedIn_Profile__c == null){
                trainer.Verification_Status__c = 'Details Needed';
				system.debug('Verification_Status__c1 ' + trainer.Verification_Status__c);
            }
            else if(trainer.Background_Check_Done__c =='No' && trainer.LinkedIn_Profile__c!= null){
                trainer.Verification_Status__c = 'Non Verified';
				system.debug('Verification_Status__c2 ' + trainer.Verification_Status__c);
            }
            else if(trainer.Background_Check_Done__c =='Yes' && trainer.LinkedIn_Profile__c!= null){
                trainer.Verification_Status__c = 'Verified';
				system.debug('Verification_Status__c3 ' + trainer.Verification_Status__c);
            }
			lstTM.add(trainer);
        }
        
        if(!lstTM.IsEmpty()){
		update lstTM;
		}
    }
    Global void finish(database.BatchableContext BC){
        
    }
}


TO Execute
BatchUpdateTrainer M = new BatchUpdateTrainer (); 
Database.executeBatch(M);

Above is my Batch class code and I want to count the number of records with the Verification_Status__c = 'Non Verified'.

Kindly help me in enhancing the code.

Thanks in advance.

Regards,
Sanjay Vinayak T
Hi,

I want to update the fields in a custom object based on the condition using the Batch class. 
I have written a code on batch class but I'm unable to update the fields.

Below is the code which I have worked, 

Global class BatchUpdateTrainer implements Database.Batchable<Sobject> {
    
    
    Global database.QueryLocator start(database.BatchableContext BC){
        return Database.getQueryLocator('Select id, Background_Check_Done__c, LinkedIn_Profile__c, Verification_Status__c from Trainer_Master__c where id!=null');
    }
    
    Global void execute(database.BatchableContext BC, List<Trainer_Master__c> Scope){
        for (Trainer_Master__c trainer : Scope){
            if(trainer.Background_Check_Done__c =='No' && trainer.LinkedIn_Profile__c == null){
                trainer.Verification_Status__c = 'Details Needed';
            }
            else if(trainer.Background_Check_Done__c =='No' && trainer.LinkedIn_Profile__c!= null){
                trainer.Verification_Status__c = 'Non Verified';
            }
            else if(trainer.Background_Check_Done__c =='Yes' && trainer.LinkedIn_Profile__c!= null){
                trainer.Verification_Status__c = 'Verified';
            }
        }
        system.debug('verification status' + scope);
        Database.update(Scope);
    }
    Global void finish(database.BatchableContext BC){
        
    }
}

Kindly Help me to fix the code.

Thank You..!!

Regards,
Sanjay Vinayak T
Hi All,
 
There are 2 objects - 
Object 1- Student Details with Field 1- Pan Number, Field 2- Background status, Field 3-Phone number, 
Object 2- Backlisted candidates with Field 1 - Pan number and Field 2- Phone number. 
 
My requirement is: 
When a record is created/inserted in Object 1- Student Details.
 If Field 1- Pan Number of  Object 1- Student Details is equal to Field 1 - Pan number of Object 2- Backlisted candidates. 
Then update Field 2- Background status of Object 1- Student Details with a message as Student is blacklisted, and also update Field 2- Phone number of Object 2- Backlisted candidates with Field 3-Phone number of Object 1- Student Details.
I have tried with Flows but am unable to fetch the fields to compare.
 
So tried APEX Class and Triggers, but unable to update the fields.
 
Below is the Apex code and Trigger I worked on:
 
APEX Class:
 User-added image
Trigger: 
 User-added image
Kindly help me to improvise the code and work on it.
 
Or What should be the new approach for this problem using Apex and Trigger?
Hi All,
On click of "Generate PDF" button,I have to show VF Page in PDF format with renderAs attribute.
I am able to render VF Page in PDF format but field values are not added in pdf.How to achieve this?
Please help!!!!

VF Page:
<apex:page controller="VendorRegister" tabStyle="Vendor__c" renderAs="PDF" >
    <!-- Javascript -->
    <script type="text/javascript">

    function validate()
    {
        if(document.getElementById('{!$Component.frm.pb.pbs.pbsi1.vendorcompname}').value == '')
        {
            alert("Vendor name is mandatory");
        }
        if(document.getElementById('{!$Component.frm.pb.pbs.pbsi2.amountperevent}').value == '')
        {
            document.getElementById('{!$Component.frm.pb.pbb.sendemail}').disabled = true;
        }
        if(document.getElementById('{!$Component.frm.pb.pbs.pbsi3.city}').value == '' && 
           document.getElementById('{!$Component.frm.pb.pbs.pbsi4.country}').value == '')
        {
           document.getElementById('{!$Component.frm.pb.pbb.pdfbutton}').disabled = true;
        }
    }
   
    </script>
<!-- Javascript -->
    <apex:form title="Vendor Registration Form" id="frm">
        <apex:pageBlock id="pb">
            <apex:pageBlockSection id="pbs" >
                <apex:pageBlockSectionItem > 
                    <apex:outputLabel >Vendor Company Name</apex:outputLabel>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem id="pbsi1">
                    <apex:inputText value="{!vendorcompname}" id="vendorcompname" />
                </apex:pageBlockSectionItem>
                
                <apex:outputLabel >Vendor Contact Person</apex:outputLabel><br/>
                <apex:inputText value="{!vendorconperson}"/><br/>
                 <apex:pageBlockSectionItem >
                <apex:outputLabel >Amount per Event</apex:outputLabel><br/>
                </apex:pageBlockSectionItem> 
                <apex:pageBlockSectionItem id="pbsi2">
                <apex:inputText value="{!amountperevent}" id="amountperevent"/><br/>
                    </apex:pageBlockSectionItem>
                 <apex:pageBlockSectionItem >
                <apex:outputLabel >City</apex:outputLabel><br/>
                </apex:pageBlockSectionItem>
                 <apex:pageBlockSectionItem id="pbsi3">
                <apex:inputText value="{!city}" id="city"/><br/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                <apex:outputLabel >Country</apex:outputLabel><br/>
                 </apex:pageBlockSectionItem>
                 <apex:pageBlockSectionItem id="pbsi4">
                <apex:inputText value="{!country}" id="country"/><br/>
                 </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:pageBlockButtons id="pbb" location="bottom">
                
               
        <apex:commandButton id="sendemail" value="Send Email"
                            onclick="validate();"
                           />
        <apex:commandButton value="Reset" />                                        
        <apex:commandButton id="pdfbutton" value="Generate PDF"  />                                          
        </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
    

</apex:page>
  • July 27, 2021
  • Like
  • 0
Hi All,
In my below code, return false is not working. I have highlighted those lines. Though i'm getting alert message "Enter state...." , command button is executed. Any help is appreciated.
=============
<apex:page controller="Bookings" id="page">
<script>
    
    function nameValidation(id){
        
        var n = document.getElementById('{!$Component.page.form.pb.pbs.name}');
        
        if(n.value == "")
        {
            alert("Name is mandatory");
            return false;
        }
       
       
        if(id == 'page:form:pb:pdf'){
        this.clickMe();
        }
        }
function clickMe()
     {
        var a = document.getElementById('{!$Component.page.form.pb.pbs.state}');
        var b = document.getElementById('{!$Component.page.form.pb.pbs.coun}');
        var pdfbtn = document.querySelector("[id$='pdf']");
        
        if(a.value == "" )
        {
            alert("Enter state to show Generate Pdf Button");
            pdfbtn.style.visibility = 'hidden';
            return false;
        }
        else if(b.value == "")
        {
            alert("Enter Country to show Generate Pdf Button");
            pdfbtn.style.visibility = 'hidden';
            return false;
        }
        else
        {
            alert("inside else");
            clickme();
        }
    }
</script>
 <apex:form id="form">
    <apex:actionFunction action="{!clickme}" name="clickme" reRender="pb"/>
  <apex:actionFunction name="toggleButton" reRender="op"/>
  <apex:pageBlock title="Booking Form" id="pb">
  <apex:pageBlockSection columns="2" id="pbs">
  Name :<apex:inputText value="{!person}" id="name" />
  State :<apex:inputText value="{!state}" id="state" onchange="toggleButton()"/>
  Country :<apex:inputText value="{!country}" id="coun" onchange="toggleButton()"/>
  </apex:pageBlockSection>
  <apex:outputPanel id="op">
  <apex:commandButton value="Click Me" id="pdf" action="{!clickme}" onclick="return nameValidation(this.id);"/>
  
  </apex:outputPanel>
  </apex:pageBlock>
  
  </apex:form>
</apex:page>
  • May 19, 2021
  • Like
  • 0