You need to sign in to do that
Don't have an account?
ckahl
Save Error
I have limited apex knowledge and I'm trying to adapt this code to fit my custom objects. It worked fine until I started plugging in my custom objects. The original code is- http://visualforcemadeeasy.blogspot.com/2009/03/how-to-add-and-delete-row-in-datatable.html?showComment=1360345388003#c2926072741019740563
Here's what I have so far, but I keep getting "Save error: Variable does not exist: acct.id" I tried a couple different things to fix this, but it doesn't seem to work. Any ideas?
public class TimeOffAccountController { /* I set the Time Off Account and Time Off Request Objects here for use through out the code*/ public Time_Off_Account__c TOA { get; private set;} public time_off_request__c[] requestItems { get; private set; } private ApexPages.StandardController controller; // constructor, loads the Time Off Account and // any Requests associated with it void requestItems(id id) { TOA = [SELECT Id, Name, Account_type__c, Account_Balance__c, Accrual_Start__c, Accrued_Hours__c, Adjusted_Hours__c, Annual_Accrual_Rate__c, Annual_Maximum__c, Available_Balance__c, Daily_Accrual_Rate__c, Employee__c, First_Date_Current_Year__c, Hours_Pending__c, Hours_Used__c, Last_Date_Current_Year__c, Maximum_Deficit__c, Maximum_Hours__c, Number_of_Days_YTD__c, Other_Accrual_Start_Date__c, Rollover_Hours__c, (SELECT Id, Name, Status__c, Begin_Date__c, End_Date__c, Number_of_Days__c, Pending__c, Pending_Check__c, Pending_Text__c, Projected_Eligible_Days__c, Projected_Hours_Accrued__c, Total_Hours__c FROM pto_requests__r) FROM time_off_account__c where id = :id limit 1]; //Hook requestItems to the query above requestItems = TOA.time_off_request__c; } //Define the id id accountid; /* A List Method to delete the Requests assigned*/ public list<time_off_request__c> todelete = new list<time_off_request__c>(); public TimeOffAccountController (ApexPages.StandardController c) { /* this will kickoff you main page */ controller = c; /* to get this current Time Off Account Id*/ accountid = c.getRecord().id; /*kick off the init() function*/ init(); } public TimeOffAccountController () { accountid = ApexPages.CurrentPage().getParameters().get('id'); init(); } void init() { /* load up Requests basically we defined requestitems up on top, so when the page loads then requestItems(accountId) will go through the query and list out the Requests assoicated with it */ requestItems(accountid); } public PageReference save() { try { upsert requestItems; if ( todelete.size() > 0 ) { delete todelete; } requestItems(acct.id); } catch ( DmlException exc) { ApexPages.addMessages(exc); return null; } return null; } /* your Delete functionality*/ public PageReference del() { string delname = ApexPages.CurrentPage().getParameters().get('delname'); system.assert( delname != null ); integer gone = -1; integer i = 0; for ( i=0; i< requestItems.size(); i++ ) { if (requestItems[i].RequestNumber== delname) { gone = i; } } if ( gone >= 0) { todelete.add(requestItems.remove(gone) ); } return null; } public PageReference add() { // insert a new line, after user clicks Add time_off_request__c tor = new time_off_request__c( AccountId = acct.id ); requestItems.add ( tor ); return null; } }
All Answers