• Joshua Meyer
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 7
    Replies
When I try to save an Apex class or trigger in sandbox, the developer console hangs up on saving and never finishes.

I've tried deleting my workspace. I've also done 'Cancel Save (Cancels all deployments).

Have been reading old threads for over an hour to no avail.

Any idea on what to try next?

Thanks!

 
Hi There!

I am using a trigger to to some calculations on quote line item which involves pulling a value from opportunity product if a corresponding opp product exists (for example when a quote is created vs when a quote line item is manually added). In my test class I create a quote as follows: 
 
Quote a1o1q1 = new Quote();
        a1o1q1.Name = 'a1o1q1';
        a1o1q1.Opportunity = a1o1;
        a1o1q1.OpportunityId = a1o1.Id;
        a1o1q1.Expiration__c = Date.parse('08/01/2018');
        a1o1q1.Net_Terms__c = 'Net 30';
        a1o1q1.Payment_Schedule__c = 'Annual';
        a1o1q1.Payment_Terms__c = 'None';
		a1o1q1.Discount_Special_Term_Explanation__c = 'none';
        a1o1q1.of_Hires__c = '1';
        a1o1q1.of_Employees__c = 1;
	    a1o1q1.Use_limited_to__c = '1';
        a1o1q1.ContactId = quoteContact.Id;
        a1o1q1.ShippingName = 'Test Name';
        a1o1q1.ShippingStreet = '123 Sesame Street';
        a1o1q1.ShippingCity = 'Pretend City';
        a1o1q1.ShippingPostalCode = '77546';
        a1o1q1.ShippingState = 'Texas';
        a1o1q1.ShippingCountry = 'USA';
        a1o1q1.Pricebook2Id = Test.getStandardPricebookId();
        
        List<Quote> quotes = new List<Quote>();
        quotes.add(a1o1q1);
        insert quotes;
Although there are Opportunity Products on the Opportunity I'm tying the quote to, they are not being created as line items on the quote. Here's a screen of my code coverage, you'll see that the qliOli (related opp product to the quote line item) is not being covered.

** Please note, this code is actually working in Sandbox. When I create a quote, the opportunity products push to quote line items. I just can't get the code coverage in my test class. Any help greatly appreciated. Thanks!

User-added image

 
Hi Awesome Developers!

This is my first trigger (first one for a my job anyways) and I want to make sure I wrote it efficiently. My test class is yeidling the expected results. I'm basically putting a list of products families from active opportunities (closed won and in the subscription date range) on the Account object. I'm also putting Active MRR (monthly recurring revenue) on the account.

The part I have the question about is each time I go through the loop, I loop through every opportunity to ensure I only calculate on the opportunities related to the current account. It seems inefficient to me. Is there a better way to do this. Please don't hold back and critiques or observations as I am learning and appreciative! Thanks so much!
 
trigger UpdateProductMix on Account (before update) {
    //System.debug('Trigger Account ID: ' + acct.Id);
            
    List<Opportunity> opps = [SELECT id, Account.Id, Opportunity_MRR__c, (SELECT Id, PricebookEntry.Product2.Family FROM OpportunityLineItems) FROM Opportunity 
                              WHERE AccountId IN :Trigger.New AND StageName = 'Closed Won' 
                              AND Subscription_Start_Date__c <= TODAY 
                              AND Subscription_Current_Expiration_Date__c >= TODAY];
    
    for(Account acct:Trigger.New){
        //Initialize variables
        String prodMix = '';
        Set<String> families = new Set<String>();
        Decimal mrr = 0.00;
        
        // Process the query results
        for(Opportunity o:opps){
            if(acct.Id == o.AccountId){
                //System.debug('o.Opportunity_MRR__c' + o.Opportunity_MRR__c);
                mrr += o.Opportunity_MRR__c; //Add opp MRR of all active opps
                for(OpportunityLineItem oli:o.OpportunityLineItems){
                    if(!families.contains(oli.PricebookEntry.Product2.Family)){
                        //System.debug('oli.PricebookEntry.Product2.Family: ' + oli.PricebookEntry.Product2.Family);
                        families.add(oli.PricebookEntry.Product2.Family); //Add each unique product family to the set
                    }
                }
            }
        }
        
        acct.Active_MRR__c = mrr; //Set the MRR on the account
        
        List<String> famList = new List<String>(families); //Convert set to list so we can sort that bad boy
        famList.sort(); // Sort magic
        
        //Create the product mix string
        for(String family:famList){
            prodMix += family + ', ';
        }
        System.debug('prodMix.length: ' + prodMix.length());   
        if (prodMix.length() > 0){
            acct.Current_Products__c = prodMix.substring(0,prodMix.length()-2); //Trim the final comma and space and set
        } else{
            acct.Current_Products__c = 'No active products';
        }
        
    }
}

 
When I try to save an Apex class or trigger in sandbox, the developer console hangs up on saving and never finishes.

