Checkmarx Code Quality Warning
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
add a comment |
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
add a comment |
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
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
apex bulkification checkmarx
asked 9 hours ago
Zack WaltonZack Walton
642314
642314
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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