0

Can someone help me identify what is wrong with me "saveOverview" method? I keep getting compiling error saying variable "orep" does not exist. Thanks

VF Command Button:

<apex:commandButton style="float:centre; width:75px" value="Save" action="{!SaveOverview}"/>

Controller:

//Overview
public ApexPages.StandardsetController setConOverview{
    get {
        if(setConOverview == null) {
            setConOverview = new ApexPages.StandardsetController(Database.getQueryLocator(
                  [SELECT Prevented_Breach__c
                   From CBR__c Where Id = 'a5b180000008Ocn' limit 1]));
            setConOverview.setPageSize(1);
        }
        return setConOverview;

    }
    set;

}

public List<CBR__c> getOvervieworeports() {
     return (List<CBR__c>) setConOverview.getRecords();
}

public List<overviewrepWrapper> getOvervieworeportsWithIndex() {

    List<CBR__c> overvieworeps = this.getOvervieworeports();
    List<overviewrepWrapper> OvervieworepsWrapped = new List<overviewrepWrapper>();

    Integer idex = 1;
    for (CBR__c orep : overvieworeps) {
        overvieworepsWrapped.add(new overviewrepWrapper(orep, idex));
        idex++;
    }
    return overvieworepsWrapped;

}

public class overviewrepWrapper {
    public CBR__c orep { get; set; }
    public Integer tabIndex { get; set; }
    public overviewrepWrapper(CBR__c orep, Integer tabIndex) {
        this.orep = orep;
        this.tabIndex = tabIndex;
    }
}    
public List<wrapperClass> overviewRecord{get; set;}

public void saveOverview(){
    List<CBR__c> reportToUpdate  = new List<CBR__c>();
    for(wrapperClass w : reportToUpdate){

        overviewRecord.add(w.orep);

    }
    if(overviewRecord.size() > 0){
        update overviewRecord;
    }    

}   
  • 1
    Hi user7123. welcome to SFSE! Your question is asking for other people to write code for you, without presenting a real question or issue. SFSE is a Q&A forum where we look to help each other by asking and answering questions that are real problems or errors. Posting requests to write code for you will get closed. If you post what you've written so far and where you're stuck, i'm confident you'll find plenty of people willing to assist you. – Adrian Larson Jul 30 '15 at 23:03
  • It should be <apex:commandButton style="float:centre; width:75px" value="Save" action="{!SaveOverview}"/> and you have no method SaveOverview – Eric Jul 30 '15 at 23:04
  • So, I just included by SaveOverview method. The error is w.orep variable doesn't exist. – user7123 Jul 30 '15 at 23:27
  • 1
    Little confused here, reportToUpdate is a List<CBR__c> not a wrapperClass, so first error is the field does not exist, second error will be need to iterate over a List<CBR__c>, third, the list is initialized to empty so the loop will never happen. – Eric Jul 30 '15 at 23:34
0

I think you got your properties mixed up, should it not be:

public void saveOverview(){
    List<CBR__c> reportToUpdate  = new List<CBR__c>();
    for(wrapperClass w : overviewRecord){

        reportToUpdate.add(w.orep);

    }
    if(reportToUpdate.size() > 0){
        update reportToUpdate;
    }    

}   
  • no, still doesn't compile. – user7123 Jul 30 '15 at 23:41
  • @user7123 - Thanks for the detailed response, you have additional issues then as my code will compile if everything else is correct. Think I am done here – Eric Jul 30 '15 at 23:42
0

Use this code:

public void saveOverview(){
    List<CBR__c> reportToUpdate  = new List<CBR__c>();
    List<overviewrepWrapper> wrapperList = getOvervieworeportsWithIndex();

    for(wrapperClass w : wrapperList){

        reportToUpdate.add(w.orep);

    }
    if(overviewRecord.size() > 0){
        update overviewRecord;
    }    
}  

Some suggestions:

  1. It seems to me that you don't need a standardSetController in this case.

  2. As Adrian Larson has stated, be a little more specific about your question. As an example of this one, you can say, how to save a list of records from a list of wrapper objects. For me, it cost me a while to figure out what your issue is, not how to resolve it.

  • You can't add a CBR__c (w.orep is a CBR__c) to a List<wrapperClass> - We are all confused here, but between both our responses lies the answer. Hard to get a correct one with the code posted – Eric Jul 30 '15 at 23:38
  • @Eric ah, you are right. I will update the code. – Lance Shi Jul 30 '15 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.