0

I am trying to query Using another class in One custom button. I need to compare one custom pick list value with another object custom field. If that matches, after click on this custom button one popup widow should appear.

global with sharing class PreventWarranty
{
    webService static String warranty(ID oppid)
    {
        Opportunity OppRecord = [SELECT Id, Project_Solution__c, PartnerAccountId FROM Opportunity Where Id =: oppid];
        String PartnerAccount = OppRecord.PartnerAccountId;
        string ProjectSolution = OppRecord.Project_Solution__c;
        date d = system.today().addDays(-180);
        List<Accreditation__c> AccredList = [Select Id, Solution_Type__c,Renewal_Date__c from Accreditation__c where 
                                             Account__c  = :PartnerAccount And 
                                             Renewal_Date__c < :d And
                                             Solution_Type__c = :ProjectSolution ];
        If(AccredList.size()>0)

        return 'Opportunity Number is ' + AccredList;      

    }
}

Here is my custom button:

Code Screenshot

I am facing this error at if condition:

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

One more error here:

enter image description here

1
  • You have return statement in if condition. What if this if block doesn't get execute.I think you have to add one more return for satisfying that need.return '' might work.
    – Mr.Frodo
    Commented Jul 16, 2016 at 6:45

1 Answer 1

5

Change:

If(AccredList.size()>0)

    return 'Opportunity Number is ' + AccredList; 

To something like:

If(AccredList.size()>0){

    return 'Opportunity Number is ' + AccredList.size(); 
}

return 'No Opportunity Found'; //or similar

The way you currently have it if the IF condition is not met then there would be no return

3
  • I think the return message inside your if statement should use AccredList.size(), not AccredList itself?
    – Adrian Larson
    Commented Jul 16, 2016 at 14:46
  • @Eric Thanks for your Valuable suggestion. But i still facing the error like above. Please find I updated question.
    – user24737
    Commented Jul 16, 2016 at 18:22
  • 1
    @chris That is a different question. Your original question has been answered (I believe). You should make a new question for that. The format here is around a specific problem not a perpetual discussion.
    – Eric
    Commented Jul 16, 2016 at 18:58

You must log in to answer this question.