So I have read other responses to the error like mines but nothing seems to fix the issue maybe someone can look at my code and help. I have in my controller class (trying to do an add and delete function for additional items assocaited with a contract). For some reason i keep getting the error: Didn't understand relationship 'Contract__r.Additional_Contract_Item__c' in field path. If you are attempting to use a custom relationship, be sure to append the '_r' after the custom relationship name. Please reference your WSDL........
Can anyone help me figure out why im getting the error what am i missing... Code below:
void contractItems(id id) {
cont = [SELECT Id, Name, Status, ContractNumber, Event__c, Contact__c,
(SELECT Id, Contract__c, Contract__r.Item_Description__c, Contract__r.Quantity__c, Contract__r.Total__c,
Contract__r.Unit_Price__c FROM Contract__r.Additional_Contract_Item__c) FROM Contract
where id = :id limit 1];
contractItems = cont.Additional_Contract_Item__c;
}
Full Code:
public with sharing class ContractsController {
public Contract cont { get; private set;}
public Additional_Contract_Item__c[] contractItems { get; private set; }
private ApexPages.StandardController controller;
// constructor, loads the Account and
// any cases associated with it
void contractItems(id id) {
cont = [SELECT Id, Contract__c, Item_Description__c, Quantity__c, Total__c,
Unit_Price__c FROM Additional_Contract_Item__c
where Contract__c = :id];
//Hook caseItems to the query above
contractItems = cont.Additional_Contract_Item__c;
/* contractItems = [SELECT Id, Contract__c, Contract__r.Item_Description__c, Contract__r.Quantity__c,
Contract__r.Total__c, Contract__r.Unit_Price__c
FROM Additional_Contract_Item__c
where Contract__c = : id]; */
}
//Define the id
id contractid;
/* A List Method to delete the Cases assigned*/
public list todelete = new list();
public ContractsController (ApexPages.StandardController c)
{
/* this will kickoff you main page */
controller = c;
/* to get this current Account Id*/
contractid = c.getRecord().id;
/*kick off the init() function*/
init();
}
public ContractsController () {
contractid =
ApexPages.CurrentPage().getParameters().get('id');
init();
}
void init() {
/* load up Cases
basically we defined caseitems up on top, so
when the page loads then caseItems(accountId)
will go through the query and list out the
Items assoicated with it */
contractItems(contractid);
}
public PageReference save() {
try {
upsert contractItems;
if ( todelete.size() > 0 ) {
delete todelete;
}
contractItems(cont.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< caseItems.size(); i++ ) {
if (contractItems[i].Contract__c== delname) {
gone = i;
}
}
if ( gone >= 0) {
todelete.add(caseItems.remove(gone) );
}
return null;
}
public PageReference add() {
// insert a new line, after user clicks Add
Additional_Contract_Item__c ac = new Additional_Contract_Item__c(
contractid = cont.id
//Subject = 'hello', Status = 'Low',
//Reason = 'Other',Origin='Low'
);
contractItems.add ( ac );
return null;
}
}