You need to sign in to do that
Don't have an account?
ezhil_k
Am new to salesforce..please help me to do the visualforce requirement
1. Define a new custom object named – HR in your Dev org. It should have all fields as indicated
HR NAme
firstname
lastname
jobcode
jobtitle
user(look up field)
2. Create new HR record
Note - associated user field is blank.
3. Click Activate USER button
4. Open User screen and pre-populate information from HR record -
5. Fill in required details and click SAVE.
6. Associate this newly created USER with HR record and bring the control back to HR detail view page.
Note – this time, we need to see the User name populated in HR record user lookup.
Hi,
1 - Create a custom object :
HR__c
Fields :
Name
First_Name__c
Job_Code__c
Job_Title__c
Last_Name__c
User__c (Lookup(User))
2 - Create a visualforce page : newuser.page
3 - Create a controller : newuser.class
4 - Create a button on the custom object HR :
Label of the button : Activate USER
Display Type = Detail Page Button
Behaviour : Display in existing window with sidebar
Content Source = visualforce page
content : newuser (your VF page)
5 - Add the button to your object page layout
6 - past the code bellow in your page and controller
____________________________________________________________________
<apex:page standardController="HR__c" extensions="newuser ">
<apex:form>
<apex:pageMessages id="error"/>
<apex:pageBlock title="New User" mode="edit">
<apex:pageBlockButtons location="both">
<apex:commandButton value="Save" action="{!saveUser}" />
</apex:pageBlockButtons>
<apex:pageBlockSection title="New User" columns="2">
<apex:inputText value="{!myNewUser.Title}" required="false" />
<apex:inputText value="{!myNewUser.LastName}" required="false" />
<apex:inputText value="{!myNewUser.FirstName}" required="false" />
<apex:inputField value="{!myNewUser.EmployeeNumber}" required="false"/>
<apex:inputField value="{!myNewUser.Email}" required="false"/>
<apex:inputField value="{!myNewUser.Username}" required="false"/>
<apex:inputField value="{!myNewUser.Alias}" required="false"/>
<apex:inputField value="{!myNewUser.CommunityNickname}" required="false"/>
<apex:inputField value="{!myNewUser.TimeZoneSidKey}" required="false"/>
<apex:inputField value="{!myNewUser.LocaleSidKey}" required="false"/>
<apex:inputField value="{!myNewUser.EmailEncodingKey}" required="false"/>
<apex:inputField value="{!myNewUser.ProfileId}" required="false"/>
<apex:inputField value="{!myNewUser.LanguageLocaleKey}" required="false"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
________________________________________________________________________
public with sharing class newuser {
public HR__c record {set;get;}
public HR__c hr {set;get;}
public User myNewUser {set;get;}
public string last_Name {set;get;}
public string first_Name {set;get;}
public string job_Code {set;get;}
public string name {set;get;}
public string lastName {set;get;}
public string job_Title {set;get;}
public string email {set;get;}
public newuser(ApexPages.StandardController controller) {
myNewUser = new User();
record = (HR__c) controller.getRecord();
hr = [Select Id, Name,First_Name__c, Job_Code__c, Job_Title__c, Last_Name__c, User__c From HR__c where Id=: record .Id LIMIT 1 ];
myNewUser.FirstName = hr.First_Name__c;
myNewUser.EmployeeNumber = hr.Job_Code__c;
myNewUser.Title= hr.Job_Title__c;
myNewUser.LastName = hr.Last_Name__c;
}
public PageReference saveUser(){
try{
myNewUser.IsActive = false;
insert myNewUser;
hr.User__c = myNewUser.Id;
update hr;
return new PageReference('/' + hr.Id);
} catch (Exception e){
ApexPages.addMessages(e);
return null;
}
}
}
All Answers
Hi,
1 - Create a custom object :
HR__c
Fields :
Name
First_Name__c
Job_Code__c
Job_Title__c
Last_Name__c
User__c (Lookup(User))
2 - Create a visualforce page : newuser.page
3 - Create a controller : newuser.class
4 - Create a button on the custom object HR :
Label of the button : Activate USER
Display Type = Detail Page Button
Behaviour : Display in existing window with sidebar
Content Source = visualforce page
content : newuser (your VF page)
5 - Add the button to your object page layout
6 - past the code bellow in your page and controller
____________________________________________________________________
<apex:page standardController="HR__c" extensions="newuser ">
<apex:form>
<apex:pageMessages id="error"/>
<apex:pageBlock title="New User" mode="edit">
<apex:pageBlockButtons location="both">
<apex:commandButton value="Save" action="{!saveUser}" />
</apex:pageBlockButtons>
<apex:pageBlockSection title="New User" columns="2">
<apex:inputText value="{!myNewUser.Title}" required="false" />
<apex:inputText value="{!myNewUser.LastName}" required="false" />
<apex:inputText value="{!myNewUser.FirstName}" required="false" />
<apex:inputField value="{!myNewUser.EmployeeNumber}" required="false"/>
<apex:inputField value="{!myNewUser.Email}" required="false"/>
<apex:inputField value="{!myNewUser.Username}" required="false"/>
<apex:inputField value="{!myNewUser.Alias}" required="false"/>
<apex:inputField value="{!myNewUser.CommunityNickname}" required="false"/>
<apex:inputField value="{!myNewUser.TimeZoneSidKey}" required="false"/>
<apex:inputField value="{!myNewUser.LocaleSidKey}" required="false"/>
<apex:inputField value="{!myNewUser.EmailEncodingKey}" required="false"/>
<apex:inputField value="{!myNewUser.ProfileId}" required="false"/>
<apex:inputField value="{!myNewUser.LanguageLocaleKey}" required="false"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
________________________________________________________________________
public with sharing class newuser {
public HR__c record {set;get;}
public HR__c hr {set;get;}
public User myNewUser {set;get;}
public string last_Name {set;get;}
public string first_Name {set;get;}
public string job_Code {set;get;}
public string name {set;get;}
public string lastName {set;get;}
public string job_Title {set;get;}
public string email {set;get;}
public newuser(ApexPages.StandardController controller) {
myNewUser = new User();
record = (HR__c) controller.getRecord();
hr = [Select Id, Name,First_Name__c, Job_Code__c, Job_Title__c, Last_Name__c, User__c From HR__c where Id=: record .Id LIMIT 1 ];
myNewUser.FirstName = hr.First_Name__c;
myNewUser.EmployeeNumber = hr.Job_Code__c;
myNewUser.Title= hr.Job_Title__c;
myNewUser.LastName = hr.Last_Name__c;
}
public PageReference saveUser(){
try{
myNewUser.IsActive = false;
insert myNewUser;
hr.User__c = myNewUser.Id;
update hr;
return new PageReference('/' + hr.Id);
} catch (Exception e){
ApexPages.addMessages(e);
return null;
}
}
}
Thanks a Lot sandra! I ll try with this .