• Jon Gradman
  • NEWBIE
  • 20 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 6
    Replies
Hi everyone,

For some reason I can't figure out how to get my test class code coverage to get above 65%. Can someone point me in the right direction?

Here is the trigger code:
trigger QuoteCharge_Update on zqu__QuoteRatePlanCharge__c ( after insert, after update )
{
// Step 1. Declare list to hold newly created opp line items.

List<OpportunityLineItem> listOli = new List<OpportunityLineItem>();

//Step 2. Loop through items in trigger for insert case: 
if (trigger.isInsert) {
  for(zqu__QuoteRatePlanCharge__c zQuoteCh1: Trigger.new) {
    OpportunityLineItem oli = new OpportunityLineItem();
    oli.OpportunityId = zQuoteCh1.Opportunity_Id__c;
    oli.Product2Id = zQuoteCh1.Product_Id__c;
    oli.Quote_Rate_Plan_Charge__c = zQuoteCh1.Id;
    oli.Quote_Rate_Plan__c = zQuoteCh1.zqu__QuoteRatePlan__c;
    oli.Description = zQuoteCh1.zqu__Description__c;
    oli.TotalPrice = zQuoteCh1.zqu__EffectivePrice__c;
    oli.Quantity = 1;
    oli.Quote_Amendment__c = Id.ValueOf(zQuoteCh1.Quote_Amendment_Id__c);
    if(zQuoteCh1.Projected_Product_MRR__c != null ) {
        oli.Projected_Product_MRR__c = zQuoteCh1.Projected_Product_MRR__c;
    }
    if(zQuoteCh1.Projected_Product_MRR__c == null) {
        oli.Projected_Product_MRR__c = zQuoteCh1.zqu__EffectivePrice__c;
    }
    
    
    listOli.add(oli);
    }
}
//Step 3. Loop through items in trigger for update case:
if(trigger.isUpdate) {
  for(zqu__QuoteRatePlanCharge__c zQuoteCh1: Trigger.new) {
    OpportunityLineItem oli = [SELECT id, Quote_Rate_Plan_Charge__c, Projected_Product_MRR__c, TotalPrice 
                                FROM OpportunityLineItem WHERE Quote_Rate_Plan_Charge__c = :zQuoteCh1.id];
    oli.TotalPrice = zQuoteCh1.zqu__EffectivePrice__c;
    if(zQuoteCh1.Projected_Product_MRR__c != null ) {
        oli.Projected_Product_MRR__c = zQuoteCh1.Projected_Product_MRR__c;
    }
    if(zQuoteCh1.Projected_Product_MRR__c == null) {
        oli.Projected_Product_MRR__c = zQuoteCh1.zqu__EffectivePrice__c;
    }

    listOli.add(oli);
    }
}

// Step 4 If any items in the list, insert into the db.
if(listOli.size() > 0 ) {
    upsert listOli;
}
}

