• parth sachi 7
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
The requirement is to fire trigger in case of record update, but do not want to update record in-case of mass update i.e. bulk update via data loader. 
Even i changes name field ,update trigger is getting called and adding un-neccessary discount to price.Expected is that it should update only if brand is getting change.How can i remove this ?


trigger MobileShopeeDiscount on Mobile__c (before insert,before Update) {
    if(trigger.isInsert == true ){
        MobileShopeeDiscount.MobileShopeeDiscountFuncation(Trigger.new);
    }
       if(trigger.isUpdate == true){
       MobileShopeeDiscount.OldCustomerDiscountFuncation(Trigger.new);
    }

}

public class MobileShopeeDiscount {

    public static void MobileShopeeDiscountFuncation(list<mobile__c>VarList){
        for(mobile__c tempvar :VarList){
            if(tempvar.Brand__c == 'samsung'){
                tempvar.Price__c = tempvar.Price__c-(tempvar.Price__c *0.1);
                tempvar.DiscountStatus__c = 'Congrates !! You got 10% Discount';
            }else if(tempvar.Brand__c == 'Apple'){
                tempvar.Price__c = tempvar.Price__c-(tempvar.Price__c *0.2);
                tempvar.DiscountStatus__c = 'Congrates !! You got 20% Discount';
            }
        }
    }

public static void OldCustomerDiscountFuncation(list<mobile__c>VarList1){
        for(Mobile__c tempvar :VarList1 ){
            if(tempvar.Brand__c == 'samsung'){
                tempvar.Price__c = tempvar.Price__c-(tempvar.Price__c *0.05);
                tempvar.DiscountStatus__c = 'Congrates !! You got 5% Discount';
            }else if(tempvar.Brand__c == 'Apple'){
               // tempvar.Price__c = tempvar.Price__c-(tempvar.Price__c *0.2);
                tempvar.DiscountStatus__c = 'No Discount Applicable on this purchase';
            }
        }
        
    }


}
Even i changes name field ,update trigger is getting called and adding un-neccessary discount to price.Expected is that it should update only if brand is getting change.How can i remove this ?


trigger MobileShopeeDiscount on Mobile__c (before insert,before Update) {
    if(trigger.isInsert == true ){
        MobileShopeeDiscount.MobileShopeeDiscountFuncation(Trigger.new);
    }
       if(trigger.isUpdate == true){
       MobileShopeeDiscount.OldCustomerDiscountFuncation(Trigger.new);
    }

}

public class MobileShopeeDiscount {

    public static void MobileShopeeDiscountFuncation(list<mobile__c>VarList){
        for(mobile__c tempvar :VarList){
            if(tempvar.Brand__c == 'samsung'){
                tempvar.Price__c = tempvar.Price__c-(tempvar.Price__c *0.1);
                tempvar.DiscountStatus__c = 'Congrates !! You got 10% Discount';
            }else if(tempvar.Brand__c == 'Apple'){
                tempvar.Price__c = tempvar.Price__c-(tempvar.Price__c *0.2);
                tempvar.DiscountStatus__c = 'Congrates !! You got 20% Discount';
            }
        }
    }

public static void OldCustomerDiscountFuncation(list<mobile__c>VarList1){
        for(Mobile__c tempvar :VarList1 ){
            if(tempvar.Brand__c == 'samsung'){
                tempvar.Price__c = tempvar.Price__c-(tempvar.Price__c *0.05);
                tempvar.DiscountStatus__c = 'Congrates !! You got 5% Discount';
            }else if(tempvar.Brand__c == 'Apple'){
               // tempvar.Price__c = tempvar.Price__c-(tempvar.Price__c *0.2);
                tempvar.DiscountStatus__c = 'No Discount Applicable on this purchase';
            }
        }
        
    }


}