• Selvaganesh Ilango
  • NEWBIE
  • 30 Points
  • Member since 2017

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
please help me with this code so that i can able to display an error msg on vf page if user is  submitting for without the attachment

controller:
public class myWeb2LeadExtension {

    private final Lead weblead;
    private ID Leadid;
   
    public myWeb2LeadExtension(ApexPages.StandardController
                                stdController) {
       this.weblead = (Lead)stdController.getRecord();
       this.Leadid  = stdController.getId();
                                     
    }
    
    @testvisible transient private Attachment myfile;
    public Attachment getmyfile() {
    myfile = new Attachment();
    return myfile;
}

   
     public PageReference saveLead() {
       try {
        weblead.LeadSource='Job Application Non-India';
        weblead.Company='added from Job Application Page';
        weblead.Status='open';
        insert(weblead);
        Attachment a = new Attachment(parentid=weblead.id, Name = myfile.name , Body = myfile.Body );
        insert a;     
       }
       catch(System.DMLException e) {
           ApexPages.addMessages(e);
           return null;
       }
         
       PageReference p = Page.ThankYou;
       p.setRedirect(true);
       return p;
     }
        


VF page`:
 <tr><th><apex:outputLabel value="First Name"></apex:outputLabel></th></tr>
            <td><apex:inputField value="{!Lead.FirstName}" style="width:400px; height:30px;border-radius: 5px;" required="true"></apex:inputField></td>
            
            <tr><th><apex:outputLabel value="Last Name"></apex:outputLabel></th></tr>
            <td><apex:inputField value="{!Lead.LastName}" style="width:400px; height:30px;border-radius: 5px;" required="true"></apex:inputField></td>
            
            <tr><th><apex:outputLabel value="Email"></apex:outputLabel></th></tr>
            <td><apex:inputField value="{!Lead.Email}" style="width:400px; height:30px;border-radius: 5px;" required="true"></apex:inputField></td>
            
            <tr><th><apex:outputLabel value="Position Applying For"></apex:outputLabel></th></tr>
            <td><apex:inputField value="{!Lead.position__c}" style="width:400px; height:30px;border-radius: 5px;" required="true"></apex:inputField></td>
            
            <tr><th><apex:outputLabel value="Location"></apex:outputLabel></th></tr>
            <td><apex:inputField value="{!Lead.Location__c}" style="width:400px; height:30px;border-radius: 5px;" required="true"></apex:inputField></td>
            
            <tr><th><apex:outputLabel value="Summarize your education and experience."></apex:outputLabel></th></tr>
            <td><apex:inputField value="{!Lead.Expirience__c}" style="width:400px; height:30px;border-radius: 5px;" required="true"></apex:inputField></td>
            
            <tr><th><apex:outputLabel value="What type of opportunity are you looking for?"></apex:outputLabel></th></tr>
            <td><apex:inputField value="{!Lead.Career_Interest__c}" style="width:400px; height:30px;border-radius: 5px;" required="true"></apex:inputField></td>
            
            <tr><th><apex:outputLabel value="What is your current salary?"></apex:outputLabel></th></tr>
            <td><apex:inputField value="{!Lead.Current_Salary__c}" style="width:400px; height:30px;border-radius: 5px;" required="true"></apex:inputField></td>
            
            <tr><th><apex:outputLabel value="What is your desired salary?"></apex:outputLabel></th></tr>
            <td><apex:inputField value="{!Lead.Desire_Salary__c}" style="width:400px; height:30px; border-radius: 5px;" required="true"></apex:inputField></td>
             
                    
            <tr><th><apex:outputLabel value="Resume" ></apex:outputLabel></th>  
            <td>
                <div class="file-input" style="background:#fff; margin-left:-355px;" name="username" >
                   <apex:inputfile value="{!myfile.body}" filename="{!myfile.Name}" required="true" id="username"  onclick="return(validate());"/>   
                </div>
                
              </td>  
              </tr> 
              
             <tr><th  class="padd"></th></tr> 
            <tr><th><apex:outputLabel value="Email OPT-IN"  ></apex:outputLabel>   
            <td><apex:inputField value="{!Lead.Email_OPT_IN__c}" style="margin-left:-320px;"></apex:inputField></td></th></tr>
              
            </div>   
                
                <apex:pageBlockButtons location="bottom" style="background:#fff">
                    <div class="save-button" style="float: left;width: 100%;margin-top: 45px;margin-left: 50px; margin-bottom: 20px;">                      
                    
                        <apex:commandButton styleclass="slds-button slds-button_brand" value="Save" action="{!saveLead}"/>               
                        
                    </div>
please help me with this code so that i can able to display an error msg on vf page if user is  submitting for without the attachment

controller:
public class myWeb2LeadExtension {

    private final Lead weblead;
    private ID Leadid;
   
    public myWeb2LeadExtension(ApexPages.StandardController
                                stdController) {
       this.weblead = (Lead)stdController.getRecord();
       this.Leadid  = stdController.getId();
                                     
    }
    
    @testvisible transient private Attachment myfile;
    public Attachment getmyfile() {
    myfile = new Attachment();
    return myfile;
}

   
     public PageReference saveLead() {
       try {
        weblead.LeadSource='Job Application Non-India';
        weblead.Company='added from Job Application Page';
        weblead.Status='open';
        insert(weblead);
        Attachment a = new Attachment(parentid=weblead.id, Name = myfile.name , Body = myfile.Body );
        insert a;     
       }
       catch(System.DMLException e) {
           ApexPages.addMessages(e);
           return null;
       }
         
       PageReference p = Page.ThankYou;
       p.setRedirect(true);
       return p;
     }
        


VF page`:
 <tr><th><apex:outputLabel value="First Name"></apex:outputLabel></th></tr>
            <td><apex:inputField value="{!Lead.FirstName}" style="width:400px; height:30px;border-radius: 5px;" required="true"></apex:inputField></td>
            