Here is my test class (65% coverage):
@isTest
public class QuoteChargeTest
{
    static testMethod void QuoteChargeTest()
    {

        Account acct = new Account(name='dummy',Type='Prospect',Website='dummy.com',Account_Source__c='Sales',
                                  Priority__c=1);
        insert acct;
     
        Opportunity opp = new Opportunity(Name='dummy opp',Type='New Business',Product_Interest__c='Google PLA',
                                          Success_Notes__c='awesome',StageName='Discovery Set',CloseDate=System.today());
        insert opp;
        
        Product2 prod = new Product2(Name='PLA',Description='test text',isActive=true);
        insert prod;
        
        Pricebook2 book = new Pricebook2(Name='normal',isActive=true);
        insert book;
        
        Id standardPB = Test.getStandardPricebookId();
        
        PriceBookEntry dummy = new PriceBookEntry(isActive=true,Product2Id=prod.id,UnitPrice=1200,Pricebook2Id = standardPB);
        insert dummy;
        
        zqu__Quote__c newQuote = new zqu__Quote__c(zqu__Opportunity__c=opp.Id,zqu__Account__c=acct.Id,Name='test');
        insert newQuote;

        zqu__QuoteAmendment__c qa = new zqu__QuoteAmendment__c(Name='test amendment', zqu__Quote__c=newQuote.Id, zqu__Type__c='NewProduct');
        insert qa;
        
        zqu__ProductRatePlan__c prp = new zqu__ProductRatePlan__c(Name='test rateplan',zqu__Product__c=prod.Id);
        insert prp;
        
        zqu__ProductRatePlanCharge__c prpc = new zqu__ProductRatePlanCharge__c(Name='spend / or',zqu__Type__c='Usage',zqu__ListPrice__c=1);
        insert prpc;

        zqu__QuoteRatePlan__c qrp = new zqu__QuoteRatePlan__c(Name='qrp',zqu__ProductRatePlan__c=prp.Id,zqu__QuoteAmendment__c=qa.id,zqu__Quote__c=newQuote.Id,
                                                             zqu__AmendmentType__c='NewProduct');
        insert qrp;
        
        
    
            Test.starttest();
       try
           {
           zqu__QuoteRatePlanCharge__c qrpc = new zqu__QuoteRatePlanCharge__c(Name='Flat Fee',zqu__QuoteRatePlan__c=qrp.Id,zqu__Description__c='test',
                                                                           Projected_Product_MRR__c=500,zqu__EffectivePrice__c=1000);
           insert qrpc;
           zqu__QuoteRatePlanCharge__c qrpc2 = new zqu__QuoteRatePlanCharge__c(Name='Flat Fee',zqu__QuoteRatePlan__c=qrp.Id,zqu__Description__c='test',
                                                                           Projected_Product_MRR__c=500,zqu__EffectivePrice__c=1000);
     	  insert qrpc2;
           
           qrpc.Projected_Product_MRR__c = 0;
           update qrpc;
           
           
           }
           catch (DMLException e)
           {
          
           }
    Test.stoptest();
    }    
}

 
Hi all,

I've been a Salesforce admin for 2 years and have experience with point and click development like Visual Workflow and Visualforce controllers but I don't have a lot of experience writing test classes.  This test class is coming up short with 43% coverage:
 
@isTest
private class AcctUpdateTest {
    
  public static testMethod void testschedule() {

  Test.StartTest();
  AccountsUpdate sh1 = new AccountsUpdate();      
    String sch = '0 0 23 * * ?';
        system.schedule('Test check', sch, sh1);
    Test.stopTest();
 
    }
}

Here is the class code.  The reason I am updating the code is to avoid being timed out by a trigger, which is part of the Lookup Helper managed package.  Our batchable APEX code below runs every night to update all of our customer Accounts in SFDC so that various workflows and alerts fire when they are relevant.  Since installing this package, however, we are having timeout errors.  As a second question, will this code help increase the CPU time to avoid an error?
 
global class AccountsUpdate implements Database.Batchable<sObject>,Schedulable {
    global Database.QueryLocator start(Database.BatchableContext bc) {
        String query = 'SELECT Id, Type FROM Account'; // create the query to run
        return Database.getQueryLocator(query); //get all of the data in the start
    }
    global void execute(Database.BatchableContext bc,List<sObject> objects){
        //because a generic list is passed in, you have to 'box' it (type set) it to the Right Object.
        List<Account> acctList = [Select Id, Type From Account Where Type = 'Customer - Current' OR Type =               'Customer - Current - Overdue' ];
        List<Account> updAccounts = new List<Account>();
        integer counter = 0;
        
        for(Account thisAcct : acctList) {
            updAccounts.add(thisAcct);
            counter++;
            if (counter == 20) { update(updAccounts); }
        }
        
        if (counter > 0) { update(updAccounts); }
    }
    global void finish(Database.BatchableContext BC) {
        AsyncApexJob aaj = [Select Id, Status, NumberOfErrors, JobItemsProcessed, MethodName, TotalJobItems, CreatedBy.Email from AsyncApexJob where Id =:BC.getJobId()];
    }
    global void execute(SchedulableContext sc){
        Database.executeBatch(new AccountsUpdate());
    }
}
The old code just selected all customers and attempted an update, but doing 200 records at a time was making the triggers associated with Lookup Helper to fail / timeout - since they are written for every update on Accounts and not for specific fields.

Any suggestions?  All help appreciated thank you.

- Jon
 
Hi,

