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
Vigneshwaran LoganathanVigneshwaran Loganathan 

Error: Compile Error: Non-void method might not return a value or might have statement after a return statement

 public pagereference submit()
    {
       integer count = [select count() FROM Sworn_Undertaking__c WHERE id =:swornUT.id];
        if (count>0)  // Error at this Line
        {
        if(SUT.submit_done__C == false)
        {
            sakid = 'Y';
            system.debug('***sakid'+sakid);
            SUT.City_of__c = swornUT.City_of__c;
            SUT.Address__c = swornUT.Address__c;
             upsert SUT;    
                
        }
        else
        {
             sakid = 'N';
             ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,' You have already entered details in Sworn Undertaking Form'));   
        }
        return null;
        else
        {
             sakid = 'N';
             ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,' You have already entered details in Sworn Undertaking Form'));   
        }
        
        
         pagereference pdf = page.pdfSwornUndertaking;
         pdf.getParameters().put('id',SUT.New_applicant_Name__c);
         Attachment attach = new Attachment();
         Blob body;
         try
         {
             body=pdf.getcontent();
         }
         catch(visualforceException e)
         {
             body=Blob.valueOf('Some Text');
         }
         return null;
        
}}

I have given return null but its still shows the same.. Am i wrong Anywhere?
PrakashbPrakashb
Hi,

The 'return null' is inside the if condition.

You need to add it outside the if condition.

Regards,
Prakash B
Waqar Hussain SFWaqar Hussain SF
public pagereference submit(){
       integer count = [select count() FROM Sworn_Undertaking__c WHERE id =:swornUT.id];
        if (count>0)  
        {
        if(SUT.submit_done__C == false)
        {
            sakid = 'Y';
            system.debug('***sakid'+sakid);
            SUT.City_of__c = swornUT.City_of__c;
            SUT.Address__c = swornUT.Address__c;
             upsert SUT;    
                
        }
        else
        {
             sakid = 'N';
             ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,' You have already entered details in Sworn Undertaking Form'));   
        }
        return null;
        }else{
             sakid = 'N';
             ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,' You have already entered details in Sworn Undertaking Form'));   
        }
        
         pagereference pdf = page.pdfSwornUndertaking;
         pdf.getParameters().put('id',SUT.New_applicant_Name__c);
         Attachment attach = new Attachment();
         Blob body;
         try
         {
             body=pdf.getcontent();
         }
         catch(visualforceException e)
         {
             body=Blob.valueOf('Some Text');
         }
         return null;
        
}