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
Brian Cherry FWIBrian Cherry FWI 

Multiple Related List Records Add

public class AddingLineItemsController {
    public List<Professional_Services_Partner_Line_Items__C> LineItems {get;set;}
    public Integer rowNum{get;set;}
    public  AddingLineItemsController (){
        LineItems = new List<Professional_Services_Partner_Line_Items__c>();  
        LineItems.add(new Professional_Services_Partner_Line_Items__c());      
    }
    
    public void insertLineItems(){
        LineItems.Professional_Services_Partner_Contract__c = ApexPages.currentPage().getParameters().get('cid');
        insert LineItems;
    }
    
    public void insertRow(){
        LineItems.add(new Professional_Services_Partner_Line_Items__c()); 
    }
    
    public void delRow(){
        rowNum = Integer.valueOf(apexpages.currentpage().getparameters().get('index'));
        LineItems.remove(rowNum);   
    }
}

Above is my class. What I'm trying to accomplish is for the url parameter cid = Professional_Services_Partner_Contract__c for every row that is inserted. I keep getting this error: Error: Compile Error: Initial term of field expression must be a concrete SObject: List<Professional_Services_Partner_Line_Items__c> at line 10 column 9. Can anyone point me in the right direction?

Best,
Brian
 
povery.sf@gmail.compovery.sf@gmail.com
LineItems is an array... You'll need something like:

LineItems[0] = new Professional_Services_Partner_Line_Items__C();
LineItems[0].Professional_Services_Partner_Contract__c = ...
Brian Cherry FWIBrian Cherry FWI
Awesome thanks, it appears to work for 1 record, but not mutliples though. It creates them it just doesn't reference the cid for the Contract__C
povery.sf@gmail.compovery.sf@gmail.com
I'm not sure exactly what you're trying to accomplish... You might just want to add the contract to the last row added?

For that you might do something like this:

Integer size = LineItems.size();
if (size > 0) {
    LineItems[size-1].test_Object__c = ApexPages.currentPage().getParameters().get('cid');
}
Brian Cherry FWIBrian Cherry FWI
Basically what I’m doing is creating a multiple add page for a related list. For each row inserted from insertLineItems I want the CID populated into the Professional_Services_Partner_Contract__c field. InsertRow creates a new row in my datatable on my visualforce page below.
Andy Kallio 7Andy Kallio 7
@Brian did you figure this out? I have the same requirement. J