1

enter image description here enter image description here

When I add new pricing by clicking 'new' button in pricing section,

activities and purchases information also add to the list below.

Right now, when I save new pricing, pricing list updates instantly,

but I have to refresh the page manually to update activities and purchases list.

What would be the best way to update all three lists instantly when I save new pricing?

here is the trigger

trigger PricingTrigger on Pricing__c (after insert, after update, before delete) {


if (Trigger.isBefore) {
    if(Trigger.isDelete){
        PricingTriggerHandler.handleBeforeDelete(Trigger.old);      
    }
}
else {
    //Add
    if (Trigger.isInsert) {
        PricingTriggerHandler.handleAfterInsert(Trigger.new);      
    }
    //Update
    else if (Trigger.isUpdate){
        PricingTriggerHandler.handleAfterUpdate(Trigger.old, Trigger.new);    
    }
}

}

Here is the part of the trigger controller class

 public static void handleAfterInsert(List<Pricing__c> pricings) {
    List<Id> pricingIds = new List<Id>();
    for(Pricing__c pricing : pricings){
        // Only if record is submitted
        if ( pricing.Trigger_Enabled__c == true ){            
            pricingIds.add(pricing.Id);
        }

    }
    addActivitiesPurchasesAndTotalPrice(pricingIds);
}

public static void handleAfterUpdate(List<Pricing__c> oldPricings, List<Pricing__c> newPricings) {
    updateActivitiesPurchasesAndTotalPrice(oldPricings, newPricings);
}

public static void handleBeforeDelete(List<Pricing__c> pricings) {
    deleteActivitiesPurchasesAndTotalPrice(pricings);
}


    public static void addActivitiesPurchasesAndTotalPrice(List<Id> pricingIds) {

    for(Id pricingId : pricingIds){
        //Retrieve Pricing and Reservation
        Pricing__c newPricing = [SELECT Id, Name, Item__c, Pricing_Lookup__c, Quantity__c, Reservation__c, Subtotal__c, Unit_Price__c, Package_Unit_Price__c FROM Pricing__c WHERE Id = : pricingId];
        newPricing.Package_Unit_Price__c = newPricing.Unit_Price__c;
        update newPricing;

        Id reservationId = newPricing.Reservation__c;

        //Reservation that will be updated
        Reservation__c reservation = [SELECT Id, Name, Arrival_Date__c, Departure_Date__c, Date_Received__c FROM Reservation__c where Id =: reservationId];    
        String priceLookupId = newPricing.Pricing_Lookup__c;
        update reservation;

        Pricing_Lookup__c priceLookup = [SELECT Id, Name FROM Pricing_Lookup__c WHERE Id = : priceLookupId ];

        //Add Activities and Purchases
        addActivityAndPurchasesByPricingLookupId(newPricing, pricingId, reservationId, reservation.Arrival_Date__c, priceLookupId);

        //Update Total
        List<Pricing__c> reservationPricingList = [SELECT Id, Name, Item__c, Pricing_Lookup__c, Quantity__c, Reservation__c, Subtotal__c, Unit_Price__c, Package_Unit_Price__c FROM Pricing__c WHERE Reservation__c = : reservation.Id];
        updateReservationTotalByReservationAndPricings(reservation, reservationPricingList);
    }
}

addActivityAndPurchasesByPricingLookupId inserts activity and purchase list....

thank you guys

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.