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
watanabe2watanabe2 

id record pass and field update

I've built a simple two screen Visualforce sequence on an opportunity.

The first Visualforce page is used to upload documents to the opportunity.

 

This is the second VF page, used to update a field on the opportunity.

<apex:page standardController="opportunity" extensions="Digilant_UpdateRating" showHeader="true" sidebar="true">
    <apex:form >
    
    <apex:pageBlock >
        <apex:pageBlockButtons >
            <apex:commandButton value="Notify Sales" Action="{!saveRating}"/>
            <apex:commandButton value="Cancel" Action="{!cancel}"/>
            </apex:pageBlockButtons>
        <apex:pageBlockSection title="Select Rating" columns="1">    
            <apex:inputField value="{!opportunity.Rating__c}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
    
    </apex:form>
</apex:page>

 

The controller should retrieve set the recId property from a URL parameter, use this to execute a SOQL query, and then update the retrieved record. However, the value is not getting pushed to the record and the update is failing. No error message is being generated.

 

This is the controller code.

public class Digilant_UpdateRating
{
    public Id recId{get;set;}
    public PageReference pr{get;set;}
    public ApexPages.StandardController ctrl;
    public opportunity opp;

    public Digilant_UpdateRating(ApexPages.StandardController controller) {
        ctrl = controller;
        recId = ApexPages.CurrentPage().getParameters().get('opportunityid');
        this.opp = [SELECT Id, rating__c FROM Opportunity WHERE Id =: recId];
        System.debug('opportunity is' + opp.id);
    }
    
    public pageReference saveRating()
    {
        update opp;
        pr = new PageReference('/'+recId);
        pr.setRedirect(true);
        return pr;
    }
}

 

 

Best Answer chosen by Admin (Salesforce Developers) 
pigginsbpigginsb

Your input field points to Rating__c on the opportunity in the standard controller... <apex:inputField value="{!opportunity.Rating__c}"/>

 

Even if you get the correct Id, your update does not apply to the opportunity in the standard controller. Instead you are updating the opportunity from your query.

 

You could try changing your input field to <apex:inputField value="{!opp.Rating__c}"/>, so that it points to the property in your extension.

 

But it still wouldn't help with your url parameter. What is it that initally puts the "opportunityId" as a parameter?

All Answers

pigginsbpigginsb

Can you retrieve the opportunityId from the standard controller?

 

crtl.getId();

watanabe2watanabe2

crtl.getId() retrieves null because the visualforce page has been linked to via a page reference redirect from the initial visualforce page

 

pigginsbpigginsb

Your input field points to Rating__c on the opportunity in the standard controller... <apex:inputField value="{!opportunity.Rating__c}"/>

 

Even if you get the correct Id, your update does not apply to the opportunity in the standard controller. Instead you are updating the opportunity from your query.

 

You could try changing your input field to <apex:inputField value="{!opp.Rating__c}"/>, so that it points to the property in your extension.

 

But it still wouldn't help with your url parameter. What is it that initally puts the "opportunityId" as a parameter?

This was selected as the best answer