You need to sign in to do that
Don't have an account?
Vishnu7700
Apex CPU Time out Exception
Hi,
While checking the product duplicate i'm faceing Apex CPU Time out limit Exception.Here is the code
public list<BD_Identifier__c> LegacyproductBDlistinputcheck(list<BD_Identifier__c> bdlist)//bdllist contains list of products
{
set<string> dupcodeinput = new set<string>();
system.debug('Class duplicate count:'+bdlist.size());//Size was 456 records
for(BD_Identifier__c b: bdlist)
{
system.debug('Class duplicate:'+dupcodeinput.size());
if (dupcodeinput.size()>0)
{
while (dupcodeinput.contains(b.SPM_BrokerDealer__C+b.SPM_Legacy_Product_Code__c))//After processing 64 records time out error was shown
{
if(b.SPM_BrokerDealer__c=='FSC')
{
string code =b.SPM_Legacy_Product_Code__c.right(1);
string productcode= b.SPM_Legacy_Product_Code__c;
if(code.isNumeric())
{
Integer i;
if(b.SPM_Legacy_Product_Code__c.right(2).isNumeric())
{
string s=b.SPM_Legacy_Product_Code__c.right(2);
Integer c,d;
c=Integer.valueOf(s.right(1));
d=Integer.valueOf(s.left(1));
if(d==c-1){
code=b.SPM_Legacy_Product_Code__c.right(1);
}
else{code=b.SPM_Legacy_Product_Code__c.right(2);}
}
i=Integer.valueOf(code)+1;
b.SPM_Legacy_Product_Code__c=((productcode+String.valueOf(i)).right(7));
}
else
{
b.SPM_Legacy_Product_Code__c=((productcode+String.valueOf(1)).right(7));
}
}
else if (b.SPM_BrokerDealer__c=='RAA' || b.SPM_BrokerDealer__c=='SPF' || b.SPM_BrokerDealer__c=='WFS')
{
string code =b.SPM_Legacy_Product_Code__c.right(1);
string productcode= b.SPM_Legacy_Product_Code__c;
if(code.isNumeric())
{
Integer i;
if(b.SPM_Legacy_Product_Code__c.right(2).isNumeric())
{
string s=b.SPM_Legacy_Product_Code__c.right(2);
integer c,d;
c=Integer.valueOf(s.right(1));
d=Integer.valueOf(s.left(1));
if(d==c-1){
code=b.SPM_Legacy_Product_Code__c.right(1);
}
else{code=b.SPM_Legacy_Product_Code__c.right(2);}
}
i=Integer.valueOf(code)+1;
b.SPM_Legacy_Product_Code__c=(b.SPM_Legacy_Sponsor_Code__c +(productcode+String.valueOf(i)).right(6));
}
else
{
b.SPM_Legacy_Product_Code__c=(b.SPM_Legacy_Sponsor_Code__c +(productcode+String.valueOf(1)).right(6));
}
}
}
dupcodeinput.add(b.SPM_BrokerDealer__C+b.SPM_Legacy_Product_Code__c);
}
else {dupcodeinput.add(b.SPM_BrokerDealer__C+b.SPM_Legacy_Product_Code__c);}
}
//system.debug('class remove duplicate'+bdlist);
return bdlist;
}
While checking the product duplicate i'm faceing Apex CPU Time out limit Exception.Here is the code
public list<BD_Identifier__c> LegacyproductBDlistinputcheck(list<BD_Identifier__c> bdlist)//bdllist contains list of products
{
set<string> dupcodeinput = new set<string>();
system.debug('Class duplicate count:'+bdlist.size());//Size was 456 records
for(BD_Identifier__c b: bdlist)
{
system.debug('Class duplicate:'+dupcodeinput.size());
if (dupcodeinput.size()>0)
{
while (dupcodeinput.contains(b.SPM_BrokerDealer__C+b.SPM_Legacy_Product_Code__c))//After processing 64 records time out error was shown
{
if(b.SPM_BrokerDealer__c=='FSC')
{
string code =b.SPM_Legacy_Product_Code__c.right(1);
string productcode= b.SPM_Legacy_Product_Code__c;
if(code.isNumeric())
{
Integer i;
if(b.SPM_Legacy_Product_Code__c.right(2).isNumeric())
{
string s=b.SPM_Legacy_Product_Code__c.right(2);
Integer c,d;
c=Integer.valueOf(s.right(1));
d=Integer.valueOf(s.left(1));
if(d==c-1){
code=b.SPM_Legacy_Product_Code__c.right(1);
}
else{code=b.SPM_Legacy_Product_Code__c.right(2);}
}
i=Integer.valueOf(code)+1;
b.SPM_Legacy_Product_Code__c=((productcode+String.valueOf(i)).right(7));
}
else
{
b.SPM_Legacy_Product_Code__c=((productcode+String.valueOf(1)).right(7));
}
}
else if (b.SPM_BrokerDealer__c=='RAA' || b.SPM_BrokerDealer__c=='SPF' || b.SPM_BrokerDealer__c=='WFS')
{
string code =b.SPM_Legacy_Product_Code__c.right(1);
string productcode= b.SPM_Legacy_Product_Code__c;
if(code.isNumeric())
{
Integer i;
if(b.SPM_Legacy_Product_Code__c.right(2).isNumeric())
{
string s=b.SPM_Legacy_Product_Code__c.right(2);
integer c,d;
c=Integer.valueOf(s.right(1));
d=Integer.valueOf(s.left(1));
if(d==c-1){
code=b.SPM_Legacy_Product_Code__c.right(1);
}
else{code=b.SPM_Legacy_Product_Code__c.right(2);}
}
i=Integer.valueOf(code)+1;
b.SPM_Legacy_Product_Code__c=(b.SPM_Legacy_Sponsor_Code__c +(productcode+String.valueOf(i)).right(6));
}
else
{
b.SPM_Legacy_Product_Code__c=(b.SPM_Legacy_Sponsor_Code__c +(productcode+String.valueOf(1)).right(6));
}
}
}
dupcodeinput.add(b.SPM_BrokerDealer__C+b.SPM_Legacy_Product_Code__c);
}
else {dupcodeinput.add(b.SPM_BrokerDealer__C+b.SPM_Legacy_Product_Code__c);}
}
//system.debug('class remove duplicate'+bdlist);
return bdlist;
}
Record processed are 500 to 1000
while (dupcodeinput.contains(b.SPM_BrokerDealer__C+b.SPM_Legacy_Product_Code__c))