+ Start a Discussion
kathybbkathybb 

expecting right curly bracket, found 'for' error in test class

I'm trying to write a test class, but I keep getting this error message.  Here's my code:

@isTest
public class Test_AttachPRTOPOExtension_Final{
    static testmethod void Test_Attachment_process() {
        SFDC_Purchase_Order__c myOrder = new SFDC_Purchase_Order__c();
        List<SFDC_Purchase_Requisition__c> RequestsToUpdate = new List<SFDC_Purchase_Requisition__c>();
        List<SFDC_Purchase_Items__c> ItemsToUpdate = new List<SFDC_Purchase_Items__c>();
        //Instatiate Controllers
        
        ApexPages.StandardController con = new ApexPages.StandardController(myOrder);
        AttachPRTOPOExtension ext = new AttachPRTOPOExtension(con);
          
        // create items
        List<SFDC_Purchase_Items__c> newItems= new List<SFDC_Purchase_Items__c>();
        for(integer i=0;i<100;i++){
            SFDC_Purchase_Items__c thisitem = new SFDC_Purchase_Items__c(name ='item '+ i);
            newItems.add(thisItem);
        }	//end for
        if(newItems.size() != 100){
            system.debug('newItems <> 100'+ newItems.size());
                } else {		//end if
        system.assertEquals(newItems.size(),100);
                }		// end else
        try {
            Database.SaveResult[] sriList = database.insert(newItems);
            for (Database.SaveResult sri : sriList) {
    			if (sri.isSuccess()) {
        // Operation was successful, so get the ID of the record that was processed
        System.debug('Successfully inserted item. Item ID: ' + sri.getId());
    } else {
        // Operation failed, so get all errors                
        for(Database.Error err : sri.getErrors()) {
            System.debug('The following error has occurred.');                    
            System.debug(err.getStatusCode() + ': ' + err.getMessage());
            System.debug('Item fields that affected this error: ' + err.getFields());
        }		// end inner for
    }			// end else
}				// 3ne outer for
        } catch (DMLEXCEPTION e){
            system.debug('insertItems failed: ' + e);
                         }	//end catch
		List<SFDC_Purchase_Order__c> newOrders = new List<SFDC_Purchase_Order__c>();
        date newDate= date.today();
        ID myPurchaser = [select id from User where  has_purchasing_authority__c = true Limit 1] ;
        ID myApprover = [select id from User where (has_approval_authority__c = true) and (has_purchasing_authority__c = false) Limit 1] ;
        List<SFDC_Purchase_Requisition__c> newReqs= new List<SFDC_Purchase_Requisition__c>();
       
        for(integer i=0;i<100;i++){
            SFDC_Purchase_Requisition__c thisReq = new SFDC_Purchase_Requisition__c(status__c = 'Sent to Purchaser',Department__c = 'Dev CR',Quantity__c = i,
                Item_requested__c = newItems[i].id, Approver__c = myApprover, Purchaser__c = myPurchaser); 
            newReqs.add(thisReq);
        }
        if(newReqs.size() != 100){
            system.debug('newIReqs <> 100'+ newReqs.size());
                } else {
        system.assertEquals(newReqs.size(),100);
                }
        Set<string> ReqSet = new Set<string>();
           try {
            Database.SaveResult[] srrList = database.insert(newReqs);
            for (Database.SaveResult srr : srrList) {
    if (srr.isSuccess()) {
        ReqSet.add(srr.getId());
        // Operation was successful, so get the ID of the record that was processed
        System.debug('Successfully inserted Requisition. Requisition ID: ' + srr.getId());
    } else {
        // Operation failed, so get all errors                
        for(Database.Error err1 : srr.getErrors()) {
            System.debug('The following error has occurred.');                    
            System.debug(err.getStatusCode() + ': ' + err.getMessage());
            System.debug('Requisition fields that affected this error: ' + err.getFields());
        }		//end inner for
    }		//end else
}			// end  outer for
        } catch (DMLEXCEPTION e){
            system.debug('insertReqs failed: ' + e);
        }
         List<SFDC_Purchase_Requisition__c> AllReqs = new List<SFDC_Purchase_Requisition__c>(AttachPRTOPOExtension.m_requestQuery);               }

