Skip to main content
formatted code, fixed some spelling/grammar issues to appease the 6 char limit
Source Link

The below code can be executed in Anonymous window.I I have seen this code working before.

I am expecting qProdList to return exact number of records that i pass in the set "st".I am passing 18 items in st. ButBut the number of product records returnreturned by qProdList is always 10 records.

I have verified all these 18 items in the database, and all are present. only post iI am applying string operation itit results in 10 items.

Please advice what could be the reason string operation is behaving inconsitentinconsistent in apex  ?

 set<string> st = new set<String>{'A,'B','C','D','E','F','G,'S,'Q','N','M','Y','O','P,'J,'K,'I','H'H'};

system.debug('st : ' + st.size() + '--' + st);

string b = string.valueof(st).split('[{}]')[1];

system.debug('b : ' + b);

string qProd = 'select isActive,ProductCode from Product2 where isActive = true and  ProductCode IN (\''+ b.replaceAll('\\, ','\',\'')+'\')'; 

system.debug('qProd : + ' + qProd); 

 list<Product2> qProdList = Database.query(qProd); 
             
system.debug(' --  qProdList  -- : ' + qProdList.size()); 

system.debug(' -- qProdList -- : ' + qProdList.size());

The below code can be executed in Anonymous window.I have seen this code working before.

I am expecting qProdList to return exact number of records that i pass in the set "st".I am passing 18 items in st. But the number of product records return by qProdList is always 10 records.

I have verified all these 18 items in the database, and all are present. only post i am applying string operation it results in 10 items.

Please advice what could be the reason string operation is behaving inconsitent in apex  ?

 set<string> st = new set<String>{'A,'B','C','D','E','F','G,'S,'Q','N','M','Y','O','P,'J,'K,'I','H};

system.debug('st : ' + st.size() + '--' + st);

string b = string.valueof(st).split('[{}]')[1];

system.debug('b : ' + b);

string qProd = 'select isActive,ProductCode from Product2 where isActive = true and  ProductCode IN (\''+ b.replaceAll('\\, ','\',\'')+'\')';

system.debug('qProd : + ' + qProd);

 list<Product2> qProdList = Database.query(qProd);
             

system.debug(' -- qProdList -- : ' + qProdList.size());

The below code can be executed in Anonymous window. I have seen this code working before.

I am expecting qProdList to return exact number of records that i pass in the set "st".I am passing 18 items in st. But the number of product records returned by qProdList is always 10 records.

I have verified all these 18 items in the database, and all are present. only post I am applying string operation it results in 10 items.

Please advice what could be the reason string operation is behaving inconsistent in apex?

set<string> st = new set<String>{'A,'B','C','D','E','F','G,'S,'Q','N','M','Y','O','P,'J,'K,'I','H'};

system.debug('st : ' + st.size() + '--' + st);

string b = string.valueof(st).split('[{}]')[1];

system.debug('b : ' + b);

string qProd = 'select isActive,ProductCode from Product2 where isActive = true and  ProductCode IN (\''+ b.replaceAll('\\, ','\',\'')+'\')'; 

system.debug('qProd : + ' + qProd); 

list<Product2> qProdList = Database.query(qProd); 
             
system.debug(' --  qProdList  -- : ' + qProdList.size()); 
Source Link
user10727
  • 585
  • 11
  • 27

Why the split operation in Apex behaves different than Java

The below code can be executed in Anonymous window.I have seen this code working before.

I am expecting qProdList to return exact number of records that i pass in the set "st".I am passing 18 items in st. But the number of product records return by qProdList is always 10 records.

I have verified all these 18 items in the database, and all are present. only post i am applying string operation it results in 10 items.

Please advice what could be the reason string operation is behaving inconsitent in apex ?

 set<string> st = new set<String>{'A,'B','C','D','E','F','G,'S,'Q','N','M','Y','O','P,'J,'K,'I','H};

system.debug('st : ' + st.size() + '--' + st);

string b = string.valueof(st).split('[{}]')[1];

system.debug('b : ' + b);

string qProd = 'select isActive,ProductCode from Product2 where isActive = true and  ProductCode IN (\''+ b.replaceAll('\\, ','\',\'')+'\')';

system.debug('qProd : + ' + qProd);

 list<Product2> qProdList = Database.query(qProd);
             

system.debug(' -- qProdList -- : ' + qProdList.size());