• sai rocks 3
  • NEWBIE
  • 20 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 3
    Replies
@isTest
public class CS_MSA_QuoteHandlerTest {
static Opportunity opp;
    static Opportunity opp1;
    static Opportunity opp2;
    static Account acc;
    static Contact con;
    static Quote objQuote;
    static Quote objQuoteChild;
    static MSA_Quote_Trade_In_Product__c objTradeIn;
    static Quotelineitem objQuoteItem;
    static PricebookEntry pbook;
    static Product2 p;
    


    static void insertData(){
        acc=new Account();
        acc.Name='Test Health';
        acc.External_ID__c='1456';
        
        insert acc;
        
        opp=new Opportunity();
        opp.AccountId=acc.id;
        opp.Name='Test Opp';
        opp.Stagename='S5 Nurture';
        opp.CloseDate=Date.Today();
        opp.Promo_Opportunity__c=true;
        opp.type='New Business';
        insert Opp;
        
        opp1=new Opportunity();
        opp1.AccountId=acc.id;
        opp1.Name='Test Opp';
        opp1.Stagename='S5 Nurture';
        opp1.CloseDate=Date.Today();
        opp1.Promo_Opportunity__c=true;
        opp1.type='New Business';
        insert Opp1;
        
        opp2=new Opportunity();
        opp2.AccountId=acc.id;
        opp2.Name='Test Opp';
        opp2.Stagename='S5 Nurture';
        opp2.CloseDate=Date.Today();
        opp2.Promo_Opportunity__c=true;
        opp2.type='New Business';
        insert opp2;
        
        p=new Product2();
        p.name='Test';
        p.ProductCode=Label.MSA_Add_On_Applicator;
        p.family='Systems';
        p.MSA_Is_Discountable__c=true;
        p.isactive=true;
        insert p;
        
        ID standardPBID = Test.getStandardPricebookId();
        
        PricebookEntry standardPrice = new PricebookEntry(
            Pricebook2Id =standardPBID , Product2Id = p.Id,
            UnitPrice = 10000, IsActive = true);
        insert standardPrice;
        
        Pricebook2 PB=NEW Pricebook2();
        PB.NAME='AM USA';
        pb.isactive=true;
        INSERT pb;
        
        pbook=new PricebookEntry();
        pbook.Product2Id=p.id;
        pbook.unitprice=100;
        pbook.CurrencyIsoCode='USD';
        PBOOK.Pricebook2id=pb.id;
        PBOOK.Pricebook2=pb;
        PBOOK.isactive=true;
        insert pbook;        
        
        objQuote=new Quote();
        objQuote.NAME='TEST1';
        objQuote.opportunityid=Opp.id;
        objQuote.Pricebook2Id=pb.id;
        objQuote.MSA_System_Trade_In_Value__c=100;
        objQuote.MSA_Cards_Trade_In_Value__c=100;
        objQuote.MSA_Of_Multi_Location__c = 10;
        insert objQuote;

        objQuoteChild=new Quote();
        objQuoteChild.NAME='TEST2';
        objQuoteChild.opportunityid=Opp1.id;
        objQuoteChild.MSA_Parent_Quote__c=objQuote.id;
        objQuoteChild.Pricebook2Id=pb.id;
        objQuoteChild.MSA_Payment_Term__c='Prepaid';      
        objQuoteChild.MSA_Down_Payment_Method__c='Check';
        objQuoteChild.MSA_Multi_System_Same_Sold_To__c=true;
        objQuoteChild.MSA_System_Trade_In_Value__c=100;
        objQuoteChild.MSA_Cards_Trade_In_Value__c=100;
        
        insert objQuoteChild;
        
        Quote objQuoteChild2=new Quote();
        objQuoteChild2.NAME='TEST3';
        objQuoteChild2.opportunityid=opp2.id;
        objQuoteChild2.MSA_Parent_Quote__c=objQuote.id;
        objQuoteChild2.Pricebook2Id=pb.id;
        objQuoteChild2.MSA_Multi_System_Same_Sold_To__c=true;
        objQuoteChild2.MSA_System_Trade_In_Value__c=100;
        objQuoteChild2.MSA_Cards_Trade_In_Value__c=100;
        
        insert objQuoteChild2;   
        
        objTradeIn=new MSA_Quote_Trade_In_Product__c();
        objTradeIn.Name='Test';
        objTradeIn.MSA_Product_Name__c='Test';
        objTradeIn.MSA_Quantity_Cycle_For_Return__c=1;
        objTradeIn.MSA_Total_Trade_In_Value__c=100;
        objTradeIn.MSA_Quote__c=objQuoteChild.id;
        insert objTradeIn;
        
        objTradeIn=new MSA_Quote_Trade_In_Product__c();
        objTradeIn.Name='Test';
        objTradeIn.MSA_Product_Name__c='Test';
        objTradeIn.MSA_Quantity_Cycle_For_Return__c=1;
        objTradeIn.MSA_Total_Trade_In_Value__c=100;
        objTradeIn.MSA_Quote__c=objQuote.id;
        insert objTradeIn;
        
        objQuoteItem=new QuoteLineitem();
        objQuoteItem.PricebookEntryId=pbook.id;
        objQuoteItem.Quoteid=objQuoteChild.id;
        objQuoteItem.Product2Id=p.id;
        objQuoteItem.Quantity=1;
        objQuoteItem.UnitPrice=decimal.valueof(Label.MSA_New_Business_Applicator_Value);
        //insert objQuoteItem;     
        
    }
    
