You need to sign in to do that
Don't have an account?
How to retrieve account Name from visualforce page??
i have created a visualforce page (for creating user)... i have created a custom lookup on this vf page (lookup for accounts)...
and one more thing i have added .. i have taken a custom field on User (standard) object named as Account__c...
i want that whenever we will create new user by using this vf page... once account is selected this account name should be stored in Accouunt__c..
how to do??
here is my Code,
vf Page-: (CreateNewUser)
<apex:page standardController="User" extensions="CreateNewUserExtension">
<script language="javascript">
var newWin=null;
function openLookupPopup(name, id)
{
var url="/apex/AccountLookupPopup?namefield=" + name + "&idfield=" + id;
newWin=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
if (window.focus)
{
newWin.focus();
}
return false;
}
function closeLookupPopup()
{
if (null!=newWin)
{
newWin.close();
}
}
</script>
<apex:sectionHeader title="User Creation" subtitle="{!User.Name}" help="/help/doc/user_ed.jsp?loc=help"></apex:sectionHeader>
<apex:form >
<apex:pageBlock mode="edit">
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton action="{!saveme}" value=" Save "></apex:commandButton>
<apex:commandButton action="{!cancel}" value="Cancel"></apex:commandButton>
</apex:pageBlockButtons>
<apex:pageBlockSection title="User Information" columns="2" collapsible="false">
<apex:pageBlockSectionitem >
<apex:outputLabel value="Account"/>
<apex:outputPanel >
<apex:inputHidden value="{!accountId}" id="targetId" />
<apex:inputText size="20" value="{!accountName}" id="targetName" onFocus="this.blur()" disabled="false"/>
<a href="#" onclick="openLookupPopup('{!$Component.targetName}', '{!$Component.targetId}'); return false"><apex:image value="{!$Resource.lookup_logo}" title="LookupLogo"/></a>
</apex:outputPanel>
</apex:pageBlockSectionitem>
<apex:inputField value="{!User.User_Type__c}" />
<apex:inputField value="{!User.FirstName}"/>
<apex:inputField value="{!User.LastName}"/>
<apex:inputField value="{!User.Username}"/>
<apex:inputField value="{!User.Email}"/>
<apex:inputField value="{!User.alias}"/>
<apex:inputField value="{!User.UserRoleId}"/>
<apex:inputField value="{!User.IsActive}"/>
<apex:inputField value="{!User.UserType}"/>
<apex:inputField value="{!User.ProfileId}"/>
<apex:inputField value="{!User.Phone}"/>
<apex:inputField value="{!User.Extension}"/>
<apex:inputField value="{!User.Fax}"/>
<apex:inputField value="{!User.EmployeeNumber}"/>
<apex:inputField value="{!User.Title}"/>
<apex:inputField value="{!User.CompanyName}"/>
<apex:inputField value="{!User.Division}"/>
<apex:inputField value="{!User.Department}"/>
<apex:inputField value="{!User.CommunityNickName}"/>
<apex:inputField value="{!User.UserType}"/>
<apex:inputField value="{!User.ReceivesInfoEmails}" />
</apex:pageBlockSection>
<apex:pageBlockSection title="Other Information" columns="1" collapsible="false">
<apex:inputField value="{!User.EmailEncodingKey}"/>
<apex:inputField value="{!User.TimeZoneSidKey}"/>
<apex:inputField value="{!User.LocaleSidKey}"/>
<apex:inputField value="{!User.LanguageLocaleKey}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Class-:CreateNewUserExtension
public class CreateNewUserExtension {
public Id accountId{get;set;}
public String accountName{get;set;}
public List<Account> accs{get;set;}
private final User user;
public CreateNewUserExtension(ApexPages.StandardController controller)
{
this.user= (User)controller.getrecord();
}
public PageReference saveme()
{
user.Username = user.Username;
user.UserRoleId = user.UserRoleId;
user.FirstName = user.FirstName;
user.LastName = user.LastName;
user.Email = user.Email;
user.ProfileId = user.ProfileId;
user.CompanyName = user.CompanyName;
user.CommunityNickName = user.CommunityNickName;
user.EmailEncodingKey = user.EmailEncodingKey;
user.TimeZoneSidKey = user.TimeZoneSidKey;
user.LocaleSidKey = user.LocaleSidKey;
user.LanguageLocaleKey = user.LanguageLocaleKey;
insert user;
return null;
}
}
Cheers,
Amit Singh
Hi,
I am not sure where are you trying to create an account. I want to know how the account is created. do you want to create a new account when the user is created?
As per my understanding I am giving this code. check this and let me know. I am not totally sure. but this might give you a small lead towards what I am indicating. I am really not sure if my code is totally correct as I wrote it in notepad.
Your save method should only be this