• Hughbert Strong
  • NEWBIE
  • 20 Points
  • Member since 2016
  • Salesforce Administrator
  • ECi Software Solutions


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 5
    Replies
All,

I need help writing a test class for this Apex Trigger that fires on the CPQ Quoteline. Can anyone help me out?

Apex Trigger:
trigger QLSummaryRollUps on SBQQ__QuoteLine__c (after insert,after update,after delete) {
    list<SBQQ__QuoteLine__c> l;
    if(Trigger.isInsert || Trigger.isUpdate)
    {
        l = Trigger.new;
    }
    if(Trigger.isDelete)
    {
        l = Trigger.old;
    }
    Decimal rec=0.00;
    Decimal upf=0.00;
    Decimal hware=0.00;
    Decimal Nrec=0.00;
    Decimal Nupf=0.00;
    Decimal Nhware=0.00;    
    String qid;
    
    
    for(SBQQ__QuoteLine__c q : l)
    {
        qid=q.SBQQ__Quote__c;
    }
    for(SBQQ__QuoteLine__c f : l)
    {
        if(f.Quote_Line_Grouping__c != null){
        if(f.Quote_Line_Grouping__c == 'Recurring Fee')
        {
                rec+=f.Adjusted_List_Line_Item__c;
                Nrec+=f.SBQQ__NetTotal__c;
        }
        if(f.Quote_Line_Grouping__c == 'Hardware')
        {
                hware+=f.Adjusted_List_Total__c;
                Nhware+=f.SBQQ__NetTotal__c;
        }        
        if(f.Quote_Line_Grouping__c == 'Upfront Fee')
        {
                upf+=f.Adjusted_List_Total__c;
                Nupf+=f.SBQQ__NetTotal__c;
        } 
        }   
    }
    SBQQ__Quote__c q=[SELECT Id, Adjusted_List_Total_Recurring_Fee_2__c, Adjusted_List_Total_Hardware_2__c, Adjusted_List_Total_Upfront_Fee_2__c, Net_Total_Hardware_2__c, Net_Total_Recurring_Fee_2__c, Net_Total_Upfront_Fee_2__c FROM SBQQ__Quote__c WHERE Id =: qid];
    q.Adjusted_List_Total_Recurring_Fee_2__c=rec;
    q.Adjusted_List_Total_Hardware_2__c=hware;
    q.Adjusted_List_Total_Upfront_Fee_2__c=upf;
    q.Net_Total_Recurring_Fee_2__c=Nrec;
    q.Net_Total_Hardware_2__c=Nhware;
    q.Net_Total_Upfront_Fee_2__c=Nupf;    
    System.debug(rec);
    System.debug(hware);
    System.debug(upf);
    System.debug(Nrec);
    System.debug(Nhware);
    System.debug(Nupf);
    update q;
}
Hello,

My trigger is running fine in the sandbox. When I run my test class, I receive the following error: System.LimitException: SBQQ:Too many SOQL queries: 101. Can someone take a look at my code and point me in the right direction?