I'm pretty new to Visualforce, although I have coding experience in other languages.  I've never built a test class for a custom controller before, and looking for some guidance.  Here is the controller code:
 
public class ParentCntacts {
    
    public List<Account> accts {get;set;}
    public Account thisAcct {get;set;}

    
    public ParentCntacts() {
    thisAcct = [Select id, Name, ParentId FROM Account WHERE id = :ApexPages.currentPage().getParameters().get('id')];
    }
    
    public List<Account> getCon() {
        accts = [SELECT id, Name, ParentId, (SELECT id, Name, Title, Main_CSM_Contact__c, Decision_Maker__c, 
            No_Longer_At_Company__c, HasOptedOutOfEmail, Role_Contact_updated__c, Email, Phone, LinkedIn_Profile__c FROM Contacts) FROM Account WHERE Id = :thisAcct.ParentId];

        return accts;
    }
}

Visualforce markup is:
<apex:page controller="ParentCntacts" >
    <apex:pageBlock >
        <apex:repeat value="{!con}" var="a">
            <apex:pageBlockSection ><b>{!a.Name}</b></apex:pageBlockSection>
            <apex:pageblockTable value="{!a.Contacts}" var="c">
                <apex:column headerValue="Contact Name">
                    <apex:outputLink id="link" value="https://cs54.salesforce.com/{!c.Id}" target="_blank" >{!c.Name}</apex:outputLink>
                </apex:column>
                <apex:column value="{!c.Title}" />
                <apex:column value="{!c.Main_CSM_Contact__c}" />
                <apex:column value="{!c.Decision_Maker__c}" />
                <apex:column value="{!c.No_Longer_At_Company__c}" />
                <apex:column value="{!c.HasOptedOutOfEmail}" />
                <apex:column value="{!c.Role_Contact_updated__c}" />
                <apex:column value="{!c.Email}" />
                <apex:column value="{!c.Phone}" />
                <apex:column value="{!c.LinkedIn_Profile__c}" />
            </apex:pageblockTable>
        </apex:repeat>
    </apex:pageBlock>
</apex:page>

The page gets put on the layout and shows contacts on a Parent Account record (shown on a child record).

Any help greatly appreciated, thanks in advance.
I have a flow that is a cutom way of converting a lead, long story short I needed a way to update a field upon conversion of the lead and we needed a custom convert flow to accomplish this. The problem is I needed to remove a status "sales qualified" as an option upon conversion and replace it with "Active Opportunity" but it's not working for me. Can someone help me figure out why? 

User-added image

User-added image

You can see I have "Active Opportunity" as an option for conversion, but it's not letting me chose that as an option. Where in this flow do I update the choices for conversion? 


User-added image
Hi all,

I've been a Salesforce admin for 2 years and have experience with point and click development like Visual Workflow and Visualforce controllers but I don't have a lot of experience writing test classes.  This test class is coming up short with 43% coverage:
 
@isTest
private class AcctUpdateTest {
    
  public static testMethod void testschedule() {

  Test.StartTest();
  AccountsUpdate sh1 = new AccountsUpdate();      
    String sch = '0 0 23 * * ?';
        system.schedule('Test check', sch, sh1);
    Test.stopTest();
 
    }
}

Here is the class code.  The reason I am updating the code is to avoid being timed out by a trigger, which is part of the Lookup Helper managed package.  Our batchable APEX code below runs every night to update all of our customer Accounts in SFDC so that various workflows and alerts fire when they are relevant.  Since installing this package, however, we are having timeout errors.  As a second question, will this code help increase the CPU time to avoid an error?
 
