• Stella maria
  • NEWBIE
  • 30 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 1
    Likes Given
  • 3
    Questions
  • 2
    Replies
Need Test class for this trigger

public with sharing class Rfleet_UpdateVehicleGroupStatus_TRG {

   public static void onAfterUpdate(list<VEH_Vehicle__c>lsvehicle) {
    
        list<VEH_Vehicle__c> lsvehObj= new list<VEH_Vehicle__c>();
        list<string> lsVehstatus= new list<string>();
        set<string> setvgroupid =new set<string>();
        List<string> lsgroupName = new List<string>();
        string strstatus=null;
              
        for(VEH_Vehicle__c Vehobj:lsvehicle){
                    
            if(Vehobj.ArisVhcStatus__c==Label.VEH_Erronous || Vehobj.ArisVhcStatus__c==Label.VEH_Registered){
                setvgroupid.add(Vehobj.VehicleGroup__c);

            }

        }
        lsgroupName.addAll(setvgroupid);
        
            for(integer j=0;j<lsgroupName.size();j++){
                Integer ko=0;
                Integer sent=0;
                Integer ok=0; 
                lsVehstatus.clear();
                strstatus=null;
                string strgroupid=null;
                lsvehObj=[Select id,ArisVhcStatus__c,VehicleGroup__c from VEH_Vehicle__c where VehicleGroup__c=:lsgroupName[j]];
                system.debug('group lsveh-->'+lsvehObj);  
               
               for(VEH_Vehicle__c lsStatus:lsvehObj){
                    lsVehstatus.add(lsStatus.ArisVhcStatus__c);
                                
                }
          
                    for(Integer i=0;i<lsVehstatus.size();i++){
                                           
                            if(lsVehstatus[i]==Label.VEH_Sent){
                                sent++;
                                 
                            }else if(lsVehstatus[i]==Label.VEH_Registered){
                                ok++;
                               
                            }else if(lsVehstatus[i]==Label.VEH_Erronous){
                                ko++;
                               
                            }
                        
                    }
            
                if(sent > 0){
                    if(ko > 0){
                        strstatus=Label.VEH_ReturnPartialKO;
                        
                    }else{
                        strstatus=Label.VEH_ReturnPartialOK;
                       
                        
                    }
                }else{
                    if(ko==0){
                        strstatus=Label.VEH_Validated;
                     
                    }else{
                        strstatus=Label.VEH_KO;
                     
                    }
                    
                }
             if(lsgroupName[j] !=null )
            {
            VHG_VehicleGroup__c updateVgroup=new VHG_VehicleGroup__c(id=lsgroupName[j],VHGStatus__c=strstatus);
            system.debug('final update group--->'+updateVgroup);
            update updateVgroup;
            }
        }
    }
      
}

Thanks in Advance
Trigger Order_Beforeupdate on Order (before update) {

 if(trigger.IsUpdate && trigger.isBefore)
 {
    if (Rfleet_TriggerAdministration.canTrigger('Order.OnBeforeUpdate')) {
        system.debug('## Inside Order Before update Trigger ## ');  
         
        Rfleet_ChangedOwnerRegistrationCard_TRG.onBeforeupdate(trigger.new,trigger.oldMap);
    } 
    
 } 

Class

 public static void onBeforeupdate(list<order>newMap,Map<Id,order>oldMap) {
      
        string strOwnerOfVehicleRegDoc;
        
        list<VEH_Vehicle__c> updateVehObj=new list<VEH_Vehicle__c>(); 
        list<VHG_VehicleGroup__c> VGHObj= new list<VHG_VehicleGroup__c>();
        list<VEH_Vehicle__c> VEHobj= new list<VEH_Vehicle__c>();
                 
          for(Order ordobj: newMap){
               
              order oldOpp =oldMap.get(ordobj.id);
              
               if(oldOpp.OwnerOfVehicleRegDocument__c != ordobj.OwnerOfVehicleRegDocument__c){
                    strOwnerOfVehicleRegDoc=oldOpp.OwnerOfVehicleRegDocument__c;
                  
                    system.debug('oldid----->'+strOwnerOfVehicleRegDoc);
                    
                } 
            }
                         system.debug('strOwnerOfVehicleRegDoc'+strOwnerOfVehicleRegDoc);
                         VGHObj=[Select id from VHG_VehicleGroup__c where VHGStatus__c !='Created' and OwnerRegDocument__c=:strOwnerOfVehicleRegDoc];
                         VEHobj=[SELECT id,VehicleGroup__c FROM VEH_Vehicle__c where VehicleGroup__r.VHGStatus__c='Created' and VehicleGroup__r.OwnerRegDocument__c=:strOwnerOfVehicleRegDoc];

                for(Order ordobjlist: newMap) {
                
                     if(VGHObj.size()>0){  
                      ordobjlist.addError('You can not change owner of registration card because of this Owner of registration card already linked VehicleGroup');
                   }
                }
        
        system.debug('list1size----->'+VEHobj.size());
            if(VEHobj.size()>0){
                for(VEH_Vehicle__c vehobjlist: VEHobj) {
                    vehobjlist.VehicleGroup__c=null;
                    updateVehObj.add(vehobjlist);
                }   
                update updateVehObj;
            }  
    }
}
Unable to login  @ Dev Org. dectivate a flow assicated with login flow for system admin. unable to login  thrown error message while login " no active flow"
Unable to login  @ Dev Org. dectivate a flow assicated with login flow for system admin. unable to login  thrown error message while login " no active flow"
Need Test class for this trigger