    @isTest(SeeAllData=false)
    static void testUpdatePayment() {        
        insertData();          
        Test.StartTest();        
        objQuote.MSA_Payment_Term__c='Prepaid';      
        objquote.MSA_Down_Payment_Method__c='Check';
        update objQuote;        
        Test.StopTest();                       
    }
    @isTest(SeeAllData=false)
    static void testSyncQuote() {        
        insertData();          
        Test.StartTest();        
        opp1.SyncedQuoteId =objQuoteChild.id;
        update opp1; 
        objQuoteItem=new QuoteLineitem();
        objQuoteItem.PricebookEntryId=pbook.id;
        objQuoteItem.Quoteid=objQuoteChild.id;
        objQuoteItem.Product2Id=p.id;
        objQuoteItem.Quantity=1;
        objQuoteItem.UnitPrice=decimal.valueof(Label.MSA_New_Business_Applicator_Value);
        //insert objQuoteItem;         
     
        objQuoteItem=new QuoteLineitem();
        objQuoteItem.PricebookEntryId=pbook.id;
        objQuoteItem.Quoteid=objQuote.id;
        objQuoteItem.Product2Id=p.id;
        objQuoteItem.Quantity=1;
        objQuoteItem.UnitPrice=decimal.valueof(Label.MSA_New_Business_Applicator_Value);
        //insert objQuoteItem;    
    
        //CS_MSA_QuoteHandler.createSoldToQLIAndTradeInProducts(new List<Quote>{objQuoteChild});        
              
        Test.StopTest();          
    }
    
    @isTest(SeeAllData=false)
    static void testSyncQuote2() {        
        insertData();          
        Test.StartTest();        
        CS_MSA_QuoteHandler.updateParentQuoteApprovalStatus(new List<Quote>{objQuoteChild});
        Test.StopTest();   
    }
    
    
    
    @isTest(SeeAllData=false)
    static void testupdateQuoteDeleteOperation() {        
        insertData();          
        Test.StartTest();        
        CS_MSA_QuoteHandler.updateQuoteDeleteOperation(new List<Quote>{objQuoteChild});        
        Test.StopTest();   
    }
}
Hi folks,

the below is test class . Currently it has 33% code coverage. Please help me to get 75% 

@isTest
public class AccountTriggerHandlerTest {
    
    static testMethod void tester(){
        CS_StaffCycleReimbursementCtrl.QuarterWrapper[] quarters = CS_StaffCycleReimbursementUtil.getQuarters();
        CS_StaffCycleReimbursementCtrl.QuarterWrapper currQuarter = CS_StaffCycleReimbursementUtil.getCurrentQuarter(quarters);
        CS_StaffCycleReimbursementCtrl.QuarterWrapper lastQuarter = CS_StaffCycleReimbursementUtil.getLastQuarter(quarters);

        Country__c country = new Country__c(
            Name = 'US',
            Area_Sales_Manager__c = UserInfo.getUserId()
        );
        insert country;

        Account acc = new Account(Name = 'test', ShippingCountry = 'US', Territory_Override__c = true,External_ID__c='1555', OwnerId = UserInfo.getUserId());
        insert acc;

        acc = [SELECT Id, OwnerId FROM Account WHERE Id = :acc.Id];
        System.assertEquals(UserInfo.getUserId(), acc.OwnerId);

        User u = [SELECT Id FROM User WHERE ProfileID = :UserInfo.getProfileId() AND ID != :UserInfo.getUserId() AND IsActive = true LIMIT 1];

        insert new Allocation__c(
            User__c = UserInfo.getUserId(),
            CoolTone_Budget__c = 100,
            CoolSculpting_Budget__c = 100,
            Start_Date__c = currQuarter.startDate,
            End_Date__c = currQuarter.endDate,
            OwnerId = UserInfo.getUserId()
        );

        insert new Allocation__c(
            User__c = u.Id,
            CoolTone_Budget__c = 100,
            CoolSculpting_Budget__c = 100,
            Start_Date__c = currQuarter.startDate,
            End_Date__c = currQuarter.endDate,
            OwnerId = u.Id
        );

        Test.startTest();
            country.Area_Sales_Manager__c = u.Id;
            update country;
            acc.OwnerId = u.Id;
            update acc;

        Test.stopTest();

        acc = [SELECT ID, OwnerId FROM Account WHERE ID = :acc.Id];

        System.assertNotEquals(UserInfo.getUserId(), acc.OwnerId);
    }

}
Hi , Please help me with writing a test class by using  TestDataFactoryUtility class..


@isTest
public class CaseController_Test {
    static testMethod void testMethod1(){
        Account acc = new Account(recordtypeid = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Person Account').getRecordTypeId(),
                                  lastName = 'test', Type = 'UK');
        insert acc;
       
        Account account = new Account(recordtypeid = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Business Account').getRecordTypeId(),
                                      Name = 'test', Type = 'UK');
        insert account;
       
        Opportunity opp = new Opportunity(recordtypeid = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Commercial').getRecordTypeId(),
                                          Name = 'Test Opp',
                                          AccountId = account.id,
                                          closedate = Date.today(),
                                          Billing_City__c = 'Test',
                                          Billing_Country_Picklist__c = SObjectType.Opportunity.Fields.Billing_Country_Picklist__c.PicklistValues[0].getValue(),
                                          Billing_Postal_Code__c = 'Test',
                                          Billing_Street__c = 'Test',
                                          Shipping_City__c = 'Test',
                                          Shipping_Country_PickList__c = SObjectType.Opportunity.Fields.Billing_Country_Picklist__c.PicklistValues[0].getValue(),
                                          Shipping_Postal_Code__c = 'Test',
                                          Shipping_Street__c = 'Test',
                                          StageName = 'Qualification');
        insert opp;    
       
        Contact con = new Contact(lastName='test',email='test@test.com',phone='9632587410',accountid=account.id);
        insert con;
       
        Case c = new Case(description='test',street__c='test',city__c='test',
                          Country_Picklist__c = SObjectType.Case.Fields.Country_Picklist__c.PicklistValues[0].getValue(),
                          PostalCode__c='1236',accountid=account.id,Opportunity__c=opp.id,contactid=con.id,Maintenance_Type__c='Domestic');
        insert c;
       
        Case ca = new Case(description='test',street__c='test',city__c='test',
                           Country_Picklist__c = SObjectType.Case.Fields.Country_Picklist__c.PicklistValues[0].getValue(),
                           PostalCode__c='1236',accountid=account.id,Opportunity__c=opp.id,contactid=con.id,Maintenance_Type__c='');
        insert ca;
       
        ApexPages.StandardController sc = new ApexPages.standardController(c);
        CaseController e = new CaseController(sc);
       
        ApexPages.StandardController sco = new ApexPages.standardController(ca);
        CaseController e1 = new CaseController(sco);
       
        test.StartTest();
        Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator());
        e.createInstallCase();
        e.createMaintenanceCase();
        e1.createInstallCase();
        e1.createMaintenanceCase();
        test.StopTest();
    }
}
 
The following error occured in the trailhead challange

We can't find an attribute tag with the correct attributes on the campingListItem component.

challange name :attributes and expressions.


my code :

<aura:component >
    <aura:attribute name="item" type="Camping_Item__c" required="true"/>
    <p>Name:{!v.item.Name}</p>
    <p>Price: <lightning:formattedNumber value="{!v.item.price__c}" style="currency"/></p>
    <p>Quantity: <lightning:formattedNumber value="{!v.item.Quantity__c}"/></p>
    <p><lightning:input type="toggle" label="Packed" checked="{!v.item.Packed__c}"/></p>
</aura:component>
AcctTrigger: execution of BeforeUpdate caused by: System.SObjectException: DML statement cannot operate on trigger.new or trigger.old Trigger.AcctTrigger: line 16, column 1

My query is i want to execute the scenario with out disabling the previous trigger which I created on the account . 

Any helpful suggestions please 
Please help me to write a testclass for the below trigger

