function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ronaldo CostaRonaldo Costa 

Communities Self Reg

Hello all,

I need to add a picklist field to the CommunitiesSelfReg VF page, but am getting the error below because I need to change it from inputext to inputfield, otherwise it won't show the drop-down menu.

"Could not resolve the entity from <apex:inputField> value binding '{!purchasedfrom}'.  <apex:inputField> can only be used with SObjects, or objects that are Visualforce field component resolvable."

VF Page:

 
<apex:page id="communitiesSelfRegPage" showHeader="true" controller="CommunitiesSelfRegController" title="{!$Label.site.user_registration}">
     <apex:define name="body">  
      <center>
<apex:form id="theForm" forceSSL="true">
                    <apex:pageMessages id="error"/>
                    
                    
                    <apex:panelGrid columns="2" style="margin-top:1em;">
                      <apex:outputLabel style="font-weight:bold;color:red;" value="First Name" for="firstName"/>
                      <apex:inputText required="true" id="firstName" value="{!firstName}" label="First Name"/>
                      <apex:outputLabel style="font-weight:bold;color:red;" value="Last Name" for="lastName"/>
                      <apex:inputText required="true" id="lastName" value="{!lastName}" label="Last Name"/>
                      <apex:outputLabel style="font-weight:bold;color:red;" value="{!$Label.site.email}" for="email"/>
                      <apex:inputText required="true" id="email" value="{!email}" label="{!$Label.site.email}"/>
                      
                      <apex:outputLabel style="font-weight:bold;color:red;" value="Phone" for="phone"/>
                      <apex:inputText required="true" id="phone" value="{!phone}" label="Phone"/>
                      <apex:outputLabel value="Title" for="title"/>
                      <apex:inputText required="true" id="title" value="{!title}" label="Title"/>                      
                      <apex:outputLabel style="font-weight:bold;color:red;" value="Company" for="companyname"/>
                      <apex:inputText required="true" id="companyname" value="{!companyname}" label="Company"/>                      

                      <apex:outputLabel style="font-weight:bold;color:red;" value="Street" for="street"/>
                      <apex:inputText required="true" id="street" value="{!street}" label="Street"/>
                      <apex:outputLabel style="font-weight:bold;color:red;"  value="City" for="city"/>
                      <apex:inputText required="true" id="city" value="{!city}" label="City"/>
                      <apex:outputLabel style="font-weight:bold;color:red;"  value="Zip" for="postalcode"/>
                      <apex:inputText required="true" id="postalcode" value="{!postalcode}" label="Zip"/>
                      <apex:outputLabel style="font-weight:bold;color:red;"  value="Country" for="country"/>
                      <apex:inputText required="true" id="country" value="{!country}" label="Country"/>
                      <apex:outputLabel style="font-weight:bold;color:red;"  value="State" for="state"/>
                      <apex:inputText required="true" id="state" value="{!state}" label="State"/>
                      
                      <apex:outputLabel value="Product Owner" for="productowner"/>
                      <apex:inputText required="true" id="productowner" value="{!productowner}" label="Product Owner"/>
<!--                       <apex:outputLabel value="Purchased From" for="purchasedfrom"/> -->
<!--                       <apex:inputText required="true" id="purchasedfrom" value="{!purchasedfrom}" label="Purchased From"/> -->
                      <apex:outputLabel value="Serial Number" for="serialnumber"/>
                      <apex:inputText required="true" id="serialnumber" value="{!serialnumber}" label="Serial Number"/>
                      
                      <apex:inputfield value="{!u.Purchased_From__c}"/>  
                      
					  <apex:outputLabel value="{!$Label.site.community_nickname}" for="communityNickname"/>
                      <apex:inputText required="true" id="communityNickname" value="{!communityNickname}" label="{!$Label.site.community_nickname}"/>                      
                      <apex:outputLabel value="{!$Label.site.password}" for="password"/>
                      <apex:inputSecret id="password" value="{!password}"/>
                      <apex:outputLabel value="{!$Label.site.confirm_password}" for="confirmPassword"/>
                      <apex:inputSecret id="confirmPassword" value="{!confirmPassword}"/>
                      <apex:outputText value=""/>
                      <apex:commandButton action="{!registerUser}" value="{!$Label.site.submit}" id="submit"/>
                    </apex:panelGrid> 
                  <br/>
</apex:form>
     </center>
      <br/>
    </apex:define>

</apex:page>

Class:
 
/**
 * An apex page controller that supports self registration of users in communities that allow self registration
 */