        // create Orders

        

    for(integer o=0;o < 20; o++){
            SFDC_Purchase_Order__c anOrder = new SFDC_Purchase_Order__c(PO_notes__c = 'note number '+ o, Ship_To_Location__c= 'Cedar Rapids Office',
                                                                        Category = 'Dev CR', Expedite= true,
                                                                        PO_Date__c = newDate);
            newOrders.add(anOrder);
        }
    Test.startTest();
    	Set<string> OrderSet = new Set<string>();
        integer placeInList = 0;
        for(myOrder : newOrders){
            OrderSet.add(myOrder.id);
            myOrder = (SFDC_PurchaseOrder__c)myOrder;
            holdPage = SavePO();
            if(holdPage.URLfor = AttachPRTOPOExtension.m_DetailPage.urlFor){
                AssertNotEquals(AttachPRTOPOExtension.m_currentID, null);}
                AssertNotEquals(AttachPRTOPOExtension.m_resultList.size(), 0);
                for(AttachPRTOPOExtension.tempPR myReq : AttachPRTOPOExtension.m_resultList){
                    myReq = (AttachPRTOPOExtension.tempPR)myReq;
                    for(x=PlaceInList : x<PlaceInList+5 :x++){
                        myReq.selected = true;
                    }
                    PlaceInList++; 
                    AttachPRTOPOExtension.processSelected();
                    AssertEquals(AttachPRTOPOExtension.m_resultList.size(),5);
                    holdPage=AttachPRTOPOExtension.FinalizePO();
                    AssertEquals(ApexPage.currentPage().getURL(),AttachPRTOPOExtension.m_DetailPageROURL + AttachPRTOPOExtension.m_currentId)
                        }  //end inner for
						
                }  //end outer for
            Test.stoptest();
    List<SFDC_Purchase_Order__c> checkPOs = new List<SFDC_Purchase_Order__c>([select id,name,PO_Notes__c,
                                                                    PO_Date__c,Category__c, numRequisitions__c,
                                                                    Total_Price__c, Status__c,Ship_To_Location__c,
                                                                    Expedite__c, Finalized__c from
                                                                    Purchase_Order__c where id in OrderSet];
                                                                             for(SFDC_Purchase_Order__c myOrder : checkPOs){
                                                                                 AssertEquals(Status__c,'Placed');
                                                                                 AssertEquals(Finalized__c,'Placed');
                                                                                 AssertEquals(numRequisitions, 5);
                                                                                 AssertEquals(Expedite, false);
                                                                             }
    List<SFDC_Purchase_Requisitions__c> checkPRs= new List<SFDC_Purchase_Requisitions__c>([select Department__c,
                                                                                            Status__c,Approver__c,
                                                                                            Purchaser__c, Purchase_Order__c,
                                                                                            Quantity__c,Price_per_Unit__c,
                                                                                            Expedite__c,Editable__c,Finalized__c,
                                                                                            Item_Requested__c from SFDC_Purchase_Requisitions__c 
                                                                                            where id in ReqSet Order by Purchase_Order__c Limit 100]);
                                                                             for(SFDC_Purchase_Requisitions__c myReq : checkPRs){
                                                                                 AssertEquals(Status__c,'Sent to Purchaser');
                                                                                 AssertEquals(Finalize__c,true);
                                                                                 AssertEquals(Editable__c, false);
                                                                                 AssertEquals(Expedite__c, false);
                                                                                 AssertNotEquals(Price_per_unit__c, 0);
                                                                                 AssertNotEquals(Quantity__c, 0);
                                                                             }		//end for
																			 }		// end Class