I've tried deleting my workspace. I've also done 'Cancel Save (Cancels all deployments).

Have been reading old threads for over an hour to no avail.

Any idea on what to try next?

Thanks!

 
Hi There!

I am using a trigger to to some calculations on quote line item which involves pulling a value from opportunity product if a corresponding opp product exists (for example when a quote is created vs when a quote line item is manually added). In my test class I create a quote as follows: 
 
Quote a1o1q1 = new Quote();
        a1o1q1.Name = 'a1o1q1';
        a1o1q1.Opportunity = a1o1;
        a1o1q1.OpportunityId = a1o1.Id;
        a1o1q1.Expiration__c = Date.parse('08/01/2018');
        a1o1q1.Net_Terms__c = 'Net 30';
        a1o1q1.Payment_Schedule__c = 'Annual';
        a1o1q1.Payment_Terms__c = 'None';
		a1o1q1.Discount_Special_Term_Explanation__c = 'none';
        a1o1q1.of_Hires__c = '1';
        a1o1q1.of_Employees__c = 1;
	    a1o1q1.Use_limited_to__c = '1';
        a1o1q1.ContactId = quoteContact.Id;
        a1o1q1.ShippingName = 'Test Name';
        a1o1q1.ShippingStreet = '123 Sesame Street';
        a1o1q1.ShippingCity = 'Pretend City';
        a1o1q1.ShippingPostalCode = '77546';
        a1o1q1.ShippingState = 'Texas';
        a1o1q1.ShippingCountry = 'USA';
        a1o1q1.Pricebook2Id = Test.getStandardPricebookId();
        
        List<Quote> quotes = new List<Quote>();
        quotes.add(a1o1q1);
        insert quotes;
Although there are Opportunity Products on the Opportunity I'm tying the quote to, they are not being created as line items on the quote. Here's a screen of my code coverage, you'll see that the qliOli (related opp product to the quote line item) is not being covered.

** Please note, this code is actually working in Sandbox. When I create a quote, the opportunity products push to quote line items. I just can't get the code coverage in my test class. Any help greatly appreciated. Thanks!

User-added image

 
Hi Awesome Developers!

This is my first trigger (first one for a my job anyways) and I want to make sure I wrote it efficiently. My test class is yeidling the expected results. I'm basically putting a list of products families from active opportunities (closed won and in the subscription date range) on the Account object. I'm also putting Active MRR (monthly recurring revenue) on the account.

The part I have the question about is each time I go through the loop, I loop through every opportunity to ensure I only calculate on the opportunities related to the current account. It seems inefficient to me. Is there a better way to do this. Please don't hold back and critiques or observations as I am learning and appreciative! Thanks so much!
 
trigger UpdateProductMix on Account (before update) {
    //System.debug('Trigger Account ID: ' + acct.Id);
            
    List<Opportunity> opps = [SELECT id, Account.Id, Opportunity_MRR__c, (SELECT Id, PricebookEntry.Product2.Family FROM OpportunityLineItems) FROM Opportunity 
                              WHERE AccountId IN :Trigger.New AND StageName = 'Closed Won' 
                              AND Subscription_Start_Date__c <= TODAY 
                              AND Subscription_Current_Expiration_Date__c >= TODAY];
    
    for(Account acct:Trigger.New){
        //Initialize variables
        String prodMix = '';
        Set<String> families = new Set<String>();
        Decimal mrr = 0.00;
        
        // Process the query results
        for(Opportunity o:opps){
            if(acct.Id == o.AccountId){
                //System.debug('o.Opportunity_MRR__c' + o.Opportunity_MRR__c);
                mrr += o.Opportunity_MRR__c; //Add opp MRR of all active opps
                for(OpportunityLineItem oli:o.OpportunityLineItems){
                    if(!families.contains(oli.PricebookEntry.Product2.Family)){
                        //System.debug('oli.PricebookEntry.Product2.Family: ' + oli.PricebookEntry.Product2.Family);
                        families.add(oli.PricebookEntry.Product2.Family); //Add each unique product family to the set
                    }
                }
            }
        }
        
        acct.Active_MRR__c = mrr; //Set the MRR on the account
        
        List<String> famList = new List<String>(families); //Convert set to list so we can sort that bad boy
        famList.sort(); // Sort magic
        
        //Create the product mix string
        for(String family:famList){
            prodMix += family + ', ';
        }
        System.debug('prodMix.length: ' + prodMix.length());   
        if (prodMix.length() > 0){
            acct.Current_Products__c = prodMix.substring(0,prodMix.length()-2); //Trim the final comma and space and set
        } else{
            acct.Current_Products__c = 'No active products';
        }
        
    }
}