You need to sign in to do that
Don't have an account?

sObject type 'ServiceContacts' is not supported.
I'm trying to have a controller extension that will pull back service contracts on an account:
The contacts pull through fine. However the service contacts displays the error:
Error: Compile Error: sObject type 'ServiceContacts' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names. at line 30 column 29
My class is:
public class myAccountControllerExtension {
public Account acct { get; set;}
public List<Contact> cont { get; set;}
public List<ServiceContracts> sc { get; set;}
public myAccountControllerExtension(ApexPages.StandardController controller) {
this.acct = (Account)controller.getRecord();
getContacts(acct.id);
getServiceContacts(acct.id);
}
public void getContacts(String aid){
if(aid != null && aid instanceOf Id)
{
for(Account a : [select id,name,AccountNumber ,(SELECT Id, Name FROM Contacts WHERE Portal_User__c = true) FROM Account where id =:aid])
{
if(a.contacts!=null && a.contacts.size()>0)
{
cont = a.contacts;
system.debug('my contacts ' + cont);
}
}
}
}
public void getServiceContracts(String aid){
if(aid != null && aid instanceOf Id)
{
for(Account a : [select id,name,AccountId FROM ServiceContacts WHERE AccountId =:aid])
{
if(a.servicecontracts!=null && a.servicecontracts.size()>0)
{
sc = a.servicecontracts;
system.debug('my service contracts' + sc);
}
}
}
}
}
}
What is the reason for the error? How would I resolve this? My end goal is to have a VF page that displays specific contract fields and specific contacts.
The contacts pull through fine. However the service contacts displays the error:
Error: Compile Error: sObject type 'ServiceContacts' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names. at line 30 column 29
My class is:
public class myAccountControllerExtension {
public Account acct { get; set;}
public List<Contact> cont { get; set;}
public List<ServiceContracts> sc { get; set;}
public myAccountControllerExtension(ApexPages.StandardController controller) {
this.acct = (Account)controller.getRecord();
getContacts(acct.id);
getServiceContacts(acct.id);
}
public void getContacts(String aid){
if(aid != null && aid instanceOf Id)
{
for(Account a : [select id,name,AccountNumber ,(SELECT Id, Name FROM Contacts WHERE Portal_User__c = true) FROM Account where id =:aid])
{
if(a.contacts!=null && a.contacts.size()>0)
{
cont = a.contacts;
system.debug('my contacts ' + cont);
}
}
}
}
public void getServiceContracts(String aid){
if(aid != null && aid instanceOf Id)
{
for(Account a : [select id,name,AccountId FROM ServiceContacts WHERE AccountId =:aid])
{
if(a.servicecontracts!=null && a.servicecontracts.size()>0)
{
sc = a.servicecontracts;
system.debug('my service contracts' + sc);
}
}
}
}
}
}
What is the reason for the error? How would I resolve this? My end goal is to have a VF page that displays specific contract fields and specific contacts.
to do it in a single DML operation you could have the following:
NOTE: This code has not been tested and may contain typographical or logical errors.
All Answers
This information can be viewed either with a metadata describe or inside of workbench [1]
For additional information, the relationship between ServiceContract and Account is called ServiceContracts. That is why this work with your query but not with your definition of your list.
ServiceContract
Account Child Relationship
[1] https://workbench.developerforce.com/describe.php
Error: Compile Error: sObject type 'ServiceContacts' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names. at line 30 column 29
Line 30 is:
for(Account a : [select id,name,AccountId FROM ServiceContact WHERE AccountId =:aid])
I've tried ServiceContracts and ServiceContract. What is the best way for me to query the contract information for account a?
to do it in a single DML operation you could have the following:
NOTE: This code has not been tested and may contain typographical or logical errors.