+ Start a Discussion
Jeff JobsJeff Jobs 

Need to Edit Multiple Opportunities without using recordSetVar

Hi,

 

New to VF so pardon the ignorance.

 

Let's begin with the objective:

 

I decide which Opportunities need to be edited based on specific criteria.  Then I want users to enter in deal numbers and update all the opportunities on the screens.  

 

Here is the code I have:

 

VF:

 

<apex:page controller="listDealNumbers">
<apex:form >
<apex:pageBlock title="Assign Deal Numbers">
<apex:pagemessages />
<apex:pageBlockButtons >
<apex:commandButton action="{!assign}" value="Assign"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!opportunities}" var="opp">
<apex:column headerValue="Opportunity">
<apex:outputLink value="https://cs9.salesforce.com/{!opp.Id}" target="_blank">{!Opp.Name}</apex:outputlink>
</apex:column>
<apex:column headerValue="Cha-Ching Date">
<apex:outputField value="{!opp.Cha_Ching_Date_v2__c}"/>
</apex:column>
<apex:column headerValue="Deal Number This Month">
<apex:inputField value="{!opp.Deal_Number_This_Month__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

APEX:

 

public class listDealNumbers {

public List<Opportunity> getOpportunities() {

date myDate = date.Today();
date startOfMonth = myDate.toStartOfMonth();
date startOfLastMonth = startOfMonth.addMonths(-1);
id userId = UserInfo.getUserId();

return [SELECT o.Id, o.Owner.Id, o.Name, o.Cha_Ching_Date_V2__c, o.Deal_Number_This_Month__c FROM Opportunity o
WHERE o.Cha_Ching_Date_V2__c >= :startOfLastMonth AND o.Cha_Ching_Date_V2__c < :startOfMonth AND o.Owner.Id = :userId
ORDER BY o.Cha_Ching_Date_V2__c];
}


public PageReference assign() {
return null;
}

}

 

So everything works but I'm not sure how to use the "assign" method to update the Opportunity Records.  I'd like to just say "update opportunities" but that won't work.  So please help with the missing "update" code I need in the "assign" method.  Thanks so much for any help :)

Best Answer chosen by Admin (Salesforce Developers) 
Avidev9Avidev9

You have to do lil homework on Apex and VF.

 

So here is what you are missing. You need to define the controller variables for opportuniteis so that you can collect data from page

 

public class listDealNumbers {

    public List < Opportunity > Opportunities {
        get;
        set;
    }

    public listDealNumbers() {
        Opportunities = loadOpportunities();
    }

    private List < Opportunity > loadOpportunities() {

        date myDate = date.Today();
        date startOfMonth = myDate.toStartOfMonth();
        date startOfLastMonth = startOfMonth.addMonths(-1);
        id userId = UserInfo.getUserId();

        return [SELECT o.Id, o.Owner.Id, o.Name, o.Cha_Ching_Date_V2__c, o.Deal_Number_This_Month__c FROM Opportunity o WHERE o.Cha_Ching_Date_V2__c >= : startOfLastMonth AND o.Cha_Ching_Date_V2__c < : startOfMonth AND o.Owner.Id = : userId ORDER BY o.Cha_Ching_Date_V2__c];
    }

    public PageReference assign() {
        update Opportunities;
        return null;
    }
}

 

All Answers

Avidev9Avidev9

You have to do lil homework on Apex and VF.

 

So here is what you are missing. You need to define the controller variables for opportuniteis so that you can collect data from page

 

public class listDealNumbers {

    public List < Opportunity > Opportunities {
        get;
        set;
    }

    public listDealNumbers() {
        Opportunities = loadOpportunities();
    }

    private List < Opportunity > loadOpportunities() {

        date myDate = date.Today();
        date startOfMonth = myDate.toStartOfMonth();
        date startOfLastMonth = startOfMonth.addMonths(-1);
        id userId = UserInfo.getUserId();

        return [SELECT o.Id, o.Owner.Id, o.Name, o.Cha_Ching_Date_V2__c, o.Deal_Number_This_Month__c FROM Opportunity o WHERE o.Cha_Ching_Date_V2__c >= : startOfLastMonth AND o.Cha_Ching_Date_V2__c < : startOfMonth AND o.Owner.Id = : userId ORDER BY o.Cha_Ching_Date_V2__c];
    }

    public PageReference assign() {
        update Opportunities;
        return null;
    }
}

 

This was selected as the best answer
Jeff JobsJeff Jobs

Thanks Avidev9, I'll consider myself "schooled."

 

Unfortunately, I get the following error when using your code:

 

Error: listDealNumbers Compile Error: The method LIST<Opportunity> getOpportunities() is referenced by Visualforce Page (assignDealNumbers) in salesforce.com. Remove the usage and try again. at line 3 column 30

 

Do I need to change my VF page?

Avidev9Avidev9
Backup the VF code >> Delete the Page >>save the controller >> restore the page
Jeff JobsJeff Jobs

Excellent!!  That worked!!  Thank you very much :)