+ Start a Discussion
TRossiTRossi 

Newbie question (forms and controller extension)

Hello,

I'm very new to salesforce, so hopefully this will be very easy. I would like to update the value of the "Status" of  CampaignMembers from the Lead detail page (thus I want to add a section with a visualforce page in the Lead pagelayout).

 

So far I've developed this extension for the Lead StdController (it loads the Campaign Members which correspond to the lead I am visualizing in the page). As you see I'm missing to overwrite the save() function, because i can't figure out how to get the edited values from the page.

public class CMintoLeadExtension {

    private final Lead lead;
    private final List<CampaignMember> cmlist;    
   
    public CMintoLeadExtension(ApexPages.StandardController stdController) {
        this.lead = (Lead)stdController.getRecord();
        this.cmlist = getCampaignmembers();        
    }

    public List<CampaignMember> getCampaignmembers() {
        List<CampaignMember> CM = [SELECT id,Campaign.Name,Lead.Name,Status FROM CampaignMember WHERE LeadId =:lead.id];
        return CM;
    }
   
    public PageReference save() {
        //prendere la lista editata dalla pagina e lanciarla sul DB
         
        Database.update(cmlist);
        return null;

    }
}

 Then I have this visualforce page, which enables the inLine editing:

<apex:page standardController="Lead" extensions="CMintoLeadExtension"> 

     <apex:form >
         <apex:pageBlock mode="inlineEdit">
         <apex:pageBlockTable value="{!campaignmembers}" var="o">    
            <apex:inlineEditSupport showOnEdit="saveButton, cancelButton" hideOnEdit="editButton" event="ondblclick" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>    
            <apex:column value="{!o.Campaign.name}"/>
            <apex:column value="{!o.Lead.Name}"/>
            <apex:column value="{!o.Status}"/>
         </apex:pageBlockTable>
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}" id="saveButton" />
                <apex:commandButton value="Cancel" action="{!cancel}" id="cancelButton" />
            </apex:pageBlockButtons>
         </apex:pageBlock >
     </apex:form>
    
</apex:page>

 The page displays fine, I can see the Campaign Members which are in a relationship with the current Lead, but of course the "Save" button doesn't work.

 

Could you please help me? I sense it should not be difficult, it's just a form:) I need to get the values from the form, in my mind the save function in the extension should be:

 

save(){

    take the modified set from the form;

    update the modified set;

}

 

it would be nice to update only the values that are different, but also taking the whole bunch of values and updating will do.

 

Thanks for you help! Any advice is welcome.

Thomas

    

stcforcestcforce

i think you need a set method. These are called prior to the action methods and ensure they are using the current values based on the vf page. (get and sets usually in pairs). i could be wrong - it has happened before.