• Del Santos
  • NEWBIE
  • 15 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 2
    Replies
Hi Guys!

Good day. I am creating a test method for a class i just created from a recycled apex code.
I have a requirement of updating the custom lookup field product__c in our opportunity object.
This field gets its value from the opportunity line item.  

I've created an apex class, got the code somewhere from the internet, i read and tried a lot, fortunately made it working for our requirement. :)
The problem is i been trying to make a test method for it but keeps failing. I am a new admin and do not know much about coding.

Can someone help me to make a test class please. :) TIA guys!

Heres my apex class:

public class UpdateOLIProdMgr {
    public static void updateOppProdMgr(OpportunityLineItem[] oppLineItems)
        {
            List<Opportunity> opps = new List<Opportunity>();
            List<Id> idPriceBookEntry = new List<Id>();
            List<Id> idProducts = new List<Id>();
            List<String> strFamily = new List<String>();
             

            for(OpportunityLineItem oppLineItem:oppLineItems)
            {
                idPriceBookEntry.add(oppLineItem.PricebookEntryId);             
            }   
            
            
            List<PricebookEntry> sObjPriceBookEntries = [Select Product2Id, Product2.Family, Product2.Name from PricebookEntry where Id in :idPriceBookEntry]; 
            for(PricebookEntry objPriceBookEntry:sObjPriceBookEntries)
            {
                idProducts.add(objPriceBookEntry.Product2Id);
                strFamily.add(objPriceBookEntry.Product2.Family);
            }
            
                        
                       
            if (sObjPriceBookEntries.size() > 0)
            {
                                 
                Integer intCounter = 0;
                for(OpportunityLineItem oppLineItem:oppLineItems)
                {
                    Opportunity opp = new Opportunity(id = oppLineItem.OpportunityId,Product__c = idProducts[intCounter]);                                                                                                       
                    opps.add(opp);
                    intCounter++;
                }
             
                Database.update(opps);  
            }
                                
        }
    
    public static void updateOLIMgr(OpportunityLineItem[] oppLineItems)
    {
        List<Id> idOpp = new List<Id>();
               
        for(OpportunityLineItem oppLI: oppLineItems)
        {
            idOpp.add(oppLI.OpportunityId);
        }       
        
         
        
    }   
    
    public static void eraseOppProd(OpportunityLineItem[] oppLineItems)
    {
        List<Opportunity> opps = new List<Opportunity>();
        List<Id> idOpp = new List<Id>();
            
        for(OpportunityLineItem oppLI: oppLineItems)
        {
            idOpp.add(oppLI.OpportunityId);
        }       
        
        List<Opportunity> sObjOpp = [Select Id, Product__c from Opportunity where Id in :idOpp];
        
        for(Opportunity opp:sObjOpp)
            {
                Opportunity oppty = new Opportunity(id=opp.id, Product__c = null, X50__c = null);                                                                                                        
                opps.add(oppty);
            }
        database.update(opps);
    }
  }
Hi!

Anybody have an idea on how can I make the Sales Path on lead page read-only?
I do not want users to click on this path to mark it as complete..

I want them to use the Lead status field from the detail page to change the lead status..Once saved, the status will just reflects in the sales path section.

Thanks!
Hi!

Can someone give me a sample apex code to update a custom LOOKUP field Product__custom in my opportunity detail page.

When i select an opportunity product, i want that product to reflect in my custom lookup field also.


TIA!
 
Hi!

Is there any existing topic i can check for my issue. I created a lookup field PRODUCT in my opportunity object, from this i want to display the opportunity product i selected so from here i can create a new formula fields to display the discount, list price etc. Is there any other approach i can do? 

tia!

Del
Hi Guys!

Good day. I am creating a test method for a class i just created from a recycled apex code.
I have a requirement of updating the custom lookup field product__c in our opportunity object.
This field gets its value from the opportunity line item.  

I've created an apex class, got the code somewhere from the internet, i read and tried a lot, fortunately made it working for our requirement. :)
The problem is i been trying to make a test method for it but keeps failing. I am a new admin and do not know much about coding.

Can someone help me to make a test class please. :) TIA guys!

Heres my apex class:

public class UpdateOLIProdMgr {
    public static void updateOppProdMgr(OpportunityLineItem[] oppLineItems)
        {
            List<Opportunity> opps = new List<Opportunity>();
            List<Id> idPriceBookEntry = new List<Id>();
            List<Id> idProducts = new List<Id>();
            List<String> strFamily = new List<String>();
             

            for(OpportunityLineItem oppLineItem:oppLineItems)
            {
                idPriceBookEntry.add(oppLineItem.PricebookEntryId);             
            }   
            
            
            List<PricebookEntry> sObjPriceBookEntries = [Select Product2Id, Product2.Family, Product2.Name from PricebookEntry where Id in :idPriceBookEntry]; 
            for(PricebookEntry objPriceBookEntry:sObjPriceBookEntries)
            {
                idProducts.add(objPriceBookEntry.Product2Id);
                strFamily.add(objPriceBookEntry.Product2.Family);
            }
            
                        
                       
            if (sObjPriceBookEntries.size() > 0)
            {
                                 
                Integer intCounter = 0;
                for(OpportunityLineItem oppLineItem:oppLineItems)
                {
                    Opportunity opp = new Opportunity(id = oppLineItem.OpportunityId,Product__c = idProducts[intCounter]);                                                                                                       
                    opps.add(opp);
                    intCounter++;
                }
             
                Database.update(opps);  
            }
                                
        }
    
    public static void updateOLIMgr(OpportunityLineItem[] oppLineItems)
    {
        List<Id> idOpp = new List<Id>();
               
        for(OpportunityLineItem oppLI: oppLineItems)
        {
            idOpp.add(oppLI.OpportunityId);
        }       
        
         
        
    }   
    
    public static void eraseOppProd(OpportunityLineItem[] oppLineItems)
    {
        List<Opportunity> opps = new List<Opportunity>();
        List<Id> idOpp = new List<Id>();
            
        for(OpportunityLineItem oppLI: oppLineItems)
        {
            idOpp.add(oppLI.OpportunityId);
        }       
        
        List<Opportunity> sObjOpp = [Select Id, Product__c from Opportunity where Id in :idOpp];
        
        for(Opportunity opp:sObjOpp)
            {
                Opportunity oppty = new Opportunity(id=opp.id, Product__c = null, X50__c = null);                                                                                                        
                opps.add(oppty);
            }
        database.update(opps);
    }
  }
Hi!

Is there any existing topic i can check for my issue. I created a lookup field PRODUCT in my opportunity object, from this i want to display the opportunity product i selected so from here i can create a new formula fields to display the discount, list price etc. Is there any other approach i can do? 

tia!

Del