Trigger:
trigger QLAdjustListTotal on SBQQ__QuoteLine__c (after insert, after update, after delete) {
    Decimal ADJrec = 0.00;
    Decimal ADJup = 0.00;
    Decimal ADJhware = 0.00;
    Decimal NETrec = 0.00;
    Decimal NETup = 0.00;
    Decimal NEThware = 0.00;    
    String qid;
    
    list<SBQQ__QuoteLine__c> l;
    
    if(Trigger.isInsert || Trigger.isUpdate){
        l = Trigger.new;
    }
    
    if(Trigger.isDelete){
        l = Trigger.old;
    }
    
    try{
    for(SBQQ__QuoteLine__c q : l){
        qid=q.SBQQ__Quote__c;
    }
 
    for(SBQQ__QuoteLine__c f : l){
        if(f.Adjusted_List_Line_Item__c > 0 && f.Quote_Line_Grouping__c == 'Recurring Fee'){
            ADJrec+=f.Adjusted_List_Line_Item__c;
            if(f.SBQQ__NetTotal__c > 0){
            NETrec+=f.SBQQ__NetTotal__c;
            }
        }
         if(f.Adjusted_List_Total__c > 0 && f.Quote_Line_Grouping__c == 'Upfront Fee'){
            ADJup+=f.Adjusted_List_Total__c;
            if(f.SBQQ__NetTotal__c > 0){ 
            NETup+=f.SBQQ__NetTotal__c;
            }     
        }
        if(f.Adjusted_List_Total__c > 0 && f.Quote_Line_Grouping__c == 'Hardware'){
            ADJhware+=f.Adjusted_List_Total__c;
            if(f.SBQQ__NetTotal__c > 0){ 
            NEThware+=f.SBQQ__NetTotal__c;
                }    
            }
        }
    SBQQ__Quote__c q = [Select Id from SBQQ__Quote__c where Id =: qid];
    q.Adjusted_List_Total_Recurring_Fee_2__c = ADJrec;
    q.Adjusted_List_Total_Upfront_Fee_2__c = ADJup;
    q.Adjusted_List_Total_Hardware_2__c = ADJhware;
    q.Net_Total_Recurring_Fee_2__c = NETrec;
    q.Net_Total_Upfront_Fee_2__c = NETup;
    q.Net_Total_Hardware_2__c = NEThware;
    update q;   
    }catch(QueryException ex){
    System.debug(ADJrec);
    System.debug(ADJup);
    System.debug(ADJhware);
    System.debug(NETrec);
    System.debug(NETup);
    System.debug(NEThware);}     
    
}

Test Class
@isTest(SeeAllData = true)
public class TestQLAdjustListTotal {
    static testMethod void TestQL(){
        //Start Test
        Test.startTest();
        
        //Declare Variables and Objects
        Decimal ST = 12;
        Date StartQuote = Date.today();
        Account a = new Account();
        Opportunity o = new Opportunity();
        SBQQ__Quote__c q = new SBQQ__Quote__c();
        SBQQ__QuoteLine__c qlRec = new SBQQ__QuoteLine__c();
        SBQQ__QuoteLine__c qlUp = new SBQQ__QuoteLine__c();
        SBQQ__QuoteLine__c qlHware = new SBQQ__QuoteLine__c();        

        //Create Account Record
        a.Name = 'TestAccount';
        insert a;
        update a;
        
        //Create Opporunity
        o.Name = 'Test Opp';
        o.AccountId = a.Id;
        o.Type = 'New Business 2';
        o.CloseDate = StartQuote;
        o.Type_of_Sale__c = 'New System';
        o.ECi_Product__c = 'Spruce';
        o.StageName = 'Owned Lead';
        o.Cloud_Deal__c = True;
      o.Pricebook2 = [Select id from Pricebook2 where id ='01s0v000000PRox'];
        insert o;

        
        //Create Quote Record
        q.SBQQ__Account__c = a.Id;
        q.SBQQ__Opportunity2__c = o.Id;
        q.SBQQ__Status__c = 'Draft';
        q.SBQQ__Type__c = 'Quote';
        q.SBQQ__StartDate__c = StartQuote;
        q.CurrencyIsoCode = 'USD';
        q.SBQQ__Primary__c = True;
        q.SBQQ__SubscriptionTerm__c = ST;
        q.SBQQ__PriceBook__c = [Select id from Pricebook2 where id ='01s0v000000PRox'].id;
        insert q;

        //Create Quote Line Records
        
        //Create Recurring Fee Quote Line
        qlRec.SBQQ__Quote__c = q.Id;
        qlRec.SBQQ__Product__c = [Select id from Product2 where id ='01t0v0000010bna'].id;
        insert qlRec;
        delete qlRec;
        
        //Create Upfront Fee Quote Line
        qlUp.SBQQ__Quote__c = q.Id;
        qlUp.SBQQ__Product__c = [Select id from Product2 where id ='01t0v0000010bnV'].id;
        insert qlUp;
        delete qlUp;        

        //Create Hardware Fee Quote Line
        qlHware.SBQQ__Quote__c = q.Id;
           qlHware.SBQQ__Product__c = [Select id from Product2 where id ='01t0v0000010bnf'].id;

        insert qlHware;
        delete qlHware;        
        Test.stopTest(); 
    }

}
Hello friends,

I'm fairly new to writting Apex code, and I'm running code covearge issues with my scheduled apex class. 50% 4/8 lines. Can someone help me out?

