You need to sign in to do that
Don't have an account?

Chckmarx Issue : Bulkify apex methods using collections In methods
Hi,
i having some problem in salesforce checkmarx report. this generated one waring : Bulkify_Apex_Methods_Using_Collections_In_Methods in particular code
interested_prop = String.escapeSingleQuotes(interested_prop);
String qry = 'select ' + sObjectUtility.sObjectFields('srex__Matches__c') +' Id from Matches__c';
string whereString = ' where Interested_in_Dealing__c = false';
whereString += ' AND ('+ sObjName + ' =: propid ';
whereString += ' OR '+ lookup2 +' =: propid )';
whereString += ' AND ('+ sObjName + ' =: interested_prop ';
whereString += ' OR '+ lookup2 +' =: interested_prop )';
list<Matches__c> matches = Database.query(String.escapeSingleQuotes(qry)+String.escapeSingleQuotes(whereString));
if(matches.size() > 0){
matches[0].Interested_in_Dealing__c = true;
try{
update matches;
}catch(Exception ex){
system.debug('Error occurred while perfoming DML Operation :::::'+ ex.getMessage());
}
}else{
Matches__c new_match = new Matches__c();
new_match.put(sObjName, prop_id);
new_match.put(lookup2 , interested_prop);
new_match.Interested_in_Dealing__c = true;
try{
List<Matches__c> matchlst =
new List<Matches__c>();
matchlst.add(new_match);
insert matchlst;
}catch(Exception ex){
system.debug('Error occurred while perfoming DML Operation :::::'+ ex.getMessage());
}
}
pls help me out
i having some problem in salesforce checkmarx report. this generated one waring : Bulkify_Apex_Methods_Using_Collections_In_Methods in particular code
interested_prop = String.escapeSingleQuotes(interested_prop);
String qry = 'select ' + sObjectUtility.sObjectFields('srex__Matches__c') +' Id from Matches__c';
string whereString = ' where Interested_in_Dealing__c = false';
whereString += ' AND ('+ sObjName + ' =: propid ';
whereString += ' OR '+ lookup2 +' =: propid )';
whereString += ' AND ('+ sObjName + ' =: interested_prop ';
whereString += ' OR '+ lookup2 +' =: interested_prop )';
list<Matches__c> matches = Database.query(String.escapeSingleQuotes(qry)+String.escapeSingleQuotes(whereString));
if(matches.size() > 0){
matches[0].Interested_in_Dealing__c = true;
try{
update matches;
}catch(Exception ex){
system.debug('Error occurred while perfoming DML Operation :::::'+ ex.getMessage());
}
}else{
Matches__c new_match = new Matches__c();
new_match.put(sObjName, prop_id);
new_match.put(lookup2 , interested_prop);
new_match.Interested_in_Dealing__c = true;
try{
List<Matches__c> matchlst =
new List<Matches__c>();
matchlst.add(new_match);
insert matchlst;
}catch(Exception ex){
system.debug('Error occurred while perfoming DML Operation :::::'+ ex.getMessage());
}
}
pls help me out
This will set Interested_in_Dealing__c to true for every match, and if there are no matches create a new one. The upsert the entire list.
NOTE: This code has not been tested and may contain typographical or logical errors
Query: Bulkify Apex Methods Using Collections In Methods ... I have no idea what's wrong here
thanks in advance
The problem isn't specifically this method. What is probably happening is that youare calling this method from inside a loop
I also don' t know why you have this method (or at least the the if statement). You can say
With that being said, I would recommend that you change this to take in a List and upsert that list instead of taking in a single sObject. However, without seeing the method / trigger that calls this (and any higher level methods / triggers) I cannot say why checkmarx is flagging that code.