Updating because my question was not clear:
I'm trying to override the new and save functionality of a Custom Object on Visualforce page via a controller extension.
Here's my .vfp code:
<apex:page standardController="CustomObj__c" extensions="CustomObjExtension">
<apex:form >
<apex:pageBlock title="Create a New Grouping">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{! saveNewGroup }"/>
<apex:commandButton value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection columns="1">
<apex:selectList label="Groups" value="{! CustomObj.group_id__c}" size="1">
<apex:selectOptions value="{! CommunityGroups }" />
</apex:selectList>
<apex:inputField label="Chute Album Shortcut" value="{! CustomObj.group_name__c }" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
and for my extension:
public class CustomObjExtension {
private ApexPages.StandardController controller {get; set;}
public CustomObjExtension(ApexPages.StandardController controller) {
this.controller = controller;
}
public PageReference saveNewGroup(){
//accessing CustomObj here and do things before saving
this.controller.save();
return null;
}
public List<SelectOption> getCommunityGroups() {
List<Group> groups = [SELECT Id, Name FROM Group];
List<SelectOption> options = new List<SelectOption>();
for (Group g : groups) {
if(String.isNotBlank(g.Name)){
options.add(new SelectOption(g.Id, g.Name));
}
}
return options;
}
}
Before I save the new Grouping, I want to access the CustomObj object to change some data before saving. How do I do that? I've looked at a number of documents and forums with different ways of doing it, but none of them has worked for me yet.
I tried to add a {get; set;} for the customObj but that didn't seem to work.
What am I missing?