function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DestinyLomasDestinyLomas 

please help with force.com workbook instructions

I am trying to fix my apex class testing code except I do not understand a way around what it is telling me to do. It tells me that in line 17, its expecting a right parenthesis, but only found a ;...however when I attempt to put a right parenthesis in it begins telling me all manor of things. It tells me that it does not expect token 'product' in the next line, that it is now expecting a close right curly bracket in line 17, etc. Please help!

 

This is my code, you will probably recognize it from the force.com workbook spring 13 release. I followed their instructions exactly:

 

@isTest

private

class TestHandleProductPriceChange {

 

  

statictestMethodvoid testPriceChange () {

  

Invoice_Statement__c Invoice = newInvoice_Statement__c(Status__c = 'Negotiating');

  

insert Invoice;

  

  

Merchandise__c[] products = new merchandise__c[]{

  

newMerchandise__c(Name = 'item 1', Description__c =

  

'test product 1', Price__c = 10,Total_Inventory__c = 10),

  

newMerchandise__c(Name = 'item 2', Description__c =

  

'test product 2', Price__c = 11,Total_Inventory__c = 10)

    };

    Insert products;

  

Line_Items__c[] LineItems = newLine_Items__c[] {

  

newLine_Items__c(Invoice_Statement__c = invoice.id,

  

Merchandise__c = products[0].price__c = 20; //raise price

    prodcts[1].price__c = 5;

//lower price

    Test.startTest();

  

update products;

    Test,stopTest();

  

    lineItems =

    [

SELECT id, unit_price__c FROM Line_items__c WHERE id IN :lineItems];

    System.assert(lineItems[0].unit_price__c ==10);

//unchanged

    System.assert(lineItems[1].unit_price__c == 5);

//changed!!

    };

  

insert lineItems;

  

    products[0].price__c = 20;

    Test.startTest();

  

update products;

    Test.stopTest ();

  

    lineItems = [

SELECT id, unit_Price__c FROMLine_Items__cWHERE id IN :lineItems];

  

  

system.assert(lineItems[0].unit_Price__c == 10);

    }

    }

 

 

 

any help would be much appreciated

jbroquistjbroquist

I've tried to clean your code up as best as possible, but there we're alot of issues. I've highlighted in red below the area that I couldn't make any sense of, hope this helps.

 

@isTest
private
class TestHandleProductPriceChange 
{ 
   static testMethod void testPriceChange() 
   {
     
      Invoice_Statement__c invoice = new Invoice_Statement__c(Status__c = 'Negotiating');
      insert invoice;
        
        
      Merchandise__c[] products = new merchandise__c[]
      {
         new Merchandise__c(Name = 'item 1', Description__c = 'test product 1', Price__c = 10,Total_Inventory__c = 10), 
         new Merchandise__c(Name = 'item 2', Description__c = 'test product 2', Price__c = 11,Total_Inventory__c = 10)
      };
      insert products;
        
      Line_Items__c[] lineItems = new Line_Items__c[]
      {
         new Line_Items__c(Invoice_Statement__c = invoice.id,
         Merchandise__c = products[0].price__c = 20; //raise price
         prodcts[1].price__c = 5;
         //lower price
      };
      
      Test.startTest();
        
      update products;
      
      lineItems = [SELECT id, unit_price__c FROM Line_items__c WHERE id IN :lineItems];
      System.assert(lineItems[0].unit_price__c == 10);
      //unchanged
      System.assert(lineItems[1].unit_price__c == 5);
      //changed!!
        
      products[0].price__c = 20;
      update products;
        
      lineItems = [SELECT id, unit_Price__c FROM Line_Items__cWHERE id IN :lineItems];
      system.assert(lineItems[0].unit_Price__c == 10);

      Test.stopTest();
   }
}

 

Let me know if you have any questions.

DestinyLomasDestinyLomas

Thankyou for the time you put into helping me. I realised that the reason it wasn't working was because I was altering the wrong section of the code. This is my first time on the discussion board. I am not sure what kudos are, however I have given them to you.

 

Once again thankyou so much for your help.