function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Somasundaram SubramanianSomasundaram Subramanian 

apex class skips


public void createServicesUsageT97(){

    if (zUsageToCreateT97.isEmpty()){
      System.debug('no usage to create in T97');
      return;
    }
      
    // batch by 50 usage records 
    for (Integer i = 0; i <= zUsageToCreateT97.size()/50 ; i++){
      JSONGenerator jsonBody = JSON.createGenerator(false);
      jsonBody.writeStartObject();
      jsonBody.writeStringField('type', 'Usage');
      jsonBody.writeObjectField('objects', batch50(i*50, zUsageToCreateT97.size()));
      jsonBody.writeEndObject();

      // remove the double quote before and after each object definition
      String jsonBodyToString = jsonBody.getAsString().replaceAll('\\"\\{','\\{');
      jsonBodyToString = jsonBodyToString.replaceAll('\\}\\"','\\}'); 
      // remove the escape character before the doubld quote
      jsonBodyToString = jsonBodyToString.replaceAll('\\\\','');
      System.debug('request body: ' + jsonBodyToString);

      HttpRequest req = new HttpRequest();
      req.setEndpoint('callout:'+ config.T97NamedCredential__c + '/v1/action/create?rejectUnknownFields=true');
      req.setHeader('Content-Type', 'application/json');
      req.setMethod('POST');
      req.setBody(jsonBodyToString);
      Http http = new Http();
      HttpResponse res = new HttpResponse();

      if (!Test.isRunningTest()){
        res = http.send(req);
      } else {
        res.setBody(mockResponse);
      } 

      if (res.getStatusCode() == 200){
        parseResponse(JSON.createParser(res.getBody()));
      } else {
        runtimeLog = Z_Util.addRunTimeLogCalloutException(runtimeLog, 'Issues creating usage in T97',
              res.getBody(), '', '');
      } 
    }   
    runtimeLog = Z_Util.addRunTimeLogItem(runtimeLog, (successfullyCreatedUsage.size() + ' successfully created T97 usage record(s)'));
  }

the above code skips and its not thowing error also am new to code , any idea why this skips
SwethaSwetha (Salesforce Developers) 
HI Somasundaram,

> I can see that code starts by checking if the zUsageToCreateT97 list is empty. If it is, then debug log should show "no usage to create in T97".  Therefore, if the list is empty, the method will not perform any further actions.

> Also the code uses a for loop to iterate over the zUsageToCreateT97 list in batches of 50. The loop condition is i <= zUsageToCreateT97.size()/50. If the zUsageToCreateT97 list has a size less than or equal to 50, the loop may not execute because the condition is not met.

> I suggest adding debug statements at various points within the method to track the flow and identify which specific part may be causing the skipping behavior.

>Also recommend reviewing the surrounding code or any other methods that interact with createServicesUsageT97(), as they can provide additional insights on this behavior.

Related: https://salesforce.stackexchange.com/questions/338007/why-is-my-batch-apex-test-skipping-the-entire-execute-method

If this information helps, please mark the answer as best. Thank you
Somasundaram SubramanianSomasundaram Subramanian
@swetha
           as per the below code if the currency field ffps_zuora__PrebillConsumed__c from financial package is greater than 0 then only zUsageToCreateT97 will be added, i thought this is skipped due to the value is 0, but in UAT when i tried for 0 value , its processed
am wondering even the value is 0 how the prebillusage is udpated, is this due to field from financial package?
  if (bei.ffps_zuora__PrebillConsumed__c > 0) {
        prebillUsage = setPrebillUsageData(bei, subName);
      }
 zUsageToCreateT97.add(usage.buildZuoraUsageT97());
        if (prebillUsage != null){
          zUsageToCreateT97.add(prebillUsage.buildZuoraUsageT97());