You need to sign in to do that
Don't have an account?
Avik Datta
Edit record from VF page with custom controller
Currently I need your expert help to solve one requirement. Hopefully you will help me.
Requirement
One VF page which will show a list of User(Manage User) data. And user will able to update Active field from that list. Means user can uncheck Active field and save so that User will be inactive in database.
My Implementation
I have created a custom controller to fetch specific set of user data. Please find below apex code
public class ReportController{
public List<User> reportRecord{
get{
return [SELECT Name,Username,Country_Code_AZ__c,LastLoginDate,Datediffcalc__c,IsActive FROM User WHERE Datediffcalc__c > 90 and IsActive=true order by Country_Code_AZ__c];
}
set;
}
public PageReference QuickSave(){
return null;
}
}
Also created a VF page where Active field is editable, please find below page code
<apex:page controller="ReportController">
<apex:form >
<apex:pageBlock title="Users List">
<apex:commandButton value="Inactive User" action="{!Quicksave}"/>
<apex:pageBlockTable value="{!reportRecord}" var="val">
<apex:column headerValue="Name" value="{!val.Name}"/>
<apex:column headerValue="Username" value="{!val.Username}"/>
<apex:column headerValue="Country Code" value="{!val.Country_Code_AZ__c}"/>
<apex:column headerValue="LastLoginDate" value="{!val.LastLoginDate}"/>
<apex:column headerValue="Days Since Last Login" value="{!val.Datediffcalc__c}"/>
<apex:column headerValue="Active">
<apex:inputField value="{!val.IsActive }"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:commandButton value="Inactive User" action="{Quicksave}"/>
</apex:form>
</apex:page>
Problem Statement
Actually I am unable to write edit code under PageReference QuickSave() so that when user unchecked that flag and click on save , the updated value will be saved.
Please help me on the above situation or if you have any doc or video which implement same, please forward to me.
Requirement
One VF page which will show a list of User(Manage User) data. And user will able to update Active field from that list. Means user can uncheck Active field and save so that User will be inactive in database.
My Implementation
I have created a custom controller to fetch specific set of user data. Please find below apex code
public class ReportController{
public List<User> reportRecord{
get{
return [SELECT Name,Username,Country_Code_AZ__c,LastLoginDate,Datediffcalc__c,IsActive FROM User WHERE Datediffcalc__c > 90 and IsActive=true order by Country_Code_AZ__c];
}
set;
}
public PageReference QuickSave(){
return null;
}
}
Also created a VF page where Active field is editable, please find below page code
<apex:page controller="ReportController">
<apex:form >
<apex:pageBlock title="Users List">
<apex:commandButton value="Inactive User" action="{!Quicksave}"/>
<apex:pageBlockTable value="{!reportRecord}" var="val">
<apex:column headerValue="Name" value="{!val.Name}"/>
<apex:column headerValue="Username" value="{!val.Username}"/>
<apex:column headerValue="Country Code" value="{!val.Country_Code_AZ__c}"/>
<apex:column headerValue="LastLoginDate" value="{!val.LastLoginDate}"/>
<apex:column headerValue="Days Since Last Login" value="{!val.Datediffcalc__c}"/>
<apex:column headerValue="Active">
<apex:inputField value="{!val.IsActive }"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:commandButton value="Inactive User" action="{Quicksave}"/>
</apex:form>
</apex:page>
Problem Statement
Actually I am unable to write edit code under PageReference QuickSave() so that when user unchecked that flag and click on save , the updated value will be saved.
Please help me on the above situation or if you have any doc or video which implement same, please forward to me.
Please find the below code as an example,
and Make changess based on your requirement.
Thanks,
Vinoth
All Answers
Please find the below code as an example,
and Make changess based on your requirement.
Thanks,
Vinoth
And once we click on the button all userlist will be updated, correct?
Thanks,
Vinoth
Thanks,
Vinoth
Thanx again for your great help.
You can mark my post as best answer, if it helps you. So it may help others in future.
Thanks,
Vinoth