Guest User

Untitled

a guest
Jun 22nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. Apex Trigger :
  2.  
  3. trigger Quote_Trigger on Quote (before insert,before update) {
  4. if((Trigger.isInsert || Trigger.isUpdate) && Trigger.isBefore){
  5. QuoteTriggerHandler.handlebeforeInsert(Trigger.New);
  6. }
  7. }
  8.  
  9. Trigger Helper class :
  10.  
  11. public class QuoteTriggerHandler{
  12. public static void handlebeforeInsert(List<Quote> listQuote){
  13. Map<String ,Id> salMap = new Map<String ,Id>();
  14. Set <String> city = new Set <String>();
  15. Set <String> state = new Set <String>();
  16. for(Quote quo : listQuote){
  17. city.add(quo.BillingCity);
  18. }
  19. for(Quote quo : listQuote){
  20. state.add(quo.BillingState);
  21. }
  22. List<Sales_Tax__c> saletax= [select Id,City__c,State__c from Sales_Tax__c where City__c IN:city AND State__c IN:state];
  23.  
  24. FOR(Sales_Tax__c SAL : saletax) {
  25. salMap.put(SAL.City__c+ '_' +SAL.State__c, SAL.Id);
  26. }
  27. for(Quote quo :listQuote) {
  28.  
  29. if((quo.BillingCity != null ||quo.BillingCity != '') && (quo.BillingState != null || quo.BillingState !='')) {
  30. if(salMap.containsKey(quo.BillingCity+ '_' +quo.BillingState))
  31. quo.SalesTax__c = salMap.get(quo.BillingCity+ '_' +quo.BillingState);
  32. }
  33. }
  34.  
  35.  
  36. }
  37. }
  38.  
  39. Thanks
  40. Ajay
Add Comment
Please, Sign In to add comment