+ Start a Discussion
The new LearnerThe new Learner 

Test class for Json method

Hi Experts,

Can anyone help me how to write test class for the below method.

public override void onCommit(){
        OM_ManageService manageRemittanceSVC = (OM_ManageRService)this.svc;
        String accJSON = OM_WorkService.getJSONAttribute(manageRemittanceSVC.jsonString, 'AccountInfo');
        Map<String, List<SObject>> accObjects =  OM_WorkService.getSObjects(accJSON);
        Account acc = (Account)accObjects.get('Account')[0];
        if(acc!= null){
            upsert acc;
        Below is the OM_WorkService.getJSONAttribut    
             public static String getJSONAttribute(String jsonStr, String attr){
        Map<String, Object> m = (Map<String, Object>)JSON.deserializeUntyped(jsonStr);
            return (String)m.get(attr);
        return null;
Pruthiviraj GanePruthiviraj Gane
private class TestClass {

    static testMethod void testMethod() {
       Account a = new Account();
       a.Name = 'Test';
       List<Account> accountList = new List<Account>();
       Map<String,List<Account>> accountMap = new Map<String,List<Account>>();
       String json = JSON.serialize(accountMap);

       OM_ManageService o = new OM_ManageService();
       o.svc.jsonString = json;

Then you have to call the commit method within the test method. If you can send definition for svc from  OM_ManageService class and the name of the class where onCommit method exists. So I can send you more code regarding this.