0

I need some help writing a test class for the following. Any help/suggestions would be greatly appreciated. Thanks

global class Oppty_SearchResponse{
    webservice Boolean isSuccess {set;get;}
    webservice String errorMessage {set;get;}
    webservice List<OpptyWrapper> lstOppWrapResults {set;get;}
}
//Opportunity wrapper class
global class OpptyWrapper {
    webservice String name;
    webservice String opptyNumber;
    webservice String stageName; 
    webservice Double amount; 
    webservice String distributionChannel;
    webservice Date   closeDate;
    webservice String accountName;
    webservice String tier2Partner;  
}

//Main web-service method
webservice static Oppty_SearchResponse performOpptySearch(Oppty_SearchData opptySearchData){
    List<OpptyWrapper> lstOpptyWraper = new List<OpptyWrapper>();
    Oppty_SearchHelper_IntegrationOperation searchHelper = new Oppty_SearchHelper_IntegrationOperation();
    Oppty_SearchResponse opptySearchResponse = new Oppty_SearchResponse();
    try{// Perform search operation
        opptySearchResponse= searchHelper.performOpptyHelperSearch(opptySearchData);
    }catch(Exception e){//On any error set operation is unsuccessful and send error message back
        opptySearchResponse.isSuccess= false;
        opptySearchResponse.errorMessage = 'Exception in Main class :getStackTraceString : ' + e.getStackTraceString() + ' -  Cause : ' + e.getCause() + ' - LineNumber : ' + e.getLineNumber() + ' - Message : ' + e.getMessage();
    }
return opptySearchResponse;
}

The main issue i'm having is with the webservice List<OpptyWrapper> lstOppWrapResults {set;get;} and the catch exception

catch(Exception e){//On any error set operation is unsuccessful and send error message back
            opptySearchResponse.isSuccess= false;
            opptySearchResponse.errorMessage = 'Exception in Main class :getStackTraceString : ' + e.getStackTraceString() + ' -  Cause : ' + e.getCause() + ' - LineNumber : ' + e.getLineNumber() + ' - Message : ' + e.getMessage();
        }
2
  • 2
    Hi RayRay! Your question is asking for other people to write code for you. SFSE is a Q&A forum where we look to help each other by asking and answering questions that are real problems or errors. Posting requests to write code for you will get closed. If you post what you've written so far of your test class and exactly where you're stuck, I'm confident you'll find plenty of people willing to assist you.
    – crmprogdev
    Commented May 28, 2015 at 21:29
  • 1
    that's an absurd accusation, @crmprogdev. i clearly have some of my test class written as i am specifically pointing out the areas where i am stuck. since when does help/suggestions = the answer?
    – RayRay
    Commented May 28, 2015 at 21:47

1 Answer 1

1

You could add this code to your class (or one of the helper classes involved):

@TestVisible private static Boolean throwException = false;

private class TestException extends Exception {
}

try{// Perform search operation
    if (throwException) {
        throw new TestException();
    }
    opptySearchResponse= searchHelper.performOpptyHelperSearch(opptySearchData);
}catch(Exception e){

and then in the test case turn the exception throwing on using:

WhateverTheClassNameIs.throwException = true;

But probably only worth the trouble if you expect the error case to happen.

0

Not the answer you're looking for? Browse other questions tagged .