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
Tyler ZikaTyler Zika 

Problem with Visualforce controller.

There is a form to create a new user for my customer portal. It creates a new contact when the form fills out. 

The problem. It doesn't collect the mobile # or the mailing addresss. It does first name, last name, email, and phone number. What could be wrong?
 
/**
 * An apex page controller that supports self registration of users in communities that allow self registration
 */
public class CommunitiesSSignUpController {

    public String firstName {get; set;}
    public String lastName {get; set;}
    public String email {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 String prefContactList { get; set; }
    public String mobilePhone { get; set; }
    public String homePhone { get; set; }
    public String mailingStreet { get; set; }
    public String mailingCity { get; set; }
    public String stateList { get; set; }
    public String mailingPostalCode { get; set; }
    public String Message {get; set; }
    public Boolean RegUserSuccessed { get; set; }

    
    public CommunitiesSSignUpController() {
        RegUserSuccessed=false;
    }
    
    public List<SelectOption> getStateCodes()
    {
        List<SelectOption> options = new List<SelectOption>();
        Schema.DescribeFieldResult fieldResult = Contact.MailingStateCode.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

        for( Schema.PicklistEntry f : ple ) {
            options.add(new SelectOption(f.getLabel(), f.getValue()));

        }
        
        system.debug('*********'+options);
        return options;
    }
    
    public List<SelectOption> getPrefContact()
    {
        List<SelectOption> options = new List<SelectOption>();
        Schema.DescribeFieldResult fieldResult = Contact.Preferred_Contact_Method__c.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

        for( Schema.PicklistEntry f : ple ) {
            options.add(new SelectOption(f.getLabel(), f.getValue()));

        }
        
        system.debug('*********'+options);
        return options;
    }    

    
    private boolean isValidPassword() {
        return password == confirmPassword;
    }

    public PageReference registerUser() {
        Boolean isEmailRegistered = false;
        List<User> users = [select Id from User where username = :email limit 1];
        if(users.size() > 0)
        {
            isEmailRegistered = true;
            Message = 'This email address already exists, click the Forgot Password link to generate a new password for it.';
             ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, 'This email address already exists, click the Forgot Password link to generate a new password for it.');
            ApexPages.addMessage(msg);
        }
        if(!isEmailRegistered)
        {
           // it's okay if password is null - we'll send the user a random password in that case
            if (!isValidPassword()) {
                message = Label.site.passwords_dont_match;
                ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, Label.site.passwords_dont_match);
                ApexPages.addMessage(msg);
                return null;
            }    
    
            String profileId = null; // To be filled in by customer.
            String roleEnum = null; // To be filled in by customer.
            String accountId = ''; // To be filled in by customer.
            
            String userName = email;
    
            User u = new User();
            u.Username = userName;
            u.Email = email;
            u.FirstName = firstName;
            u.LastName = lastName;
            u.Phone = homePhone;
            u.MobilePhone = mobilePhone;
            u.Street = mailingStreet;
            u.City = mailingCity;
            u.StateCode = stateList;
            u.PostalCode = mailingPostalCode;
            u.CommunityNickname = communityNickname;
    
            List<Account> communityAccts = [select Id from Account where Name = 'Community' limit 1];
            String communityAcctId = null;
            if(communityAccts.size() > 0)
            {
                communityAcctId = communityAccts[0].Id;
            }
            String userId = Site.createPortalUser(u, communityAcctId, null);
          system.debug('####' + userId);
            if (userId != null) { 
                RegUserSuccessed = true;
                Id cntId = [select ContactId from User where Id = :userId].COntactId;
                Id memberRecordTypeId = [select Id from RecordType where Name = 'Golden Opportunity' and sObjectType='COntact' limit 1].Id;
                COntact cnt = [select Preferred_Contact_Method__c, Phone, MobilePhone, MailingStreet, MailingCity, MailingStateCode, MailingPostalCode, RecordTypeId from Contact where id = :cntId];
                cnt.Preferred_Contact_Method__c = prefContactList;
                cnt.Phone = homePhone;
                cnt.MobilePhone = mobilePhone;
                cnt.MailingStreet = mailingStreet;
                cnt.MailingCity = mailingCity;
                cnt.MailingStateCode = stateList;
                cnt.MailingPostalCode = MailingPostalCode;
                cnt.RecordTypeId = memberRecordTypeId;
                
                update cnt;
                
                if (password != null && password.length() > 1) {
                    return Site.login(userName, password, ApexPages.currentPage().getParameters().get('startURL'));
                }
            }
            else
            {
                RegUserSuccessed = false;
            }
            
        }
        return null;
    }
}

 
Manish BhatiManish Bhati
Try to put some debug logs for printing below cnt variables:-
 
                cnt.MobilePhone = mobilePhone;
                cnt.MailingStreet = mailingStreet;
                cnt.MailingCity = mailingCity;
                cnt.MailingStateCode = stateList;
                cnt.MailingPostalCode = MailingPostalCode;
                cnt.RecordTypeId = memberRecordTypeId;


before updating cnt an see if the values are coming here or not.
 
Tyler ZikaTyler Zika
This is in my controller code
 
cnt.MobilePhone = mobilePhone;
                system.debug('####' + cnt.MobilePhone);

and nothing is printing to the debug logs.

Is that the correct way?
Tyler ZikaTyler Zika
I need to view the logs as a guest user.
Manish BhatiManish Bhati
So it means you are not able to get mobilephone value from your VF page.

Please check your VF page where you are setting this value.