global class AccountsUpdate implements Database.Batchable<sObject>,Schedulable {
    global Database.QueryLocator start(Database.BatchableContext bc) {
        String query = 'SELECT Id, Type FROM Account'; // create the query to run
        return Database.getQueryLocator(query); //get all of the data in the start
    }
    global void execute(Database.BatchableContext bc,List<sObject> objects){
        //because a generic list is passed in, you have to 'box' it (type set) it to the Right Object.
        List<Account> acctList = [Select Id, Type From Account Where Type = 'Customer - Current' OR Type =               'Customer - Current - Overdue' ];
        List<Account> updAccounts = new List<Account>();
        integer counter = 0;
        
        for(Account thisAcct : acctList) {
            updAccounts.add(thisAcct);
            counter++;
            if (counter == 20) { update(updAccounts); }
        }
        
        if (counter > 0) { update(updAccounts); }
    }
    global void finish(Database.BatchableContext BC) {
        AsyncApexJob aaj = [Select Id, Status, NumberOfErrors, JobItemsProcessed, MethodName, TotalJobItems, CreatedBy.Email from AsyncApexJob where Id =:BC.getJobId()];
    }
    global void execute(SchedulableContext sc){
        Database.executeBatch(new AccountsUpdate());
    }
}
The old code just selected all customers and attempted an update, but doing 200 records at a time was making the triggers associated with Lookup Helper to fail / timeout - since they are written for every update on Accounts and not for specific fields.

Any suggestions?  All help appreciated thank you.

- Jon
 

I have created a new survey in production environment using Survey Force from the app exchange by Salesforce Labs. When the survey is sent with caseid and contactid links from a case using an Email Template built with the Survey Force link within it. The user receives the email and survey link, can access and fill in the answers to the survey, BUT, when they attempt to Submit the answers, this message appears on top of page.

Error: Some error occured while saving response

Does anyone know what is causing this, I've checked multiple threads, enabled headers, permissions are properly set, access and visibility seem to be exactly as stated in install guide. Our org is heavily customized and lots of code but I cannot find the source of the error. Thank you for your help and time.

GabeError Message
Hi,

I'm pretty new to Visualforce, although I have coding experience in other languages.  I've never built a test class for a custom controller before, and looking for some guidance.  Here is the controller code:
 
public class ParentCntacts {
    
    public List<Account> accts {get;set;}
    public Account thisAcct {get;set;}

    
    public ParentCntacts() {
    thisAcct = [Select id, Name, ParentId FROM Account WHERE id = :ApexPages.currentPage().getParameters().get('id')];
    }
    
    public List<Account> getCon() {
        accts = [SELECT id, Name, ParentId, (SELECT id, Name, Title, Main_CSM_Contact__c, Decision_Maker__c, 
            No_Longer_At_Company__c, HasOptedOutOfEmail, Role_Contact_updated__c, Email, Phone, LinkedIn_Profile__c FROM Contacts) FROM Account WHERE Id = :thisAcct.ParentId];

        return accts;
    }
}

Visualforce markup is:
<apex:page controller="ParentCntacts" >
    <apex:pageBlock >
        <apex:repeat value="{!con}" var="a">
            <apex:pageBlockSection ><b>{!a.Name}</b></apex:pageBlockSection>
            <apex:pageblockTable value="{!a.Contacts}" var="c">
                <apex:column headerValue="Contact Name">
                    <apex:outputLink id="link" value="https://cs54.salesforce.com/{!c.Id}" target="_blank" >{!c.Name}</apex:outputLink>
                </apex:column>
                <apex:column value="{!c.Title}" />
                <apex:column value="{!c.Main_CSM_Contact__c}" />
                <apex:column value="{!c.Decision_Maker__c}" />
                <apex:column value="{!c.No_Longer_At_Company__c}" />
                <apex:column value="{!c.HasOptedOutOfEmail}" />
                <apex:column value="{!c.Role_Contact_updated__c}" />
                <apex:column value="{!c.Email}" />
                <apex:column value="{!c.Phone}" />
                <apex:column value="{!c.LinkedIn_Profile__c}" />
            </apex:pageblockTable>
        </apex:repeat>
    </apex:pageBlock>
</apex:page>

The page gets put on the layout and shows contacts on a Parent Account record (shown on a child record).

Any help greatly appreciated, thanks in advance.
Our organization would like to eliminate Pardot-related activities out of the Activity History within our leads, contacts and accounts, We want to keep the Pardot Activity section, but our sales team no longer wants Pardot activites listed in the Activity History because they feel it fills up their timeline and makes it hard to identify their personal communications with leads, contacts and accounts. 

From what I understand, this is something that would need to be custom-coded. We do not have Premier Salesforce support, but pay a lot of money annually for Salesforce licenses, and feel like this is a reasonable request. Please let us know what you can do about this. Thank you! 

Brian Overson
(952) 334-3181 
boverson@brandpoint.com