• Pams
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi All,
I have below requirement. Please help me. I have two custom object.
    object name: Temp_product__c
    fields:Status__c(Picklist- 'Calculate price', 'remove price', 'processed','Skipped  Update')
             Product_name__c(lookup to product)\
I am creating new records in this object(Temp_product__c) using trigger when ever a product is created or updated with status either 'Clculate price' or 'remove price'
object name: entry_disc__c
    fields: offer_code__c(text)
             product_classification__c(picklist: 'connect', 'bound', 'digital')
             tier1_disc__c
             tier2_disc__c
             tier3_disc__c
            
    object name: product2 (Standard object)
    fields:   offer_code__c(text)
                item_type__c(text)
                net_price__c(currency)
                tier1_price__c(currency)
                tier2_price__c(currency)
                tier3_price__c(currency)
I want to process Temp_product__c's records using batch class with a status of either ‘Calculate Price’ or ‘Remove Price’ After each record is processed the status would be updated to “Processed” to indicate the record has been processed and if the resulting product record was updated.
  • For those Temp_product__c records with a status of ‘Remove Price Tiers’, the corresponding Product record should be updated.  The fields: tier1_price__c, tier2_price__c, tier3_price__c, should all be set to null/blank.
  • For those Temp_product__c table records with a status of 'Calculate price' pricing values will be calculated based on entry_disc__c object. This object will store discount values for tier1_disc__c, tier2_disc__c,tier3_disc__c corresponding to each offer_code__c and Product Classification. Specific users will have access to this object and will be responsible for maintaining the data in it.
Product Classification on the Product record is determined based on below logic
    
    1. if(item_type__c==c)
          connect
    2. if(item_type__c ==b)
          bound
    3. if(item_type__c==d)
          digital

Once the classification is determined, then the pricing will be calculated on entry_disc__c table.
Use the sponsor code and the product classification from the previous step to lookup the discount percent for each tier in the enrty object.
  • If no record is found, then set each of the price tiers(tier1_price__c,tier2_price__c,tier3_price__c) to null/blank on the product
  • If a record is found, then calculate each of the pricing tiers
  1. If tier1_disc__c = null, then set the tier1_price__c to null/blank, otherwise calculate price as net_price__c * (1 – tier1_disc__c)
  2. If tier2_disc__c = null, then set the tier2_price__c to null/blank, otherwise calculate price as net_price__c * (1 – tier2_disc__c)
  3. If tier3_disc__c = null, then set the tier3_price__c to null/blank, otherwise calculate price as net_price__c * (1 – tier3_disc__c)
If the Calculated price tier for all the fields are matching with the existing price tier data then skip the update and change the status of the temp record as “Skipped  Update”, otherwise update the new price tier values on the Product and change the status of the temp record to “Processed”.
BELOW IS MY CODE:
global class CalculatePrice implements Database.Batchable<sObject>{ 
    
    global database.querylocator start(Database.BatchableContext BC){
        String strStatus1 = 'Calculate price';
        String strStatus2 = 'Remove price';
        String query='';
        query ='SELECT Id, Product_Name__r.offer_code__c Product_Name__r.item_type__c,Product_Name__r.net_price__c, Product_Name__r.tier1_price__c,Product_Name__r.tier2_price__c,Product_Name__r.tier3_price__c FROM Temp_product__c where status__c=:strStatus1 or status__c =: strStatus2';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<Temp_product__c> lstprod){
       list<entry_disc__c> entryRec = new list<entry_disc__c>();
       list<Temp_product__c> tempLst = new list<Temp_product__c> ();
       map<String,String> mappd = new map<String,String>();
       set<String> sponCode = new set<String>();
       String strProdClass ='Connect,Digital,Bound';
       
       if(lstprod.size() > 0){
            for(Temp_product__c p1 : lstprod){
                  entry_disc__c entryobj = new entry_disc__c();
                  if(p1.status__c=='Calculate price'){
                      if(p1.Product_Name__r.item_type__c=='c'){
                        entryobj.product_classification__c='Connect';  
                        entryRec.add(entryobj);
                      }
                   else if(p1.Product_Name__r.item_type__c=='d'){
                       entryobj.product_classification__c='digital';
                       entryRec.add(entryobj);
                   }
                   else if(p1.Product_Name__r.item_type__c=='b'){
                       entryobj.product_classification__c='Bound';
                       entryRec.add(entryobj);
                   }
                   else{}
                }
           }
            if(!entryRec.isEmpty())
            insert entryRec;
            
            for(Temp_product__c p2 : lstprod){
                
                sponCode.add(p2.Product_Name__r.offer_code__c);
                
            }
            
             for(entry_disc__c e : entryRec){
               if(sponCode.containsKey(e.offer_code__c) && (!string.isEmpty(e.product_classification__c) && strProdClass.contains(e.product_classification__c))){
                  }   
            }
        }
    }
    
    global void finish(Database.BatchableContext BC){

    }
}
I am not able to perform calculation on entry object. Please help me. Thank ypi in advance.

   
  • April 16, 2016
  • Like
  • 0
