Ed - Two excellent doc references for you to learn from --
1) http://www.developerforce.com/guides/Visualforce_in_Practice.pdf and
2) https://www.packtpub.com/application-development/visualforce-development-cookbook
both are superb.
You have a conceptual issue in your example in that a VF page is associated with a controller (standard, standard w/ extensions, or custom) and the merge field references have to be to objects known to that controller. So, if you literally want to refer to {!ObjectA.xxx} and {!ObjectB.xxx} then the page's controller has to have either public getMethods or public getters for these specific objects. A page with standardController="ObjectA" has implicit reference to ObjectA's fields and these can be updated. But if you don't have an extension class or go the full custom controller route, ObjectB is unknown
The code that you initially provided is going about things the hard way.
My preferred method of taking care of this would be to make ObjectB__c
into a separate variable in your controller, and then use that in the visualforce binding.
public class UploadControllerVendorProdRev {
// This member variable, thedateinput, won't be needed
// public Date thedateinput {get;set;}
private objectA__c parent {get;set;}
// Declare an ObjectB__c variable to be used later
public objectB__c objBVar{get;set}
public UploadControllerVendorProdRev(ApexPages.StandardController controller) {
this.parent = (ObjectA__c)controller.getRecord();
// Here, in your controller's constructor, we need to initialize
// objBVar. If it isn't initialized here, you'd probably get a
// NullPointerException when you attempt to reference it in your page
// We can also set the value of Parent__c in the constructor for ObjectB__c
objBVar = new ObjectB__c(Parent__c = this.parent.Id);
}
}
Because we're taking care of the initialization in the controller's constructor, you don't need to do it in your saveCustomAttachment()
method any more. In fact, if you leave that initialization code in your saveCustomAttachment()
method, you'll likely run into issues (a variable redeclaration error, or perhaps the date being overwritten).
private Database.SaveResult saveCustomAttachment() {
// This initialization is taken care of in the controller's constructor
//objBVar = new ObjectB__c();
// This line was moved into the call to the constructor for ObjectB__c
// (as a parameter).
// This line is no longer needed either
//objBVar.Parent __c = parent.Id;
// We can get rid of this line by changing your Visualforce to use
// {!objBVar.Document_Date__c}
// Trying to use 'thedateinput' would cause any Date stored in
// objBVar.Document_Date__c to be overwritten.
//objBVar.Document_Date__c = thedateinput ;
// In the end, this should be the only remaining line in this method
return Database.insert(obj);
}
To tie this all together, we need to update the binding that you're using in your Visualforce page
<apex:inputfield id="someId" value="{!objBVar.Document_Date__c}" required="false"/>
The way this works is that Salesforce will first attempt to find an objBVar
in the standard controller. When it doesn't find such a variable in the standard controller, it looks for the variable in your custom controller (or controller extension).
Since we declare objBVar
as public, Salesforce has no problem finding it. The input field is then bound to the Document_Date__c
field of your objBVar
object, which will have the value from your input field after you press save
(and not a moment before that!).
Best Answer
You can bind a "tabStyle" to the page, which causes the color theme/icon to match the named tab or object tab (
Custom__Tab
orCustomObject__c
). However, this value cannot be dynamic, so you may need to use a template page or component that contains the logic you want to encapsulate for each object individually, then include that page in two other pages that have the desired tabStyle set.Common.page:
Tabstyle1.page:
Tabstyle2.page:
This "trick" works because the CSS will be dynamically selected, and all subelements will take on the appropriate color attributes.
If the page itself does not need to be styled differently, but you want to change the style of individual page blocks, you can do this as well: