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
smillssmills 

Get fields from Parent Object in S-Control

I have written an S-Control that shows me some Opportunity info and related Account Info.  I have added it to a button on my Opportunity Layout screen.  When I click this button, I want to use the Opportunity ID from the accoaciated 'Opportunity' to get the info from the Account.

The query is:

 sforce.connection.query("SELECT Id, StageName, Core_Consumer_Rep__c, Core_PhPromo_Rep__c, Account.Id, Account.Name, Account.Lead_Core_Consumer__c, Account.Lead_Core_PhPromo__c FROM Opportunity WHERE StageName='Pending' AND Id = ?????????   LIMIT 20", callback);

So how do I get the Id value of the Opportunity that I clicked the button from?
smillssmills
I figured it out, I am using 'Account.Id = '{!Account.Id}'

Where is this documented?

Plus, is there a way for me to have this run only once, or have a counter to show how many times the button was clicked? 

Last question, I don't want a new screen to open up, I just want the code to run and update some values within the current opportunity.  I tried making the s-control a snippet, but then I couldn't link it to the button.  What is the correct approach for that?
Always ThinkinAlways Thinkin
Hi Smills,
If you're trying to update information on the current screen, an inline s-control can be useful to retrieve information from the related Account and either display it in the inline s-control's output (if you don't need to report on it) or update the fields in the Opp (if you do need reporting).

The only aspect of that about which I'm uncertain is how to ensure that the updates are made and displayed in the Opp before the page is loaded and viewed.

Another option for updating the fields is Workflow Rules with a Field Update. This is a little more limited since you can't invoke Retrieve calls across objects, but it's a useful way to make simpler field updates based on predetermined criteria.