            <tr><th><apex:outputLabel value="Last Name"></apex:outputLabel></th></tr>
            <td><apex:inputField value="{!Lead.LastName}" style="width:400px; height:30px;border-radius: 5px;" required="true"></apex:inputField></td>
            
            <tr><th><apex:outputLabel value="Email"></apex:outputLabel></th></tr>
            <td><apex:inputField value="{!Lead.Email}" style="width:400px; height:30px;border-radius: 5px;" required="true"></apex:inputField></td>
            
            <tr><th><apex:outputLabel value="Position Applying For"></apex:outputLabel></th></tr>
            <td><apex:inputField value="{!Lead.position__c}" style="width:400px; height:30px;border-radius: 5px;" required="true"></apex:inputField></td>
            
            <tr><th><apex:outputLabel value="Location"></apex:outputLabel></th></tr>
            <td><apex:inputField value="{!Lead.Location__c}" style="width:400px; height:30px;border-radius: 5px;" required="true"></apex:inputField></td>
            
            <tr><th><apex:outputLabel value="Summarize your education and experience."></apex:outputLabel></th></tr>
            <td><apex:inputField value="{!Lead.Expirience__c}" style="width:400px; height:30px;border-radius: 5px;" required="true"></apex:inputField></td>
            
            <tr><th><apex:outputLabel value="What type of opportunity are you looking for?"></apex:outputLabel></th></tr>
            <td><apex:inputField value="{!Lead.Career_Interest__c}" style="width:400px; height:30px;border-radius: 5px;" required="true"></apex:inputField></td>
            
            <tr><th><apex:outputLabel value="What is your current salary?"></apex:outputLabel></th></tr>
            <td><apex:inputField value="{!Lead.Current_Salary__c}" style="width:400px; height:30px;border-radius: 5px;" required="true"></apex:inputField></td>
            
            <tr><th><apex:outputLabel value="What is your desired salary?"></apex:outputLabel></th></tr>
            <td><apex:inputField value="{!Lead.Desire_Salary__c}" style="width:400px; height:30px; border-radius: 5px;" required="true"></apex:inputField></td>
             
                    
            <tr><th><apex:outputLabel value="Resume" ></apex:outputLabel></th>  
            <td>
                <div class="file-input" style="background:#fff; margin-left:-355px;" name="username" >
                   <apex:inputfile value="{!myfile.body}" filename="{!myfile.Name}" required="true" id="username"  onclick="return(validate());"/>   
                </div>
                
              </td>  
              </tr> 
              
             <tr><th  class="padd"></th></tr> 
            <tr><th><apex:outputLabel value="Email OPT-IN"  ></apex:outputLabel>   
            <td><apex:inputField value="{!Lead.Email_OPT_IN__c}" style="margin-left:-320px;"></apex:inputField></td></th></tr>
              
            </div>   
                
                <apex:pageBlockButtons location="bottom" style="background:#fff">
                    <div class="save-button" style="float: left;width: 100%;margin-top: 45px;margin-left: 50px; margin-bottom: 20px;">                      
                    
                        <apex:commandButton styleclass="slds-button slds-button_brand" value="Save" action="{!saveLead}"/>               
                        
                    </div>