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
Elizabeth BryantElizabeth Bryant 

Variable does not exist when passing SObject as parameter

Hi all,

I have been working on this for quite some time and I think that I may have to take a different approach. I am trying to convert a "guest user" (Contact) into a Registered (Customer Community) User based on the current Application that is pulled up in a community for company admins. I am doing this by building an extension on the existing controller for the page where agents can pull the application up.

I added a inputText and button to the page where the agent can enter in an email. This code updates the Contact record fine, as well as creates the associated Account. I want the code to update the Account, not create an entirely different one. This is supposed to be handled by passing methods from the original controller, but I'm running into snags here and there where the User is not being created at all and the Account that is created/updated is not being reflected in the Application record. For instance, where a guest user has filled an application they are assigned to "Guest Account" which is a placeholder of sorts for that person's application. This is also visible on the Application record in the Related_object__c field. When I enter an email in the field on my page, it updates the contact information and adds the Contact to "Firstname Middlename Last Name Account" but doesn't not update the Application's Related_Account__c field. 

I'm also unfamiliar with Page References so I may be going about using them incorrectly. 

I currently get an error "Variable does not exist: updatedCon" when I attempt to pass an SObject variable as parameter (declared and returned from changeGuestUser) method. I think I just need another pair of eyes to get this working as I have it thusfar. 

Thanks! 
 
public Contact changeGuestContact(String searchEmail){
        
       // LoginServices.generateAccountName(fname, mname, lname); *Might Still Use This*
        
       //Query for Head_of_Household information on current app
       //Can not move this out of list. 
       //Error! - SObject constructor must use name=value pairs
       List<FC_Member__c> hohContact = new List<FC_Member__c>([Select Contact__r.ID, Contact__r.FirstName, 
                        Contact__r.MiddleName, 
                        Contact__r.LastName, 
                        Contact__r.Email, 
                        ID, 
                        FC_Application__r.Related_Account__c,                                       
                        FC_Application__r.Confirmation_Number__c, 
                        FC_Application__r.Head_of_Household_Name__c
                                                              
                        
                        FROM FC_Member__C 
                        WHERE FC_Application__r.Confirmation_Number__c = :fcord.confnum LIMIT 1]);

        //Create Contact 
        Contact updatedCon = New Contact();
        updatedCon.ID = hohContact[0].Contact__r.ID;
        updatedCon.FirstName = hohContact[0].Contact__r.FirstName;
        updatedCon.MiddleName = hohContact[0].Contact__r.MiddleName;
        updatedCon.LastName = hohContact[0].Contact__r.LastName;
        updatedCon.email = searchEmail;
        
        //
        String newAcctName = LoginServices.generateAccountName(updatedCon.FirstName, updatedCon.MiddleName, updatedCon.LastName);
         Account updatedAccount = new Account(Name=newAcctName);
        
        update updatedAccount;
        
        updatedCon.AccountId = updatedAccount.ID;
        
        
        system.debug('Contact updated: ' +updatedCon);
        update updatedCon;    
        return updatedCon;

        
    }
    
    public FC_Application__c changeApp(Contact updatedCon) { //Line 171 Variable does not exist: updatedCon --> changeApp(updatedCon); 
        
        //query for the current application by confirmation number *The app that is pulled up in AdminTool*
        List <FC_Application__c>  currentApp = new List<FC_Application__c>([SELECT ID,
                                                                    Related_Account__c,
                                                                    Confirmation_Number__c
                                                                    
                                                                    FROM FC_Application__c
                                                                    WHERE Confirmation_Number__c =:fcord.confnum LIMIT 1]); 
     
        FC_Application__c updateApp = new FC_Application__c();
        updateApp.ID = currentApp[0].ID;
        updateApp.Related_Account__c = updatedCon.AccountId;

        
        update updateApp;
        system.debug('Account: ' +updateApp.Related_Account__c);
        
        //Need to set the AccountID/Name from the updatedCon variable to the Related_Account__c variable on the current
        //Application.
         //updatedAccount.Application__c = currentApp[0].ID;
         
         
        
        return updateApp;
    }   
    
    
        public Account changeGuestAccount(Contact updatedCon){
        
        //String newAcctName = LoginServices.generateAccountName(updatedCon.FirstName, updatedCon.MiddleName, updatedCon.LastName);
         //Account updatedAccount = new Account(Name=newAcctName);
        
        //upsert updatedAccount;    
        return null;
        
    }
    
    //Calls LoginServices.createNewApplicant to 'self-register' the Guest into a Customer User
    public Boolean createSuccessful(Contact updatedCon){
        try{
        changeGuestContact(searchEmail);
        LoginServices.createNewApplicant(updatedCon.email, updatedCon.firstname, updatedCon.middlename, updatedCon.lastname);
        system.debug('User created?: ');
        }
        catch (exception e){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Contact not updated'));
            return false;
        }
        return true;
    }
    
    
    
    
    

    
    public PageReference checkEmail(){
        try{
            //setSearchEmail('jdough@test.com');
            //changeGuestContact(searchEmail);
            //changeGuestAccount();
            createSuccessful(updatedCon); //Variable does not exist: updatedCon
            //changeApp(updatedCon); //variable does not exist: updatedCon
            return null;
        } 
        catch (exception e){
           ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Contact not updated'));
         
        }
        return null;
    }





 
Best Answer chosen by Elizabeth Bryant
Elizabeth BryantElizabeth Bryant
Sorry I never came back to this post. My requirements ended up changing so I had to scrap most of this. Thanks for your input!

Thanks,
Elizabeth

All Answers

ManjunathManjunath
Hi Elizabeth,

Where is this define "updatedCon " ? Dont you think its scope is local  ( scoped to  - changeGuestContact) ;) .

Regards,
Manjunath C S
Elizabeth BryantElizabeth Bryant
Sorry I never came back to this post. My requirements ended up changing so I had to scrap most of this. Thanks for your input!

Thanks,
Elizabeth
This was selected as the best answer