public with sharing class CommunitiesSelfRegController {

  public String firstName {get; set;}
  public String lastName {get; set;}
  public String email {get; set;}
  public String phone {get; set;}
  public String title {get; set;}
  public String companyname {get; set;}
  public String street {get; set;}
  public String city {get; set;}
  public String postalcode {get; set;}
  public String country {get; set;}
  public String state {get; set;}
  public String productowner {get; set;}
  public String purchasedfrom {get; set;}
  public String serialnumber {get; set;}
  public String password {get; set {password = value == null ? value : value.trim(); } }
  public String confirmPassword {get; set { confirmPassword = value == null ? value : value.trim(); } }
  public String communityNickname {get; set { communityNickname = value == null ? value : value.trim(); } }
  
  public CommunitiesSelfRegController() {}
  
  private boolean isValidPassword() {
    return password == confirmPassword;
  }

  public PageReference registerUser() {
  
    // it's okay if password is null - we'll send the user a random password in that case
    if (!isValidPassword()) {
      System.debug(System.LoggingLevel.DEBUG, '## DEBUG: Password is invalid - returning null');
      ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, Label.site.passwords_dont_match);
      ApexPages.addMessage(msg);
      return null;
    }  

    
    String profileId = '00ej0000000jJMR'; // To be filled in by customer.
    
    String accountId = '001g000000QMTDX'; // To be filled in by customer.  

    // Set this to your main Communities Profile API Name
    String profileApiName = 'PowerCustomerSuccess';
    //String profileId = [SELECT Id FROM Profile WHERE UserType = :profileApiName LIMIT 1].Id;
    //List<Account> accounts = [SELECT Id FROM Account LIMIT 1];
    //System.assert(!accounts.isEmpty(), 'There must be at least one account in this environment!');
    //String accountId = accounts[0].Id;
    
    String userName = email;

    User u = new User();
    u.Username = userName;
    u.Email = email;
    u.Phone = phone;
    u.Title = title;
    u.Street = street;
    u.City = city;
    u.PostalCode = postalcode;
    u.Country = country;
    u.State = state;
    u.Product_Owner__c = productowner;
    u.Purchased_From__c = purchasedfrom;
    u.Serial_Number__c = serialnumber;
    u.CompanyName = companyname;
    u.FirstName = firstName;
    u.LastName = lastName;
    u.CommunityNickname = communityNickname;
    u.ProfileId = profileId;
    
    String userId = Site.createPortalUser(u, accountId, password);
   
    if (userId != null) { 
      if (password != null && password.length() > 1) {
        System.debug(System.LoggingLevel.DEBUG, '## DEBUG: User creation successful and password ok - returning site.login');
        return Site.login(userName, password, null);
      }
      else {
        System.debug(System.LoggingLevel.DEBUG, '## DEBUG: User creation successful but password not ok - redirecting to self reg confirmation');
        PageReference page = System.Page.CommunitiesSelfRegConfirm;
        page.setRedirect(true);
        return page;
      }
    }
    System.debug(System.LoggingLevel.DEBUG, '## DEBUG: User creation not successful - returning null');
    return null;
  }
}


Thanks!!!

Ronaldo.
Best Answer chosen by Ronaldo Costa
Tejpal KumawatTejpal Kumawat
Hello Ronaldo,

Good that class worked. :)
This is looking your Field-Level security is not visible for community profile for Purchased_From__c field. please try that page as internally run by /apex/<your page name>. If picklist show then need to provide Field-Level security.

If this answers your question then hit Like and mark it as solution!
 

All Answers

Tejpal KumawatTejpal Kumawat
Hello Ronaldo,

please provide field types of :

Product_Owner__c
Purchased_From__c
Serial_Number__c

 
Grazitti TeamGrazitti Team
Hi Ronaldo,
There is one an other approch to show picklist in the VF page. I am going to write some sample code for this.

Apex Class:
Public String airportCode     {get;set;}

public List<SelectOption> getAirport(){
      List<SelectOption> options = new List<SelectOption>();
      options.add(new SelectOption('--None--','--None--'));
      options.add(new SelectOption('India','India'));
      options.add(new SelectOption('Australia','Australia'));
      return options;
}

​VF Page:
<apex:selectList value="{!airportCode}" size="1">
        <apex:selectOptions value="{!Airport}"/>
</apex:selectList>

Please feel to contact us if there are any concerns and also mark as best answer if it helps you.

Regards,
Grazitti Team
Web: www.grazitti.com
Email: sfdc@grazitti.com
Ronaldo CostaRonaldo Costa
Hello!

See below please.

Product_Owner__c = text field, working fine
Purchased_From__c = picklist field, not working properly
Serial_Number__c = text field, working fine

The issue really is with the syntax I'm pretty sure.

The code below works fine, but this is a picklist field, not a text. However when I change tags from 'inputText' to 'inputField' I get so many errors.
<apex:outputLabel value="Purchased From" for="purchasedfrom"/>
<apex:inputText required="true" id="purchasedfrom" value="{!purchasedfrom}" label="Purchased From"/>


Thanks,

Ronaldo.
 
Tejpal KumawatTejpal Kumawat
Hello Ronaldo,

Try this :
 
/**
 * An apex page controller that supports self registration of users in communities that allow self registration
 */
