You need to sign in to do that
Don't have an account?
mahesh1.396434879374128E12
System.LimitException: Apex CPU time limit exceeded
When i am tring to bulkify this trigger i am getting this error:
When a new case is created, the externalId value is equal to Product external Id. Th product id value shoul map to the Product__c Custom field in case.
The code:
trigger CreateReqMapProdId on Case (Before Insert)
{
list<string> lstExteralId = New list<string>();
if(trigger.isInsert)
{
for(Case ca : trigger.new)
{
lstExteralId.add(ca.ProductExteralId__c);
}
Map<Id, Product2> ProdMap = new Map<Id, Product2>([select id,PSCSID__c from Product2]);
for(Case ca : trigger.new)
{
for(Product2 prod : ProdMap.values())
{
If(ca.ProductExteralId__c != null)
{
If(ca.ProductExteralId__c == Prod.PSCSID__c)
{
ca.Product__c = Prod.Id ;
}
}
}
}
}}
Please help me.
When a new case is created, the externalId value is equal to Product external Id. Th product id value shoul map to the Product__c Custom field in case.
The code:
trigger CreateReqMapProdId on Case (Before Insert)
{
list<string> lstExteralId = New list<string>();
if(trigger.isInsert)
{
for(Case ca : trigger.new)
{
lstExteralId.add(ca.ProductExteralId__c);
}
Map<Id, Product2> ProdMap = new Map<Id, Product2>([select id,PSCSID__c from Product2]);
for(Case ca : trigger.new)
{
for(Product2 prod : ProdMap.values())
{
If(ca.ProductExteralId__c != null)
{
If(ca.ProductExteralId__c == Prod.PSCSID__c)
{
ca.Product__c = Prod.Id ;
}
}
}
}
}}
Please help me.
trigger CreateReqMapProdId on Case (Before Insert)
{
if(trigger.isInsert)
{
List<Product2> ProdMap = [select id,PSCSID__c from Product2 Where PSCSID__c!=null];
for(Case ca : trigger.new)
{
If(ca.ProductExteralId__c != null)
{
for(i=0;i<ProdMap.size();i++)
{
If(ca.ProductExteralId__c == ProdMap[i].PSCSID__c)
{
ca.Product__c = ProdMap[i].Id ;
}
}
}
}
}
}
too many Product records are iterating when i am using to get the data which is having ProductExteralId__c == PSCSID__c matching values.
I have used this code.
It is also throwing the same error .
Please help in bulkfying the above code.
and try
This is my latest Code:
trigger CreateReqMapProdId on Case (Before Insert)
{
list<string> lstExteralId = New list<string>();
if(trigger.isInsert)
{
for(Case ca : trigger.new)
{
lstExteralId.add(ca.ProductExteralId__c);
}
Map<string, Product2> ProdMap = new Map<string, Product2>();
list<Product2> Prodlst =[select id,PSCSID__C from product2 where PSCSID__C IN:lstExteralId];
for(Product2 p :Prodlst)
{
ProdMap.put(p.PSCSID__C,p);
}
for(Case ca : trigger.new)
{
If(ca.ProductExteralId__c != null)
{
ca.Product__c = (ProdMap.get(ca.ProductExteralId__c)).id ;
}
}
}
}
I am facing the above Error . when i am inserting the records above 100 (Governor limits).
This is my latest Code:
trigger CreateReqMapProdId on Case (Before Insert)
{
list<string> lstExteralId = New list<string>();
if(trigger.isInsert)
{
for(Case ca : trigger.new)
{
lstExteralId.add(ca.ProductExteralId__c);
}
Map<string, Product2> ProdMap = new Map<string, Product2>();
list<Product2> Prodlst =[select id,PSCSID__C from product2 where PSCSID__C IN:lstExteralId];
for(Product2 p :Prodlst)
{
ProdMap.put(p.PSCSID__C,p);
}
for(Case ca : trigger.new)
{
If(ca.ProductExteralId__c != null)
{
ca.Product__c = (ProdMap.get(ca.ProductExteralId__c)).id ;
}
}
}
}
I am facing the above Error . when i am inserting the records above 100 (Governor limits).
trigger CreateReqMapProdId on Case (Before Insert)
{
Set<id> lstExteralId = New set<id>();
for(Case ca : trigger.new)
{
lstExteralId.add(ca.ProductExteralId__c);
}
Map<id,Product2> ProdMap = new Map<id, Product2>([select id,PSCSID__C from product2 where PSCSID__C IN:lstExteralId]);
for(Case ca : trigger.new)
{
If(ca.ProductExteralId__c != null)
{
Product2 p = ProdMap.get(ca.ProductExteralId__c);
If(p.PSCSID__C!=null)
{
ca.Product__c = p.PSCSID__C ;
}
}
}
}