0

I'm using Custom Object and displaying the fields to be editable on the vf page. Can I update it directly on Controller class? My code is provided below:

Apex Class:

public class MyController{
     public Object items{get;set;}
     public void getValues(){
        items = [Select Id, Name, Data1 from Object where Id=:ApexPages.currentpage().getparameters().get('Id')];
     }
     public void updateValues(){
        //Do I need to query the object again???
        items = [Select Id, Name, Data1 from Object where Id=:ApexPages.currentpage().getparameters().get('Id')];
        update items;
     }
}
1

Your VF must call getValues() on pageload or on any container you are using like DIV tag or table or anthing that contains textbox with binding expression like {!items.Name}

public class MyController{
 public Object items{get;set;}
 public string name{get;set;} 
 public void getValues(){
    items = [Select Id, Name, Data1 from Object where Id=:ApexPages.currentpage().getparameters().get('Id')];
    name=items.Name; // or you can have directly have {!items.Name}
 }
 public void updateValues(){
    //Do I need to query the object again???
    items.Name=name;
    update items;
 }
}
  • I'm using {!items.name} directly in vf page. – SFDC Nov 10 '16 at 7:27

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.