Apex Class:
global class scheduleExpiredEntitlements implements Schedulable{
    global static void scheduleMe(){
        scheduleExpiredEntitlements msc = new scheduleExpiredEntitlements();
        String sch= '0 00 00 * * ?';
        String jobID = System.schedule('Scheduled Job', sch, msc);
    }
    global void execute(SchedulableContext sc){
     List<Entitlement> EntIds = [Select Id, Name, EndDate, CasesPerEntitlement, RemainingCases, IsPerIncident, AccountId from Entitlement Where EndDate = Yesterday]; 
        for(integer i = 0; i< EntIds.size(); i++){
            
        }
            update EntIds;
        }
    }

Test Class:
@istest
public class TestScheduleExpiredEntitlements {
    
        @istest static void testEntitlements(){
        Date Ender = Date.today()-1;
        Date Starter = Date.today()-365;
        
        Account a = New Account();
        a.Name = 'Hieu Truong';    
        insert a;
            
        Entitlement e = New Entitlement ();
        e.Name ='Test Entitlement';
        e.StartDate = Starter;
        e.EndDate = Ender;
        e.CasesPerEntitlement = 99;
        e.RemainingCases = 99;
        e.IsPerIncident = true;
        e.AccountId = a.Id;    
        insert e;
        
        String CRON_EXP = '0 0 0 15 3 ? *';
        
        String jobId = System.schedule('ScheduleApexClassTest',  CRON_EXP, new scheduleExpiredEntitlements());
        CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId];
        System.assertEquals(CRON_EXP, ct.CronExpression);
        System.assertEquals(0, ct.TimesTriggered);
    }
}
Hello All,

I'm new to writting triggers and classes. I have a trigger I'm trying to schedule. Not sure how to complete this. I've read that I have to place the class in my trigger, but not sure how.

Trigger Code:
trigger ExpiredEntitlements on Entitlement (after update) {
    List<Entitlement> EntIds = New List <Entitlement>();
    for (Entitlement e: Trigger.new){
        if (e.EndDate == date.today() -1){
            try{
                e.Id = [Select Id from Entitlement Where EndDate = Yesterday].Id;
            }catch(QueryException ex){
                
            }
        EntIds.add(e);    
        }
    }
List<Entitlement> EntList = [Select id FROM Entitlement WHERE id in :EntIds];
    for(integer i = 0; i < EntList.size(); i++){
        
    }
    update EntList;
}

Apex Class Code:
global class scheduleExpiredEntitlements implements Schedulable{
    global static void scheduleMe(){
        scheduleExpiredEntitlements msc = new scheduleExpiredEntitlements();
        String sch= '0 00 00 * * ?';
        String jobID = System.schedule('Scheduled Job', sch, msc);
    }
    global void execute(SchedulableContext sc){
        ExpiredEntitlements e = new ExpiredEntitlements();
    }
}

Thanks,
Hieu

Hello friends,

This is my second attempt at writing an apex trigger. I receiving an error when I save my trigger, "Illegal assignment from List to Decimal."
Hopefully someone can give me some pointers.

Here's my code:
trigger SRTake1 on Stack_Rank__c (after update) {
    Date myDate = Date.newInstance(2017, 01, 01);
    
    for( Stack_Rank__c s: Trigger.new){
        if(s.SR_Date__c == myDate && s.SR_Main_Sales__c == null){
            try{
                s.SR_Main_Sales__c=[Select OwnerID, SUM(quota_credit__c) from Opportunity Where OwnerID in (Select User__c From Stack_Rank__c Where SR_Date__c = 2017-01-01) AND CloseDate >= 2017-01-01 AND CloseDate <= 2017-01-31 Group By OwnerId];
            
            }
            catch(QueryException ex) {
                //todo add other entitlements
            }
            
        }
    }

}

Hello All,

I have 2 date fields and a number field.

Date Fields: Start Date, End Date
Number Field: Subscription Term

I would like to populate the End date based on the Subscription Term. Example: Start Date = 2/13/2017, Subscription Term 13 months, End Date = 3/13/2018.

Not sure how to start writting a formula for this. 

Thanks,
Hieu
Hello friends,

