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
RuleyRuley 

ID value not valid for custom object

I'm trying to setup an extension and custom page connected to the Account. I want to show related accounts in a parent child relationship.

 

Accounts

Subscriptions (Account can own 0-N subscriptions)

Subscription Products (Subscriptions can have 1-N Products)

Subscription Sites (Subscription Products can have 1-N Sites)

 

On the Subscription Products page I have a custom button that goes to my new Visualforce page. I want to display all of the accounts that are child accounts of the one that owns the subscription. To save the data I'm thinking I need to extend the standard controller for Subscription_Sites__c, but that is saying then the ID isn't valid.

Id value 0015000000WUMIe is not valid for the Subscription_Site__c standard controller

 

My Visualforce page is pretty simple right now, the first line is the following and later I'm trying to loop over the lstAllAccounts

 

<apex:page standardController="Subscription_Site__c"  extensions="SubscriptionSiteExtension">

 

 

That list is the return variable from my Extension Class.

 

public class SubscriptionSiteExtension {

private final Subscription_Site__c objSubscriptionSite;

public string newSiteAccountID {get ; set ;}

public SubscriptionSiteExtension(ApexPages.StandardController extController){
	this.objSubscriptionSite = (Subscription_Site__c)extController.getRecord();
}

public List<Account> lstAllAccounts {
	get {
		String txtSubscriptionProductID = objSubscriptionSite.Subscription_Product__c;
		
		List<Subscription_Product__c> lstSubscriptionProducts = 
			[SELECT Subscription__c
			FROM Subscription_Product__c
			WHERE ID = :txtSubscriptionProductID LIMIT 1];
		
		String txtSubscriptionID = lstSubscriptionProducts[0].Subscription__c;
			
		List<Subscription__c> lstSubscriptions = 
			[SELECT Purchasing_Account__c
			FROM Subscription__c
			WHERE ID = :txtSubscriptionID LIMIT 1];
		
		String txtAccountID = lstSubscriptions[0].Purchasing_Account__c;
		
		List<Account> lstAllAccounts = 
			[SELECT Name
         	FROM Account
        	WHERE ParentID = :txtAccountID OR ID = :txtAccountID
     		ORDER BY ParentID, Name];
		
		return lstAllAccounts;
	}
	private set;
}

}

 

 

I'm thinking if I can grab the Subscription_Product__c.ID that is all I need to get the list of accounts. Displaying them is half the battle and where I think I'm off is because I want this page to gather multiple Subscription_Site__c records and save them all at once under the Subscription_Product__c. It will be a huge time saver for the users.

 

I'm kind of new to this so I'm hoping I'm missing something simple. Any help is greatly appreciated.

bob_buzzardbob_buzzard

Visualforce pages accessed via custom buttons on detail pages have specify a standard controller of the same object.  When you click the button from the detail page, that opens the visualforce page and passes the id of the record you were viewing as the id parameter.  

 

Looking at your error message, that's an account id, not a subscription site id.  How have you defined your button?

RuleyRuley

The button is a custom button on the Subscription_Site__c object

 

LabelAdd Multiple SitesObject NameSubscription Site
NameAdd_Multiple_SitesLink EncodingUnicode (UTF-8)
BehaviorDisplay in existing window with sidebarDisplay TypeList Button
Button or Link URL/apex/Select_Sites?Id={!Account.Id}

 

What you say about it being an account ID makes sense, that is what I'm passing into the URL. So I was thinking that I would change the URL to this: apex/Select_Sites?Id={!Subscription_Product__c.Id}

 

Thinking that I needed the product it was related to, but obviously still not the same object type.

 

I then changed to this: /apex/Select_Sites?Id={!Subscription_Site__c.Id}

 

Which didn't make sense because there are no Subscription_Site__c records that exist, and sure enough that still errors.

 

I started out writing with the Account as the standard controller on my page, but I started changing that because ultimately I want to save a bunch of Subscription_Site__c records. To save them what I read sounded like that is the standard controller I need to use.

bob_buzzardbob_buzzard

So as you are passing the account id, presumably this button appears on the subscription sites related list on the account object?

 

I'd suggest you use the account standard controller, as you presumably need to set the account as the parent to all of the newly created subscription sites.   Then your extension controller can do whatever you like, including creating objects of any type.

 

 

RuleyRuley

Yes, it is on the Subscription Sites related list but it is on the Subscription Product object. The account is another couple of layers up (see the beginning of my first post).

 

So would I create the extension for the Subscription Product and then create Subscription Sites attached to it?

bob_buzzardbob_buzzard

Are you planning to use this button on more than one object view?  If that is the case, you may be better off using a custom controller rather than trying to extend a standard controller.  That way you can name your parameters according to type.

 

If you are only going to use this from the subscription product, then yes, you should use the subscription product standard controller and an extension controller that can create the subscription sites "parented" by the product.