public with sharing class CommunitiesSelfRegController {

  public String firstName {get; set;}
  public String lastName {get; set;}
  public String email {get; set;}
  public String phone {get; set;}
  public String title {get; set;}
  public String companyname {get; set;}
  public String street {get; set;}
  public String city {get; set;}
  public String postalcode {get; set;}
  public String country {get; set;}
  public String state {get; set;}
  public String productowner {get; set;}
  //public String purchasedfrom {get; set;}
  public String serialnumber {get; set;}
  public String password {get; set {password = value == null ? value : value.trim(); } }
  public String confirmPassword {get; set { confirmPassword = value == null ? value : value.trim(); } }
  public String communityNickname {get; set { communityNickname = value == null ? value : value.trim(); } }
  public User u{get; set;}
  
  public CommunitiesSelfRegController() {
	u = new User();
  }
  
  private boolean isValidPassword() {
    return password == confirmPassword;
  }

  public PageReference registerUser() {
  
    // it's okay if password is null - we'll send the user a random password in that case
    if (!isValidPassword()) {
      System.debug(System.LoggingLevel.DEBUG, '## DEBUG: Password is invalid - returning null');
      ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, Label.site.passwords_dont_match);
      ApexPages.addMessage(msg);
      return null;
    }  

    
    String profileId = '00ej0000000jJMR'; // To be filled in by customer.
    
    String accountId = '001g000000QMTDX'; // To be filled in by customer.  

    // Set this to your main Communities Profile API Name
    String profileApiName = 'PowerCustomerSuccess';
    //String profileId = [SELECT Id FROM Profile WHERE UserType = :profileApiName LIMIT 1].Id;
    //List<Account> accounts = [SELECT Id FROM Account LIMIT 1];
    //System.assert(!accounts.isEmpty(), 'There must be at least one account in this environment!');
    //String accountId = accounts[0].Id;
    
    String userName = email;

    
    u.Username = userName;
    u.Email = email;
    u.Phone = phone;
    u.Title = title;
    u.Street = street;
    u.City = city;
    u.PostalCode = postalcode;
    u.Country = country;
    u.State = state;
    u.Product_Owner__c = productowner;
    //u.Purchased_From__c = purchasedfrom;
    u.Serial_Number__c = serialnumber;
    u.CompanyName = companyname;
    u.FirstName = firstName;
    u.LastName = lastName;
    u.CommunityNickname = communityNickname;
    u.ProfileId = profileId;
    
    String userId = Site.createPortalUser(u, accountId, password);
   
    if (userId != null) { 
      if (password != null && password.length() > 1) {
        System.debug(System.LoggingLevel.DEBUG, '## DEBUG: User creation successful and password ok - returning site.login');
        return Site.login(userName, password, null);
      }
      else {
        System.debug(System.LoggingLevel.DEBUG, '## DEBUG: User creation successful but password not ok - redirecting to self reg confirmation');
        PageReference page = System.Page.CommunitiesSelfRegConfirm;
        page.setRedirect(true);
        return page;
      }
    }
    System.debug(System.LoggingLevel.DEBUG, '## DEBUG: User creation not successful - returning null');
    return null;
  }
}
If this answers your question then hit Like and mark it as solution!
 
Ronaldo CostaRonaldo Costa
Hi Tejpal Kumawat,

Thanks very much for your suggestion!

I implemented your class and changed the inputField field to: value="{!u.Purchased_From__c}"

This is what I'm getting, I already made sure the Field-Level security is visible for all profiles. Any thoughts why this picklist field is not working on my communities self reg. VF Page?


User-added image


Ronaldo.
Tejpal KumawatTejpal Kumawat
Hello Ronaldo,

Good that class worked. :)
This is looking your Field-Level security is not visible for community profile for Purchased_From__c field. please try that page as internally run by /apex/<your page name>. If picklist show then need to provide Field-Level security.

If this answers your question then hit Like and mark it as solution!
 
This was selected as the best answer
Ronaldo CostaRonaldo Costa
Tejpal Kumawat,

This is becoming an interesting problem! I just made the tests and all custom fields are Visible (checked) under the User Field-Level Security for my Community User profile =O

Interesting enough, this is the result I got by using /apex/communitiesselfreg

It is show the picklist field!

Now what other checks do I need to make in order for a inputField to display externally via the Self Register portal? I did several google researchs and found nothing, I even added all classes and VF pages to this profile and it did not work.



User-added image


Thanks once again,

Ronaldo Costa.
Ronaldo CostaRonaldo Costa
Nevermind my friend, I got the error!

I went to Manage Communities, Advanced Customizations, Site Details for Customer Support and edited permissions there!

All fields were not visible for this site permissions! All solved now, thanks for all the help.


Ronaldo Costa.
Pavani Akella 9Pavani Akella 9
Hi Ronaldo,

I know this is a old post. I'm also facing the same issue. Phone and Company name fields are not displayed in the VF page even though those fields are checked under Field level security.

Can you help me to find the steps you mentioned(I went to Manage Communities, Advanced Customizations, Site Details for Customer Support and edited permissions there!)

Thanks!