public with sharing class Rfleet_UpdateVehicleGroupStatus_TRG {

   public static void onAfterUpdate(list<VEH_Vehicle__c>lsvehicle) {
    
        list<VEH_Vehicle__c> lsvehObj= new list<VEH_Vehicle__c>();
        list<string> lsVehstatus= new list<string>();
        set<string> setvgroupid =new set<string>();
        List<string> lsgroupName = new List<string>();
        string strstatus=null;
              
        for(VEH_Vehicle__c Vehobj:lsvehicle){
                    
            if(Vehobj.ArisVhcStatus__c==Label.VEH_Erronous || Vehobj.ArisVhcStatus__c==Label.VEH_Registered){
                setvgroupid.add(Vehobj.VehicleGroup__c);

            }

        }
        lsgroupName.addAll(setvgroupid);
        
            for(integer j=0;j<lsgroupName.size();j++){
                Integer ko=0;
                Integer sent=0;
                Integer ok=0; 
                lsVehstatus.clear();
                strstatus=null;
                string strgroupid=null;
                lsvehObj=[Select id,ArisVhcStatus__c,VehicleGroup__c from VEH_Vehicle__c where VehicleGroup__c=:lsgroupName[j]];
                system.debug('group lsveh-->'+lsvehObj);  
               
               for(VEH_Vehicle__c lsStatus:lsvehObj){
                    lsVehstatus.add(lsStatus.ArisVhcStatus__c);
                                
                }
          
                    for(Integer i=0;i<lsVehstatus.size();i++){
                                           
                            if(lsVehstatus[i]==Label.VEH_Sent){
                                sent++;
                                 
                            }else if(lsVehstatus[i]==Label.VEH_Registered){
                                ok++;
                               
                            }else if(lsVehstatus[i]==Label.VEH_Erronous){
                                ko++;
                               
                            }
                        
                    }
            
                if(sent > 0){
                    if(ko > 0){
                        strstatus=Label.VEH_ReturnPartialKO;
                        
                    }else{
                        strstatus=Label.VEH_ReturnPartialOK;
                       
                        
                    }
                }else{
                    if(ko==0){
                        strstatus=Label.VEH_Validated;
                     
                    }else{
                        strstatus=Label.VEH_KO;
                     
                    }
                    
                }
             if(lsgroupName[j] !=null )
            {
            VHG_VehicleGroup__c updateVgroup=new VHG_VehicleGroup__c(id=lsgroupName[j],VHGStatus__c=strstatus);
            system.debug('final update group--->'+updateVgroup);
            update updateVgroup;
            }
        }
    }
      
}

Thanks in Advance
Unable to login  @ Dev Org. dectivate a flow assicated with login flow for system admin. unable to login  thrown error message while login " no active flow"

All, need help with test class on Batch apex. Below is batch apex code which make 2 callouts (for Token and actual data) however i`m not able to get test coverege on this class. All I have is 7% coverage. Can someone please help?
 
global class CalloutsAccounts implements Database.Batchable<sObject>,Database.AllowsCallouts{


   global Database.QueryLocator start(Database.BatchableContext BC){
        String query =  'SELECT Id FROM Account LIMIT 1';
        return Database.getQueryLocator(query); 
   }

   global void execute(Database.BatchableContext BC, List<Account> scope){
        HttpRequest obj = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();
        String reqBody = '{ "user": "Username", "passwd": "user_password" }';
        obj.setMethod('POST');
        obj.setHeader('Content-Type','application/json');
        obj.setEndPoint('https://test.samplepoint.com/api/UserSrvs.svc/Login');
        obj.setBody(reqBody);
        obj.getheader('Auth-Token');
        res = http.send(obj);

                authtoken objAuthenticationInfo = (authtoken)JSON.deserialize(res.getbody(), authtoken.class);
String token = res.getHeader('Auth-Token');


        Http h1 = new Http();
        HttpRequest req1 = new HttpRequest();
        String reqBody2 = ' {"Accountype" : "workforce"}'; 
        req1.setHeader('Auth-Token', token);
        req1.setHeader('Content-Type','application/json');
        req1.setMethod('POST');
         req1.setBody(reqBody2);

        req1.setEndpoint('https://test.samplepoint.com/api/accservices.svc/accountfeed');
        HttpResponse res1 = h1.send(req1);



                   JSONParser parser = JSON.createParser(res1.getBody());
                    parser.nextToken();
                     parser.nextValue();

                    String fieldName = parser.getCurrentName();
                    String fieldValue = parser.getText(); 

    accParser deserializeResults3 =  new accParser ();
    deserializeResults3 = (accParser)System.JSON.deserialize(fieldValue, accParser.class);
     List < accParser.cls_account> advisorList = new List< accParser.cls_account>();
    advisorList = deserializeResults3.root.accounts.account;

           Map <Decimal,Id> AdvisorMap = New Map  <Decimal,Id>   ();

        List <Account> advisorAccList = [SELECT Id, Fact_ID__c, RecordTypeID FROM Account WHERE RecordTypeid = '0124100000091Ho'];

        For (Account Acs : advisorAccList) {
            If (Acs.Fact_ID__c != null)
            AdvisorMap.put(Acs.Fact_ID__c, Acs.ID);
                }


             Map <String,Id> HouseholdMap = New Map  <String,Id>   ();

        List <Account> advisorAccList1 = [SELECT Id, SSCN__c, RecordTypeID FROM Account WHERE RecordTypeid = '012410000009Il6'];

        For (Account Acs1 : advisorAccList1) {
            If (Acs1.SSCN__c != null)
            HouseholdMap.put(Acs1.SSCN__c, Acs1.ID);
            system.debug('@@@'+HouseholdMap);
                }



List<Financial_Account__c> lstAccount = new List<Financial_Account__c>();
for(accountParser.cls_account cand : advisorList){
    Financial_Account__c PFA = New Financial_Account__c();
    //PFA.Cirrus_Unique_ID__c =  cand.account_id;

    //Map Advisor Lookup
   PFA.Advisor_ID__c = cand.advisor_id; 
   PFA.Advisor__c = AdvisorMap.get(PFA.Advisor_ID__c );  

    //Map Household Client Lookup
    PFA.Household_ID2__c = cand.household_id;
   if (HouseholdMap.get(PFA.Household_ID2__c) == null) {
       PFA.Client__c = '0013C000003Ywet'; 
} else if (PFA.Household_ID2__c != null) {
         PFA.Client__c = HouseholdMap.get(PFA.Household_ID2__c);  
}




    PFA.Unique_ID__c =  cand.account_id;
    PFA.Financial_Account_Number__c =  cand.accountnum;
    PFA.Account_Type__c =  cand.account;
    PFA.Tax_Status__c=  cand.taxablestatus;
    PFA.Investment_Objective__c =  cand.objective;
    if (cand.inception_date != null) {
    PFA.Account_Opening__c = date.parse(cand.inception);
        }
        if (cand.perf_begin_date != null) {
    PFA.perf_begin_date__c = date.parse(cand.perfdate);
        }
    // if (cand.household_id != null) {
  //  PFA.Household_ID__c = cand.housedate_id;
  //      }
    PFA.Account_Type__c =  cand.account_type;
   // PFA.Client__c =  '0013C000003CRTr'; LOOKUP TO ACCOUNTS
    PFA.compute_flg__c = cand.compute_flg;
    PFA.Account_Description__c = cand.description;
    PFA.fwc_hh_id__c = cand.fwc_hh_id;
        if (cand.termination_date != null) {
    PFA.termination_date__C = date.parse(cand.termination_date);
        }
        if (cand.last_date != null) {
    PFA.last_date__c = date.parse(cand.last_date);
        }
    PFA.Custodian_Id__c = cand.custodian_id;
    PFA.billing_account_num__c = cand.billing_account_num;
    PFA.rebal_method__c = cand.rebal_method;




    lstAccount.add(PFA);
}


Boolean isUpsertfirstTime = true;
try {
    upsert lstAccount Financial_Account_Number__c;
}catch (DMLException e) {
                System.debug('Re-trying');
                if(isUpsertfirstTime){
                        upsert lstAccount Financial_Account_Number__c;
                                isUpsertfirstTime = false;
              }
}


   }       

   global void finish(Database.BatchableContext BC){
              CalloutsAccounts2 myaccBatch = new CalloutsAccounts2();
      Id batchProcessId = Database.executeBatch(myacctBatch);

   }
}

Mock:
 
@isTest
global class MockHttpResponseGenerator implements HttpCalloutMock {
    // Implement this interface method
    global HTTPResponse respond(HTTPRequest req) {
        // Optionally, only send a mock response for a specific endpoint
        // and method.
               System.assertEquals('https://test.samplepoint.com/api/UserSrvs.svc/', req.getEndpoint());
        System.assertEquals('POST', req.getMethod()); 

        // Create a fake response
        HttpResponse res = new HttpResponse();
        res.setHeader('Content-Type', 'application/json');
res.setBody(''{ "user": "Username", "passwd": "user_password" }');
        res.setHeader('Auth-Token', '3+yV8B+7iSTu7Oj4alK4/fJPY1a5VRhAre6jG5vx6kDTXMOENFWJqAIQpuYE8nOdLwDmQBdo=');
 res.setStatusCode(200);         
        return res;
    }
}

Test class:
@isTest
private class CalloutClassTest {
     @isTest static void testCallout() {
        // Set mock callout class 

        Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator());
        Test.startTest();
  Account acc = new Account(  Name = 'My Test Account' );

  		  upsert acc;

        Database.executeBatch(new CalloutsAccounts(), 100);
        Test.stopTest();

    }