• elen maoel
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
Hi Everyone,
Creating a contract for an amendment opportunity is correct or not ? Or any other way to execute it. (Cpq question ) plz, help with this one.
Thanks in Advance
The trigger automatically attaches pricebooks, when a produt get created. which pricebook it should attach depends upon the LOB

public class ProductTriggerHandler extends TriggerHandler{
    public ProductTriggerHandler() {
    }
    
    public override void afterUpdate() {
        System.debug('this is after update');
        
    }   
    
    public override void beforeUpdate() {
        
        
        
    }
    
    public override void beforeInsert() {
        
    }
    
    public override void afterInsert() {
        System.debug('this is after insert');
        createPricebookEntries((List<Product2>)Trigger.new);        
    }    
    
    public void createPricebookEntries(List<Product2> productList){
        
        List<PricebookEntry> peList = new List<PricebookEntry>();
        List<PricebookEntry> mpeList = new List<PricebookEntry>(); //For Modular Kitchen
        List<PricebookEntry> opeList = new List<PricebookEntry>(); // For All other LOB
        
       
        List<Pricebook2> pricebookIds = [Select id,Site_Code__c from Pricebook2 where Pricebook_Category__c ='FR']; // Fetches only Furniture Pricebook
        List<Pricebook2> MKpricebookIds = [Select id,Site_Code__c from Pricebook2 where Pricebook_Category__c ='MK' OR IsStandard = TRUE]; // Fethches only MK Pricebook and Standard Pricebook
        List<Pricebook2> opricebookIds = [Select id,Site_Code__c from Pricebook2 where IsStandard = TRUE]; // Fetches only Standard Pricebook
           
   
 // Attaching Standard Pricebook and Furniture Pricebooks when LOB is Furniture, Home Improvement , Home Improvements
        
        if(pricebookIds.size() > 0){
            for(Product2 prod: productList){
                System.debug('prod.LOB__c:'+prod.LOB__c);
                if(prod.LOB__c!=null && Label.FR_Pricebook.contains(prod.LOB__c)){
                    for(Pricebook2 pb2 : pricebookIds){
                        PricebookEntry pe = new PricebookEntry();
                        pe.UnitPrice = 1;
                        pe.Pricebook2Id = pb2.id;
                        pe.Product2Id = prod.id;
                        peList.add(pe);
                    }
                    
                }
            }
            
         
            
            
            if(peList.size()>0){
                insert peList;
                System.debug('id:'+peList[0].id);
            }
        }
        
 // Attaches Standard pricebook to all products whose LOB is not Furniture, Modular Kitchen, Mk , Home Improvement,Home Improvements       
      
      if(opricebookIds.size() > 0){
            for(Product2 prod: productList){
                System.debug('prod.LOB__c:'+prod.LOB__c);
if(prod.LOB__c!=null && Label.Other_Pricebooks.contains(prod.LOB__c)){
                    for(Pricebook2 opb2 : opricebookIds){
                        PricebookEntry ope = new PricebookEntry();
                        ope.UnitPrice = 1;
                        ope.Pricebook2Id = opb2.id;
                        ope.Product2Id = prod.id;
                        opeList.add(ope);
                    }
                    
                }
            }
            
         
            
            
            if(opeList.size()>0){
                insert opeList;
                System.debug('id:'+opeList[0].id);
            }
        }
        
        
        
// Attaching Standard Pricebook and Modular Kitchen Pricebook when LOB is Modular Kitchen or MK    
        
           if(MKpricebookIds.size() > 0){
            for(Product2 prod: productList){
                System.debug('prod.LOB__c:'+prod.LOB__c);
                if(prod.LOB__c == 'Modular Kitchen' || prod.LOB__c == 'MK'){
                    for(Pricebook2 mpb2 : mkpricebookIds){
                        PricebookEntry mpe = new PricebookEntry();
                        mpe.UnitPrice = 1;
                        mpe.Pricebook2Id = mpb2.id;
                        mpe.Product2Id = prod.id;
                        mpeList.add(mpe);
                    }
                    
                }
            }
            
         
            
            
            if(mpeList.size()>0){
                insert mpeList;
                System.debug('id:'+mpeList[0].id);
            }
        }
    }
    
}
Ciao, guys. I'm thinking that I'd start Android open-source project focusing on Salesforce using Apex API. Android is based on Java application, so I've writing my app in Java JDK6.

I succeeded in connecting to salesforce thru SOAP base web serivce so far. Now I'm cleaning up my source code and then am ready for starting source code on...google code or so.  I'm writing serveral articles about my salesforce android on http://lg3d.blogspot.com/

When I post my code, I'll add a comment to this thread again so please join in if you're interested in it..

Grazie so much,