 I've scoured the code to find the (apparent) unmatched curly bracket, with no joy, so I'm probably doing something else wrong which is messing with the compiler.  If I put a right curly bracket on line 82, as would be obvious, it matches up with the bracket at the start of the class, the message becomes "unexpected token: for" which makes sense as it would be appearing after the bracket ending the class definition.  Can anyone offer suggestions about what is wrong and how to fix it?

Thanks in advance.

Marko LamotMarko Lamot

it seems that you are missing right curly bracket for the function

 

static testmethod void Test_Attachment_process() {
kathybbkathybb

I agree that that's what the error message seems to say.  The problem is that if I put the right curly bracket on line 82, it matches with the testmethod declaration and the error changes to ""unexpected token: for" because the compiler thinks the for  is after the end of the method.  Thank you for taking the time to look at the problem.

Sean TanSean Tan

From a high level ending the curly brace there is probably not what you want (line 81 that is). I assume the for loop underneath is part of the test method as well...

 

Try this (Sorry I've put all brackets on the new line, it helps my auto-indentation work to make sure I didn't miss one):

 

@isTest
public class Test_AttachPRTOPOExtension_Final
{
    static testmethod void Test_Attachment_process()
    {
        SFDC_Purchase_Order__c myOrder = new SFDC_Purchase_Order__c();
        List<SFDC_Purchase_Requisition__c> RequestsToUpdate = new List<SFDC_Purchase_Requisition__c>();
        List<SFDC_Purchase_Items__c> ItemsToUpdate = new List<SFDC_Purchase_Items__c>();
        //Instatiate Controllers
        
        ApexPages.StandardController con = new ApexPages.StandardController(myOrder);
        AttachPRTOPOExtension ext = new AttachPRTOPOExtension(con);
        
        // create items
        List<SFDC_Purchase_Items__c> newItems= new List<SFDC_Purchase_Items__c>();
        for(integer i=0;i<100;i++)
        {
            SFDC_Purchase_Items__c thisitem = new SFDC_Purchase_Items__c(name ='item '+ i);
            newItems.add(thisItem);
        }    //end for
        
        if(newItems.size() != 100)
        {
            system.debug('newItems <> 100'+ newItems.size());
        }
        else
        {        //end if
            system.assertEquals(newItems.size(),100);
        }
        // end else
        try
        {
            Database.SaveResult[] sriList = database.insert(newItems);
            for (Database.SaveResult sri : sriList)
            {
                if (sri.isSuccess())
                {
                    // Operation was successful, so get the ID of the record that was processed
                    System.debug('Successfully inserted item. Item ID: ' + sri.getId());
                }
                else
                {
                    // Operation failed, so get all errors                
                    for(Database.Error err : sri.getErrors())
                    {
                        System.debug('The following error has occurred.');                    
                        System.debug(err.getStatusCode() + ': ' + err.getMessage());
                        System.debug('Item fields that affected this error: ' + err.getFields());
                    }        // end inner for
                }            // end else
            }                // 3ne outer for
        }
        catch (DMLEXCEPTION e)
        {
            system.debug('insertItems failed: ' + e);
        }    //end catch
        
        List<SFDC_Purchase_Order__c> newOrders = new List<SFDC_Purchase_Order__c>();
        date newDate= date.today();
        ID myPurchaser = [select id from User where  has_purchasing_authority__c = true Limit 1] ;
        ID myApprover = [select id from User where (has_approval_authority__c = true) and (has_purchasing_authority__c = false) Limit 1] ;
        List<SFDC_Purchase_Requisition__c> newReqs= new List<SFDC_Purchase_Requisition__c>();
        
        for(integer i=0;i<100;i++)
        {
            SFDC_Purchase_Requisition__c thisReq = new SFDC_Purchase_Requisition__c(status__c = 'Sent to Purchaser',Department__c = 'Dev CR',Quantity__c = i,
            Item_requested__c = newItems[i].id, Approver__c = myApprover, Purchaser__c = myPurchaser);
            newReqs.add(thisReq);
        }
        
        if(newReqs.size() != 100)
        {
            system.debug('newIReqs <> 100'+ newReqs.size());
        }
        else
        {
            system.assertEquals(newReqs.size(),100);
        }
        Set<string> ReqSet = new Set<string>();
        try
        {
            Database.SaveResult[] srrList = database.insert(newReqs);
            for (Database.SaveResult srr : srrList)
            {
                if (srr.isSuccess())
                {
                    ReqSet.add(srr.getId());
                    // Operation was successful, so get the ID of the record that was processed
                    System.debug('Successfully inserted Requisition. Requisition ID: ' + srr.getId());
                }
                else
                {
                    // Operation failed, so get all errors                
                    for(Database.Error err1 : srr.getErrors())
                    {
                        System.debug('The following error has occurred.');                    
                        System.debug(err.getStatusCode() + ': ' + err.getMessage());
                        System.debug('Requisition fields that affected this error: ' + err.getFields());
                    }        //end inner for
                }        //end else
            }            // end  outer for
        }
        catch (DMLEXCEPTION e)
        {
            system.debug('insertReqs failed: ' + e);
        }
        List<SFDC_Purchase_Requisition__c> AllReqs = new List<SFDC_Purchase_Requisition__c>(AttachPRTOPOExtension.m_requestQuery);                   
        
        // create Orders                    
        for(integer o=0;o < 20; o++)
        {
            SFDC_Purchase_Order__c anOrder = new SFDC_Purchase_Order__c(PO_notes__c = 'note number '+ o, Ship_To_Location__c= 'Cedar Rapids Office',
            Category = 'Dev CR', Expedite= true,
            PO_Date__c = newDate);
            newOrders.add(anOrder);
        }
        
        Test.startTest();
        Set<string> OrderSet = new Set<string>();
        integer placeInList = 0;
        
        for(myOrder : newOrders)
        {
            OrderSet.add(myOrder.id);
            myOrder = (SFDC_PurchaseOrder__c)myOrder;
            holdPage = SavePO();
            
            if(holdPage.URLfor = AttachPRTOPOExtension.m_DetailPage.urlFor)
            {
                AssertNotEquals(AttachPRTOPOExtension.m_currentID, null);
            }
            AssertNotEquals(AttachPRTOPOExtension.m_resultList.size(), 0);
            for(AttachPRTOPOExtension.tempPR myReq : AttachPRTOPOExtension.m_resultList)
            {
                myReq = (AttachPRTOPOExtension.tempPR)myReq;
                for(x=PlaceInList : x<PlaceInList+5 :x++)
                {
                    myReq.selected = true;
                }
                PlaceInList++;
                AttachPRTOPOExtension.processSelected();
                AssertEquals(AttachPRTOPOExtension.m_resultList.size(),5);
                holdPage=AttachPRTOPOExtension.FinalizePO();
                AssertEquals(ApexPage.currentPage().getURL(),AttachPRTOPOExtension.m_DetailPageROURL + AttachPRTOPOExtension.m_currentId)
            }  //end inner for
            
        }  //end outer for
        Test.stoptest();
        List<SFDC_Purchase_Order__c> checkPOs = new List<SFDC_Purchase_Order__c>([select id,name,PO_Notes__c,
        PO_Date__c,Category__c, numRequisitions__c,
        Total_Price__c, Status__c,Ship_To_Location__c,
        Expedite__c, Finalized__c from
        Purchase_Order__c where id in OrderSet];
        for(SFDC_Purchase_Order__c myOrder : checkPOs)
        {
            AssertEquals(Status__c,'Placed');
            AssertEquals(Finalized__c,'Placed');
            AssertEquals(numRequisitions, 5);
            AssertEquals(Expedite, false);
        }
        List<SFDC_Purchase_Requisitions__c> checkPRs= new List<SFDC_Purchase_Requisitions__c>([select Department__c,
        Status__c,Approver__c,
        Purchaser__c, Purchase_Order__c,
        Quantity__c,Price_per_Unit__c,
        Expedite__c,Editable__c,Finalized__c,
        Item_Requested__c from SFDC_Purchase_Requisitions__c
        where id in ReqSet Order by Purchase_Order__c Limit 100]);
        for(SFDC_Purchase_Requisitions__c myReq : checkPRs)
        {
            AssertEquals(Status__c,'Sent to Purchaser');
            AssertEquals(Finalize__c,true);
            AssertEquals(Editable__c, false);
            AssertEquals(Expedite__c, false);
            AssertNotEquals(Price_per_unit__c, 0);
            AssertNotEquals(Quantity__c, 0);
        }        //end for
    }
}        // end Class

 

Sfd developerSfd developer

Hi,

 

Try this,

 

@
isTest
public class Test_AttachPRTOPOExtension_Final {

static testmethod void Test_Attachment_process() {
SFDC_Purchase_Order__c myOrder = new SFDC_Purchase_Order__c();
List < SFDC_Purchase_Requisition__c > RequestsToUpdate = new List < SFDC_Purchase_Requisition__c > ();
List < SFDC_Purchase_Items__c > ItemsToUpdate = new List < SFDC_Purchase_Items__c > ();
//Instatiate Controllers

ApexPages.StandardController con = new ApexPages.StandardController(myOrder);
AttachPRTOPOExtension ext = new AttachPRTOPOExtension(con);

// create items
List < SFDC_Purchase_Items__c > newItems = new List < SFDC_Purchase_Items__c > ();
for (integer i = 0; i < 100; i++) {
SFDC_Purchase_Items__c thisitem = new SFDC_Purchase_Items__c(name = 'item ' + i);
newItems.add(thisItem);
} //end for
if (newItems.size() != 100) {
system.debug('newItems <> 100' + newItems.size());
} else { //end if
system.assertEquals(newItems.size(), 100);
} // end else
try {
Database.SaveResult[] sriList = database.insert(newItems);
for (Database.SaveResult sri: sriList) {
if (sri.isSuccess()) {
// Operation was successful, so get the ID of the record that was processed
System.debug('Successfully inserted item. Item ID: ' + sri.getId());
} else {
// Operation failed, so get all errors
for (Database.Error err: sri.getErrors()) {
System.debug('The following error has occurred.');
System.debug(err.getStatusCode() + ': ' + err.getMessage());
System.debug('Item fields that affected this error: ' + err.getFields());
} // end inner for
} // end else
} // 3ne outer for
} catch (DMLEXCEPTION e) {
system.debug('insertItems failed: ' + e);
} //end catch
List < SFDC_Purchase_Order__c > newOrders = new List < SFDC_Purchase_Order__c > ();
date newDate = date.today();
ID myPurchaser = [select id from User where has_purchasing_authority__c = true Limit 1];
ID myApprover = [select id from User where(has_approval_authority__c = true) and(has_purchasing_authority__c = false) Limit 1];
List < SFDC_Purchase_Requisition__c > newReqs = new List < SFDC_Purchase_Requisition__c > ();

for (integer i = 0; i < 100; i++) {
SFDC_Purchase_Requisition__c thisReq = new SFDC_Purchase_Requisition__c(status__c = 'Sent to Purchaser', Department__c = 'Dev CR', Quantity__c = i,
Item_requested__c = newItems[i].id, Approver__c = myApprover, Purchaser__c = myPurchaser);
newReqs.add(thisReq);
}
if (newReqs.size() != 100) {
system.debug('newIReqs <> 100' + newReqs.size());
} else {
system.assertEquals(newReqs.size(), 100);
}
Set < string > ReqSet = new Set < string > ();
try {
Database.SaveResult[] srrList = database.insert(newReqs);
for (Database.SaveResult srr: srrList) {
if (srr.isSuccess()) {
ReqSet.add(srr.getId());
// Operation was successful, so get the ID of the record that was processed
System.debug('Successfully inserted Requisition. Requisition ID: ' + srr.getId());
} else {
// Operation failed, so get all errors
for (Database.Error err1: srr.getErrors()) {
System.debug('The following error has occurred.');
System.debug(err.getStatusCode() + ': ' + err.getMessage());
System.debug('Requisition fields that affected this error: ' + err.getFields());
} //end inner for
} //end else
} // end outer for
} catch (DMLEXCEPTION e) {
system.debug('insertReqs failed: ' + e);
}
List < SFDC_Purchase_Requisition__c > AllReqs = new List < SFDC_Purchase_Requisition__c > ();

AllReq.add(ext.m_requestQuery)

for (Integer o = 0; o < 20; o++) {
SFDC_Purchase_Order__c anOrder = new SFDC_Purchase_Order__c(PO_notes__c = 'note number ' + o, Ship_To_Location__c = 'Cedar Rapids Office',
Category = 'Dev CR', Expedite = true,
PO_Date__c = newDate);
newOrders.add(anOrder);
}
}

// create Order
Test.startTest();
Set < string > OrderSet = new Set < string > ();
integer placeInList = 0;
for (myOrder: newOrders) {
OrderSet.add(myOrder.id);
myOrder = (SFDC_PurchaseOrder__c) myOrder;
holdPage = SavePO();
if (holdPage.URLfor = AttachPRTOPOExtension.m_DetailPage.urlFor) {
AssertNotEquals(AttachPRTOPOExtension.m_currentID, null);
}
AssertNotEquals(AttachPRTOPOExtension.m_resultList.size(), 0);
for (AttachPRTOPOExtension.tempPR myReq: AttachPRTOPOExtension.m_resultList) {
myReq = (AttachPRTOPOExtension.tempPR) myReq;
for (x = PlaceInList: x < PlaceInList + 5: x++) {
myReq.selected = true;
}
PlaceInList++;
AttachPRTOPOExtension.processSelected();
AssertEquals(AttachPRTOPOExtension.m_resultList.size(), 5);
holdPage = AttachPRTOPOExtension.FinalizePO();
AssertEquals(ApexPage.currentPage().getURL(), AttachPRTOPOExtension.m_DetailPageROURL + AttachPRTOPOExtension.m_currentId)
} //end inner for

} //end outer for
Test.stoptest();
List < SFDC_Purchase_Order__c > checkPOs = new List < SFDC_Purchase_Order__c > ([select id, name, PO_Notes__c,
PO_Date__c, Category__c, numRequisitions__c,
Total_Price__c, Status__c, Ship_To_Location__c,
Expedite__c, Finalized__c from
Purchase_Order__c where id in OrderSet
];
for (SFDC_Purchase_Order__c myOrder: checkPOs) {
AssertEquals(Status__c, 'Placed');
AssertEquals(Finalized__c, 'Placed');
AssertEquals(numRequisitions, 5);
AssertEquals(Expedite, false);
}
List < SFDC_Purchase_Requisitions__c > checkPRs = new List < SFDC_Purchase_Requisitions__c > ([select Department__c,
Status__c, Approver__c,
Purchaser__c, Purchase_Order__c,
Quantity__c, Price_per_Unit__c,
Expedite__c, Editable__c, Finalized__c,
Item_Requested__c from SFDC_Purchase_Requisitions__c
where id in ReqSet Order by Purchase_Order__c Limit 100
]);
for (SFDC_Purchase_Requisitions__c myReq: checkPRs) {
AssertEquals(Status__c, 'Sent to Purchaser');
AssertEquals(Finalize__c, true);
AssertEquals(Editable__c, false);
AssertEquals(Expedite__c, false);
AssertNotEquals(Price_per_unit__c, 0);
AssertNotEquals(Quantity__c, 0);
} //end for
} // end Class

Marko LamotMarko Lamot

additionaly:

 

instead

 

     for(myOrder : newOrders)

 

it should be

 

     for(SFDC_Purchase_Order__c myOrder : newOrders)