Hi All,
I have below requirement. Please help me. I have two custom object.
    object name: Temp_product__c
    fields:Status__c(Picklist- 'Calculate price', 'remove price', 'processed','Skipped  Update')
             Product_name__c(lookup to product)\
I am creating new records in this object(Temp_product__c) using trigger when ever a product is created or updated with status either 'Clculate price' or 'remove price'
object name: entry_disc__c
    fields: offer_code__c(text)
             product_classification__c(picklist: 'connect', 'bound', 'digital')
             tier1_disc__c
             tier2_disc__c
             tier3_disc__c
            
    object name: product2 (Standard object)
    fields:   offer_code__c(text)
                item_type__c(text)
                net_price__c(currency)
                tier1_price__c(currency)
                tier2_price__c(currency)
                tier3_price__c(currency)
I want to process Temp_product__c's records using batch class with a status of either ‘Calculate Price’ or ‘Remove Price’ After each record is processed the status would be updated to “Processed” to indicate the record has been processed and if the resulting product record was updated.
  • For those Temp_product__c records with a status of ‘Remove Price Tiers’, the corresponding Product record should be updated.  The fields: tier1_price__c, tier2_price__c, tier3_price__c, should all be set to null/blank.
  • For those Temp_product__c table records with a status of 'Calculate price' pricing values will be calculated based on entry_disc__c object. This object will store discount values for tier1_disc__c, tier2_disc__c,tier3_disc__c corresponding to each offer_code__c and Product Classification. Specific users will have access to this object and will be responsible for maintaining the data in it.
Product Classification on the Product record is determined based on below logic
    
    1. if(item_type__c==c)
          connect
    2. if(item_type__c ==b)
          bound
    3. if(item_type__c==d)
          digital

Once the classification is determined, then the pricing will be calculated on entry_disc__c table.
Use the sponsor code and the product classification from the previous step to lookup the discount percent for each tier in the enrty object.
  • If no record is found, then set each of the price tiers(tier1_price__c,tier2_price__c,tier3_price__c) to null/blank on the product
  • If a record is found, then calculate each of the pricing tiers
  1. If tier1_disc__c = null, then set the tier1_price__c to null/blank, otherwise calculate price as net_price__c * (1 – tier1_disc__c)
  2. If tier2_disc__c = null, then set the tier2_price__c to null/blank, otherwise calculate price as net_price__c * (1 – tier2_disc__c)
  3. If tier3_disc__c = null, then set the tier3_price__c to null/blank, otherwise calculate price as net_price__c * (1 – tier3_disc__c)
If the Calculated price tier for all the fields are matching with the existing price tier data then skip the update and change the status of the temp record as “Skipped  Update”, otherwise update the new price tier values on the Product and change the status of the temp record to “Processed”.
BELOW IS MY CODE:
global class CalculatePrice implements Database.Batchable<sObject>{ 
    
    global database.querylocator start(Database.BatchableContext BC){
        String strStatus1 = 'Calculate price';
        String strStatus2 = 'Remove price';
        String query='';
        query ='SELECT Id, Product_Name__r.offer_code__c Product_Name__r.item_type__c,Product_Name__r.net_price__c, Product_Name__r.tier1_price__c,Product_Name__r.tier2_price__c,Product_Name__r.tier3_price__c FROM Temp_product__c where status__c=:strStatus1 or status__c =: strStatus2';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<Temp_product__c> lstprod){
       list<entry_disc__c> entryRec = new list<entry_disc__c>();
       list<Temp_product__c> tempLst = new list<Temp_product__c> ();
       map<String,String> mappd = new map<String,String>();
       set<String> sponCode = new set<String>();
       String strProdClass ='Connect,Digital,Bound';
       
       if(lstprod.size() > 0){
            for(Temp_product__c p1 : lstprod){
                  entry_disc__c entryobj = new entry_disc__c();
                  if(p1.status__c=='Calculate price'){
                      if(p1.Product_Name__r.item_type__c=='c'){
                        entryobj.product_classification__c='Connect';  
                        entryRec.add(entryobj);
                      }
                   else if(p1.Product_Name__r.item_type__c=='d'){
                       entryobj.product_classification__c='digital';
                       entryRec.add(entryobj);
                   }
                   else if(p1.Product_Name__r.item_type__c=='b'){
                       entryobj.product_classification__c='Bound';
                       entryRec.add(entryobj);
                   }
                   else{}
                }
           }
            if(!entryRec.isEmpty())
            insert entryRec;
            
            for(Temp_product__c p2 : lstprod){
                
                sponCode.add(p2.Product_Name__r.offer_code__c);
                
            }
            
             for(entry_disc__c e : entryRec){
               if(sponCode.containsKey(e.offer_code__c) && (!string.isEmpty(e.product_classification__c) && strProdClass.contains(e.product_classification__c))){
                  }   
            }
        }
    }
    
    global void finish(Database.BatchableContext BC){

    }
}
I am not able to perform calculation on entry object. Please help me. Thank ypi in advance.

   
  • April 16, 2016
  • Like
  • 0