Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Apex Trigger :
- trigger Quote_Trigger on Quote (before insert,before update) {
- if((Trigger.isInsert || Trigger.isUpdate) && Trigger.isBefore){
- QuoteTriggerHandler.handlebeforeInsert(Trigger.New);
- }
- }
- Trigger Helper class :
- public class QuoteTriggerHandler{
- public static void handlebeforeInsert(List<Quote> listQuote){
- Map<String ,Id> salMap = new Map<String ,Id>();
- Set <String> city = new Set <String>();
- Set <String> state = new Set <String>();
- for(Quote quo : listQuote){
- city.add(quo.BillingCity);
- }
- for(Quote quo : listQuote){
- state.add(quo.BillingState);
- }
- 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];
- FOR(Sales_Tax__c SAL : saletax) {
- salMap.put(SAL.City__c+ '_' +SAL.State__c, SAL.Id);
- }
- for(Quote quo :listQuote) {
- if((quo.BillingCity != null ||quo.BillingCity != '') && (quo.BillingState != null || quo.BillingState !='')) {
- if(salMap.containsKey(quo.BillingCity+ '_' +quo.BillingState))
- quo.SalesTax__c = salMap.get(quo.BillingCity+ '_' +quo.BillingState);
- }
- }
- }
- }
- Thanks
- Ajay
Add Comment
Please, Sign In to add comment