Situation
I wrote a web service class. From my understanding unit tests in salesforce are supposed to test the whole functionality (end to end). But I don't know how to test this external interface.
Therefore my question is:
- Am I supposed to call the web service class from outside?
- How to Write a Test Class for Webservice Class?
Code
global class ObjectFieldUpdate2{
global class RequiredFields{
webservice String FieldName;
webservice String FieldValue;
}
webservice static String FiledtoUpdate2(String ObjName,Integer ExtId, List<RequiredFields> fieldvalues){
String str='';
Schema.SObjectType t = Schema.getGlobalDescribe().get(ObjName);
if(t!=null){
String query = 'select Id' + ' from ' + ObjName +' where External_Id__c ='+ExtId+' Limit 1';
SObject s = Database.query(query);
if(s!=null){
SObject sObjectUpdate = t.newSObject(s.Id);
try{
for(RequiredFields flds : fieldvalues)
sObjectUpdate.put(flds.FieldName, flds.FieldValue);
if(sObjectUpdate!=null)
Update sObjectUpdate;
}catch(Exception e){
str=e.getMessage();
}
}
}
if(str=='')
return 'Success';
else
return str;
}
}