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
amit wagaskaramit wagaskar 

what i need to add here so that this controller will throw an error on VF page if lead is creating without an attachment

//my controller

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;
     }