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

Bulify the code
Hi,
Below trigger is working fine on a single transaction can we change this code to handle bulk load logic. Please suggest me
Sam
Below trigger is working fine on a single transaction can we change this code to handle bulk load logic. Please suggest me
Trigger convertToUSD on Opportunity (before update){ Try { List<String> oppiso = new List<String>(); List<date> cdate = new List<date>(); for(Opportunity o : trigger.new) { oppiso.add(o.CurrencyIsoCode); cdate.add(o.closedate); } Double cts = [SELECT ConversionRate FROM DatedConversionRate where isocode IN :oppiso and startdate <= :cdate order by startdate desc limit 1].conversionRate; for(Opportunity ops : trigger.new) { ops.CURRENCY_RATE__c = cts; } } catch (Exception e) { system.debug(e); for(Opportunity ops : trigger.new) { ops.CURRENCY_RATE__c = null; } } }Thanks
Sam
1) Try to use set to avoid duplicate values
2) Always try to fatch only related record in SOQL with "Where".
3) Use Map to avoid multipe SOQL
4) Alway use containsKey method before getting any value from MAP
Update your code like below
Let us know if this will help you
All Answers
1) Try to use set to avoid duplicate values
2) Always try to fatch only related record in SOQL with "Where".
3) Use Map to avoid multipe SOQL
4) Alway use containsKey method before getting any value from MAP
Update your code like below
Let us know if this will help you