Checkmarx Code Quality Warning












1















After running a Checkmarx scan it returned a code quality warning on a method due to Query: Bulkify Apex Methods Using Collections In Methods.



The method is very simple:



    @AuraEnabled
public static String saveDSAM(List<inscor__Data_Service_Account_Mapping__c> dsamList, List<inscor__Customer_Quote__c> cqList) {
Savepoint sp = database.setSavepoint();
try {
if (!Schema.sObjectType.inscor__Data_Service_Account_Mapping__c.isCreateable() ||
!Schema.sObjectType.inscor__Customer_Quote__c.isUpdateable()) {
throw new NoAccessException();
}
insert dsamList;
update cqList;
return 'SUCCESS';
} catch (Exception ex) {
Database.rollback(sp);
system.debug('-Exception-'+ex+'-'+ex.getStackTraceString());
return 'Error~'+ex.getMessage();
}
}


It is passed a list of two sObjects and updates, inserts one list and updates another. The line number the scan returns is when the cqList is updated.



Object: cqlist in file: classes/quote360Controller.cls
L 555: public static String saveDSAM(List<inscor__Data_Service_Account_Mapping__c> dsamList, List<inscor__Customer_Quote__c> cqList) {
Object: cqlist in file: classes/quote360Controller.cls
L 563: update cqList;


I thought by modifying the method parameters to be lists that it would resolve this issue. This method is called by a lightning component and is never call in iteration. Any thoughts?










share|improve this question



























    1















    After running a Checkmarx scan it returned a code quality warning on a method due to Query: Bulkify Apex Methods Using Collections In Methods.



    The method is very simple:



        @AuraEnabled
    public static String saveDSAM(List<inscor__Data_Service_Account_Mapping__c> dsamList, List<inscor__Customer_Quote__c> cqList) {
    Savepoint sp = database.setSavepoint();
    try {
    if (!Schema.sObjectType.inscor__Data_Service_Account_Mapping__c.isCreateable() ||
    !Schema.sObjectType.inscor__Customer_Quote__c.isUpdateable()) {
    throw new NoAccessException();
    }
    insert dsamList;
    update cqList;
    return 'SUCCESS';
    } catch (Exception ex) {
    Database.rollback(sp);
    system.debug('-Exception-'+ex+'-'+ex.getStackTraceString());
    return 'Error~'+ex.getMessage();
    }
    }


    It is passed a list of two sObjects and updates, inserts one list and updates another. The line number the scan returns is when the cqList is updated.



    Object: cqlist in file: classes/quote360Controller.cls
    L 555: public static String saveDSAM(List<inscor__Data_Service_Account_Mapping__c> dsamList, List<inscor__Customer_Quote__c> cqList) {
    Object: cqlist in file: classes/quote360Controller.cls
    L 563: update cqList;


    I thought by modifying the method parameters to be lists that it would resolve this issue. This method is called by a lightning component and is never call in iteration. Any thoughts?










    share|improve this question

























      1












      1








      1








      After running a Checkmarx scan it returned a code quality warning on a method due to Query: Bulkify Apex Methods Using Collections In Methods.



      The method is very simple:



          @AuraEnabled
      public static String saveDSAM(List<inscor__Data_Service_Account_Mapping__c> dsamList, List<inscor__Customer_Quote__c> cqList) {
      Savepoint sp = database.setSavepoint();
      try {
      if (!Schema.sObjectType.inscor__Data_Service_Account_Mapping__c.isCreateable() ||
      !Schema.sObjectType.inscor__Customer_Quote__c.isUpdateable()) {
      throw new NoAccessException();
      }
      insert dsamList;
      update cqList;
      return 'SUCCESS';
      } catch (Exception ex) {
      Database.rollback(sp);
      system.debug('-Exception-'+ex+'-'+ex.getStackTraceString());
      return 'Error~'+ex.getMessage();
      }
      }


      It is passed a list of two sObjects and updates, inserts one list and updates another. The line number the scan returns is when the cqList is updated.



      Object: cqlist in file: classes/quote360Controller.cls
      L 555: public static String saveDSAM(List<inscor__Data_Service_Account_Mapping__c> dsamList, List<inscor__Customer_Quote__c> cqList) {
      Object: cqlist in file: classes/quote360Controller.cls
      L 563: update cqList;


      I thought by modifying the method parameters to be lists that it would resolve this issue. This method is called by a lightning component and is never call in iteration. Any thoughts?










      share|improve this question














      After running a Checkmarx scan it returned a code quality warning on a method due to Query: Bulkify Apex Methods Using Collections In Methods.



      The method is very simple:



          @AuraEnabled
      public static String saveDSAM(List<inscor__Data_Service_Account_Mapping__c> dsamList, List<inscor__Customer_Quote__c> cqList) {
      Savepoint sp = database.setSavepoint();
      try {
      if (!Schema.sObjectType.inscor__Data_Service_Account_Mapping__c.isCreateable() ||
      !Schema.sObjectType.inscor__Customer_Quote__c.isUpdateable()) {
      throw new NoAccessException();
      }
      insert dsamList;
      update cqList;
      return 'SUCCESS';
      } catch (Exception ex) {
      Database.rollback(sp);
      system.debug('-Exception-'+ex+'-'+ex.getStackTraceString());
      return 'Error~'+ex.getMessage();
      }
      }


      It is passed a list of two sObjects and updates, inserts one list and updates another. The line number the scan returns is when the cqList is updated.



      Object: cqlist in file: classes/quote360Controller.cls
      L 555: public static String saveDSAM(List<inscor__Data_Service_Account_Mapping__c> dsamList, List<inscor__Customer_Quote__c> cqList) {
      Object: cqlist in file: classes/quote360Controller.cls
      L 563: update cqList;


      I thought by modifying the method parameters to be lists that it would resolve this issue. This method is called by a lightning component and is never call in iteration. Any thoughts?







      apex bulkification checkmarx






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 9 hours ago









      Zack WaltonZack Walton

      642314




      642314






















          1 Answer
          1






          active

          oldest

          votes


















          4














          This is almost certainly a false positive, although it may simply be complaining since your code does not explicitly handle the case where dsamList throws an error. I would advise simply ignoring this warning, or possibly reaching out to Checkmarx Support directly to find out why this error would have been generated. The only change I would recommend is to use the appropriate use of AuraHandledException:



          @AuraEnabled
          public static void saveDSAM(List<inscor__Data_Service_Account_Mapping__c> dsamList, List<inscor__Customer_Quote__c> cqList) {
          try {
          if (!Schema.sObjectType.inscor__Data_Service_Account_Mapping__c.isCreateable() ||
          !Schema.sObjectType.inscor__Customer_Quote__c.isUpdateable()) {
          throw new AuraHandledException('You do not have permission to update these records.');
          }
          insert dsamList;
          update cqList;
          } catch (Exception ex) {
          throw new AuraHandledException('An error occurred: '+ex.getMessage());
          }
          }


          This removes the need to database.rollback on error, and will enable your code to use proper error handling on the client-side.






          share|improve this answer
























          • Thanks for the answer and the suggestions. There is a day where I will make the exception handling change but today is not that day :)

            – Zack Walton
            8 hours ago











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "459"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f249368%2fcheckmarx-code-quality-warning%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          4














          This is almost certainly a false positive, although it may simply be complaining since your code does not explicitly handle the case where dsamList throws an error. I would advise simply ignoring this warning, or possibly reaching out to Checkmarx Support directly to find out why this error would have been generated. The only change I would recommend is to use the appropriate use of AuraHandledException:



          @AuraEnabled
          public static void saveDSAM(List<inscor__Data_Service_Account_Mapping__c> dsamList, List<inscor__Customer_Quote__c> cqList) {
          try {
          if (!Schema.sObjectType.inscor__Data_Service_Account_Mapping__c.isCreateable() ||
          !Schema.sObjectType.inscor__Customer_Quote__c.isUpdateable()) {
          throw new AuraHandledException('You do not have permission to update these records.');
          }
          insert dsamList;
          update cqList;
          } catch (Exception ex) {
          throw new AuraHandledException('An error occurred: '+ex.getMessage());
          }
          }


          This removes the need to database.rollback on error, and will enable your code to use proper error handling on the client-side.






          share|improve this answer
























          • Thanks for the answer and the suggestions. There is a day where I will make the exception handling change but today is not that day :)

            – Zack Walton
            8 hours ago
















          4














          This is almost certainly a false positive, although it may simply be complaining since your code does not explicitly handle the case where dsamList throws an error. I would advise simply ignoring this warning, or possibly reaching out to Checkmarx Support directly to find out why this error would have been generated. The only change I would recommend is to use the appropriate use of AuraHandledException:



          @AuraEnabled
          public static void saveDSAM(List<inscor__Data_Service_Account_Mapping__c> dsamList, List<inscor__Customer_Quote__c> cqList) {
          try {
          if (!Schema.sObjectType.inscor__Data_Service_Account_Mapping__c.isCreateable() ||
          !Schema.sObjectType.inscor__Customer_Quote__c.isUpdateable()) {
          throw new AuraHandledException('You do not have permission to update these records.');
          }
          insert dsamList;
          update cqList;
          } catch (Exception ex) {
          throw new AuraHandledException('An error occurred: '+ex.getMessage());
          }
          }


          This removes the need to database.rollback on error, and will enable your code to use proper error handling on the client-side.






          share|improve this answer
























          • Thanks for the answer and the suggestions. There is a day where I will make the exception handling change but today is not that day :)

            – Zack Walton
            8 hours ago














          4












          4








          4







          This is almost certainly a false positive, although it may simply be complaining since your code does not explicitly handle the case where dsamList throws an error. I would advise simply ignoring this warning, or possibly reaching out to Checkmarx Support directly to find out why this error would have been generated. The only change I would recommend is to use the appropriate use of AuraHandledException:



          @AuraEnabled
          public static void saveDSAM(List<inscor__Data_Service_Account_Mapping__c> dsamList, List<inscor__Customer_Quote__c> cqList) {
          try {
          if (!Schema.sObjectType.inscor__Data_Service_Account_Mapping__c.isCreateable() ||
          !Schema.sObjectType.inscor__Customer_Quote__c.isUpdateable()) {
          throw new AuraHandledException('You do not have permission to update these records.');
          }
          insert dsamList;
          update cqList;
          } catch (Exception ex) {
          throw new AuraHandledException('An error occurred: '+ex.getMessage());
          }
          }


          This removes the need to database.rollback on error, and will enable your code to use proper error handling on the client-side.






          share|improve this answer













          This is almost certainly a false positive, although it may simply be complaining since your code does not explicitly handle the case where dsamList throws an error. I would advise simply ignoring this warning, or possibly reaching out to Checkmarx Support directly to find out why this error would have been generated. The only change I would recommend is to use the appropriate use of AuraHandledException:



          @AuraEnabled
          public static void saveDSAM(List<inscor__Data_Service_Account_Mapping__c> dsamList, List<inscor__Customer_Quote__c> cqList) {
          try {
          if (!Schema.sObjectType.inscor__Data_Service_Account_Mapping__c.isCreateable() ||
          !Schema.sObjectType.inscor__Customer_Quote__c.isUpdateable()) {
          throw new AuraHandledException('You do not have permission to update these records.');
          }
          insert dsamList;
          update cqList;
          } catch (Exception ex) {
          throw new AuraHandledException('An error occurred: '+ex.getMessage());
          }
          }


          This removes the need to database.rollback on error, and will enable your code to use proper error handling on the client-side.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 8 hours ago









          sfdcfoxsfdcfox

          254k11196436




          254k11196436













          • Thanks for the answer and the suggestions. There is a day where I will make the exception handling change but today is not that day :)

            – Zack Walton
            8 hours ago



















          • Thanks for the answer and the suggestions. There is a day where I will make the exception handling change but today is not that day :)

            – Zack Walton
            8 hours ago

















          Thanks for the answer and the suggestions. There is a day where I will make the exception handling change but today is not that day :)

          – Zack Walton
          8 hours ago





          Thanks for the answer and the suggestions. There is a day where I will make the exception handling change but today is not that day :)

          – Zack Walton
          8 hours ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Salesforce Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f249368%2fcheckmarx-code-quality-warning%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Polycentropodidae

          Magento 2 Error message: Invalid state change requested

          Paulmy