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
mgonzalezbicmgonzalezbic 

Adding Account ID to Wrapper of another Custom Object after account created

Hi all,

I am creating a VF wizard which will take information from a VFP and dump it into three objects ( Account, Application__c, and Management_Structure__c).

I have a wrapper for the Management_Structure__c that allows me to create a pageblock table with dynamic row adding/deleting. The fields for Account and App objects are pretty standard. 

In my save I have it create the Account, then the application linking to the accountID. Once that is done, I then go to create the Management Structure records, which works properly, but I cannot add the created accountID into the wrapper before save. Accountids does show a ID in the debug log however, I just need to send it into the wrapper here's what the debug log shows:
 
21:04:40.321 (321447984)|USER_DEBUG|[169]|DEBUG|

Accountwrapper:[account=Management_Structure__c:{Account__c=null, Position_Title__c=President, Compensation__c=20000.00, Board_of_Director_Member__c=false}, accountids=001J000001jJpQYIA0, counterWrap=1]



Here is my save code:
 
//Create Management records
  
    list<Management_Structure__c> updateAccountList;
        updateAccountList = new list<Management_Structure__c>();
        if(!accountwrapperList.isEmpty()){
            for(Accountwrapper accountWrapper:accountwrapperList){

             accountid = acct.id;
             accountwrapper.accountids = accountid ; 
             
            system.debug(accountWrapper);
            
            
                updateAccountList.add(accountWrapper.account);
              
            }
        }
         if(!updateAccountList.isEmpty()){
            upsert updateAccountList;
       
        }

my wrapper:
 
public class Accountwrapper{
        public Management_Structure__c account{get;set;}
        public Integer counterWrap{get;set;}
        public id accountids {get;set;}
        
        public Accountwrapper(Management_Structure__c act){
            this.account = act;  
            act.Account__c = accountids; 
        }
    }

 
Best Answer chosen by mgonzalezbic
pconpcon
The problem is that when you call your constructor your accountids variable is null.  You can modify your assignment call on line 9 of your save code.
 
accountWrapper.account.Account__c = accountId;

 

All Answers

pconpcon
The problem is that when you call your constructor your accountids variable is null.  You can modify your assignment call on line 9 of your save code.
 
accountWrapper.account.Account__c = accountId;

 
This was selected as the best answer
mgonzalezbicmgonzalezbic
That was it!! Thank you!!!

Yeah I kept seeing it null in my debug and I was like :sadface:. I'm still wrapping my head (no pun intended) around wrappers.... but I appreciate the help!