+ Start a Discussion
venkateshyadav1243venkateshyadav1243 

test class for web serivces method

Hi this is my class am using this in one button

can you please any one tell me how to write test class for the web services method.

 

global class letter
{
    WebService static string letter(string id)
    {
        try
        {
            Opportunity opp=[Select o.AccountId, o.Delivery__c,  from Opportunity o where o.id=:id];
            
            Quote Qt=new Quote();
            Qt.name='test';
            Qt.OpportunityId=opp.id;
            if(opp.Delivery__c!=null|| opp.Deliverys__c!='')
            {
                newQt.Delivery__c=opp.Delivery__c;
            }
            
            
            insert Qt;
            return 'letter';
        }
        catch(exception ex)
        {
            return 'Error';
        }
        
    }
    
}

 

Thanks for your replay

Best Answer chosen by Admin (Salesforce Developers) 
kiranmutturukiranmutturu
try this

@isTest
private class lettertest {

static testMethod void dolettertest()
{

opportunity opp = new opportunity();
opp.name = 'test record';
opp.Delivery__c = 'test delivery'

Test.starttest();
insert opp;


letter.letter(opp.id);

}
}