I'm fairly new to writting Apex code, and I'm running code covearge issues with my scheduled apex class. 50% 4/8 lines. Can someone help me out?

Apex Class:
global class scheduleExpiredEntitlements implements Schedulable{
    global static void scheduleMe(){
        scheduleExpiredEntitlements msc = new scheduleExpiredEntitlements();
        String sch= '0 00 00 * * ?';
        String jobID = System.schedule('Scheduled Job', sch, msc);
    }
    global void execute(SchedulableContext sc){
     List<Entitlement> EntIds = [Select Id, Name, EndDate, CasesPerEntitlement, RemainingCases, IsPerIncident, AccountId from Entitlement Where EndDate = Yesterday]; 
        for(integer i = 0; i< EntIds.size(); i++){
            
        }
            update EntIds;
        }
    }

Test Class:
@istest
public class TestScheduleExpiredEntitlements {
    
        @istest static void testEntitlements(){
        Date Ender = Date.today()-1;
        Date Starter = Date.today()-365;
        
        Account a = New Account();
        a.Name = 'Hieu Truong';    
        insert a;
            
        Entitlement e = New Entitlement ();
        e.Name ='Test Entitlement';
        e.StartDate = Starter;
        e.EndDate = Ender;
        e.CasesPerEntitlement = 99;
        e.RemainingCases = 99;
        e.IsPerIncident = true;
        e.AccountId = a.Id;    
        insert e;
        
        String CRON_EXP = '0 0 0 15 3 ? *';
        
        String jobId = System.schedule('ScheduleApexClassTest',  CRON_EXP, new scheduleExpiredEntitlements());
        CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId];
        System.assertEquals(CRON_EXP, ct.CronExpression);
        System.assertEquals(0, ct.TimesTriggered);
    }
}
Hello All,

I'm new to writting triggers and classes. I have a trigger I'm trying to schedule. Not sure how to complete this. I've read that I have to place the class in my trigger, but not sure how.

Trigger Code:
trigger ExpiredEntitlements on Entitlement (after update) {
    List<Entitlement> EntIds = New List <Entitlement>();
    for (Entitlement e: Trigger.new){
        if (e.EndDate == date.today() -1){
            try{
                e.Id = [Select Id from Entitlement Where EndDate = Yesterday].Id;
            }catch(QueryException ex){
                
            }
        EntIds.add(e);    
        }
    }
List<Entitlement> EntList = [Select id FROM Entitlement WHERE id in :EntIds];
    for(integer i = 0; i < EntList.size(); i++){
        
    }
    update EntList;
}

Apex Class Code:
global class scheduleExpiredEntitlements implements Schedulable{
    global static void scheduleMe(){
        scheduleExpiredEntitlements msc = new scheduleExpiredEntitlements();
        String sch= '0 00 00 * * ?';
        String jobID = System.schedule('Scheduled Job', sch, msc);
    }
    global void execute(SchedulableContext sc){
        ExpiredEntitlements e = new ExpiredEntitlements();
    }
}

Thanks,
Hieu

Hello friends,

This is my second attempt at writing an apex trigger. I receiving an error when I save my trigger, "Illegal assignment from List to Decimal."
Hopefully someone can give me some pointers.

Here's my code:
trigger SRTake1 on Stack_Rank__c (after update) {
    Date myDate = Date.newInstance(2017, 01, 01);
    
    for( Stack_Rank__c s: Trigger.new){
        if(s.SR_Date__c == myDate && s.SR_Main_Sales__c == null){
            try{
                s.SR_Main_Sales__c=[Select OwnerID, SUM(quota_credit__c) from Opportunity Where OwnerID in (Select User__c From Stack_Rank__c Where SR_Date__c = 2017-01-01) AND CloseDate >= 2017-01-01 AND CloseDate <= 2017-01-31 Group By OwnerId];
            
            }
            catch(QueryException ex) {
                //todo add other entitlements
            }
            
        }
    }

}

Greetings!

 

I'm setting up a Customer Community for my clients to access my instance of salesforce to open and track their own Cases.  I went through he setup steps outlined to enable users and was in the process of testing the visibility of community users to their cases (where they are the contact on the case) and discovered that while logged in as a community user I can see all cases, and can open the records.

 

Is there a permission setting for Customer Community I am missing?