trigger RelatedRecord on Account(after insert, after update)   
 {    
   List<opportunity> opportunityList = new List<opportunity>();  
   Map<Id,Account> accountswithopp = new Map<Id,Account>();
   ([select Id,(select Id from opportunities) from Account Where Id IN :Trigger.New]);        
   for(Account acc : Trigger.New) {  
     System.debug('accountswithopp.get(acc.Id).opportunities.size()=' + accountsWithopp.get(acc.Id).opportunities.size());   
     if (accountswithopp.get(acc.Id).opportunities.size() = 0) {   
       opportunityList.add(new Opportunity(Name=acc.Name + ' opportunity',  
                     StageName='Prospecting',  
                     CloseDate=System.today().addMonths(3),  
                     AccountId=acc.Id));  
     }        
   }  
   if (opportunityList.size() > 0) {  
     insert opportunityList;  
   }
 }
AcctTrigger: execution of BeforeUpdate caused by: System.SObjectException: DML statement cannot operate on trigger.new or trigger.old Trigger.AcctTrigger: line 16, column 1

My query is i want to execute the scenario with out disabling the previous trigger which I created on the account . 

Any helpful suggestions please 

Hi,

 

We are struggling with the code coverage for the Trigger below.  The Test Class code is below as well.  Any assistance and/or guidance would be greatly appreciated!!

 

Cheers,

Bindu & Jason

 

 

TRIGGER

trigger UpdateQuote on QuoteLineItem(before insert,before update)

{

        for(QuoteLineItem qout : trigger.New )

        {          

if(qout.Product_Name__c == 'Testing Product')

            {                                                 

if(qout.Annual_Vol__c <> NULL )

                {                                       

if(qout.Annual_Vol__c >=  0 && qout.Annual_Vol__c <= 100000)

                   {                       

                      qout.UnitPrice = 350 ;           

                   }

               }

              qout.Quantity = 1 ;    

           }

     }

 }   

 

 

 

 

TEST CLASS:

@isTest
   public class UpdateQuoteTest{
    //private static testmethod void testGetters()
    
    static testMethod void UpdateQuoteTest()
    {
       // Pricebook2 standardPB = [select id from Pricebook2 limit 1];
       
        Pricebook2 pb = new Pricebook2(Name = 'Standard Price Book 2009', Description = 'Price Book 2009 Products', IsActive = true );
        insert pb;
        Product2 prod = new Product2(Name = 'Testing Product', Family = 'Best Practices', IsActive = true);
        insert prod;
         List<Pricebook2> standardPbList = [select id, name, isActive from Pricebook2 where IsStandard = true ];
     //   PricebookEntry standardPrice = new PricebookEntry(Pricebook2Id = pb.Id, Product2Id = prod.Id, UnitPrice = 10000, IsActive = true, UseStandardPrice = false);
    //    insert standardPrice;
    List<PricebookEntry> listPriceBook = new List<PricebookEntry>();
     for(Pricebook2 p : standardPbList ){
      PricebookEntry pbe = New PricebookEntry ();
      pbe = new PricebookEntry(Pricebook2Id = p.Id, Product2Id = prod.Id, UnitPrice = 10000, IsActive = true, UseStandardPrice = false);
       listPriceBook.add(pbe);
     }
        insert listPriceBook;
        Opportunity opp = new Opportunity(Name = 'Test Syndicated 2010', Type = 'Syndicated - New', StageName = 'Planning', CloseDate = system.today());
        insert opp;
        List<OpportunityLineItem> opplineList = new List<OpportunityLineItem>();
       for(PricebookEntry pricebook : listPriceBook){
            OpportunityLineItem oli = new OpportunityLineItem ();
            oli  = new OpportunityLineItem(opportunityId = opp.Id, pricebookentryId = pricebook.Id, Quantity = 1, UnitPrice = 7500, Description = '2007 CMR #4 - Anti-Infectives');
            opplineList.add(oli);
       }
       insert opplineList;
     //   List<OpportunityLineItem> olis = [Select Id From OpportunityLineItem Where OpportunityId =: opp.Id];
     //   update olis[0];
        Quote quttest = new Quote (Name = 'qoutetest' , OpportunityId = opp.id , Pricebook2Id = pb.id );
        insert quttest ;
        List<QuoteLineItem> listval = new   List<QuoteLineItem>();
        Integer Annualvalue = 1000 ;
        for(PricebookEntry pricebook : listPriceBook){
            QuoteLineItem qutlineitemtest = new QuoteLineItem ();
            qutlineitemtest = new QuoteLineItem(QuoteId = quttest .id , Quantity = 3.00 ,Annual_Vol__c = Annualvalue ,UnitPrice = 12 , PricebookEntryId = pricebook.id);
            
            listval.add(qutlineitemtest);
            Annualvalue = Annualvalue + 1000;
         }
       insert listval;
    }
}