+ Start a Discussion
sathya82sathya82 

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

My Webservice Code how can i modify my code.

 

webservice static ResponseClass Method2(String accName)
{

ResponseClass res1 = new ResponseClass();
List<Account> del = [ Select ID, Name from Account where Name = :accName];
if(del.size() > 0)
{
res1.errorMessage = 'Account not  exists!';
return res1;
}

delete del;

}

Best Answer chosen by Admin (Salesforce Developers) 
GlynAGlynA

Try this:

 

webservice static ResponseClass Method2(String accName)
{
    ResponseClass res1 = new ResponseClass();
    res1.errorMessage = 'Account does not exist!';

    List<Account> del = [Select ID, Name from Account where Name = :accName];
    if ( del.isEmpty() ) return res1;
    delete del;
    return null;
}

 -Glyn

All Answers

Subramani_SFDCSubramani_SFDC

webservice static ResponseClass Method2(String accName)
{

ResponseClass res1 = new ResponseClass();
List<Account> del = [ Select ID, Name from Account where Name = :accName];
delete del;

if(del.size() > 0)
{
res1.errorMessage = 'Account not exists!';
return res1;
}

}

GlynAGlynA

Try this:

 

webservice static ResponseClass Method2(String accName)
{
    ResponseClass res1 = new ResponseClass();
    res1.errorMessage = 'Account does not exist!';

    List<Account> del = [Select ID, Name from Account where Name = :accName];
    if ( del.isEmpty() ) return res1;
    delete del;
    return null;
}

 -Glyn

This was selected as the best answer
Pankaj_Kumar_PandeyPankaj_Kumar_Pandey

webservice static ResponseClass Method2(String accName){


 ResponseClass res1 = new ResponseClass();

 res1.errorMessage = 'SUCCESS'; 
 List<Account> del = [ Select ID, Name from Account where Name = :accName];
 if(del.size() > 0){
   res1.errorMessage = 'Account  exists!';
   delete del;
 }
 return res1;

 

}