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
KaityKaity 

How to fetch the18 digits ID of Master record while creating Child record.

Hi experts,

Requirement: I have 2 objects: Account(Standard) and Cobject(Custom object). Account and Cobject has a master-detail relationship. So, on Account Detail Page, we have Cobject as related list. In the relatedlist, 'NEW' button of cObject is overridden by a VisualForce Page. My query is- How can I get the AccountId for the Cobject that I am creating on clicking 'NEW' button? Please help with the syntax.

I have tried to get the AccountId from the URL. But, URL shows only 15 digits in the UI. If we take this 15 digits ID, then on assiging the 15 digits ID in the Custom field(for M-D relation) , throws an error, saying- INVALID ID.

Here, we need to get the 18 digit AccountID for which new Cobject record is creating. Please help

Thanks,
Kaity

 
Best Answer chosen by Kaity
Suneel#8Suneel#8
Kaity,

How were you able to select this VF page while overriding New button on custom object-Business?As this VF page is based on Account StandardController ,you will not be able to see this VF page in the dropdown 'Visualforce Page with'. Am I missing anything here?

Yes we can save the record by hardcoding15 digit id.I have just tried and it worked

First we need to test if this page works standalone by accessing your page like below and adding Business records.If it works,later you can progress to including this page in your app.Change your server node ap1 in below URL.Type the below URL in your address bar,add business records and check if they are getting saved.Ensure that you are using below lines in controller to get the account id instead of hardcoding the id

https://ap1.salesforce.com/apex/YOUR_VF_PAGE_NAME?id=YOUR_15_DIGIT_ACCOUNT_ID
 
public class myBusinessController {
	public Id accountId{get;set;}
	public myBusinessController(ApexPages.StandardController controller){
		accountId=controller.getId();
	}
	public PageReference saveRecord(){
		nwbusiness.Account__c = accountId;
	}
}

 

All Answers

Suneel#8Suneel#8
Assigning object id of account to the reference in Custom Object should work.Can you post your code?
KaityKaity
Thanks Suneel for replying.

Please find the below, code snippet, where I want to find the ID of Account(Master) record. Please let me know, if you need other information.

-Kaity
KaityKaity
Sorry, forgot to attach the code:

public customController(ApexPages.StandardController controller){
    this.acc = (Account)controller.getRecord();  
  
        String hostVal  = ApexPages.currentPage().getHeaders().get('Host');
            system.debug('=======MY HOST NAME========='+hostVal);
        String urlVal = Apexpages.currentPage().getUrl();
            system.debug('=======MY HOST NAME========='+urlVal );
        String URLL = 'https://' + hostVal+ urlVal;
            system.debug('=======MY HOST NAME========='+URLL);
         id1=urlVal.substring(75,91);
         System.debug('+++++15 digit id+++++'+id1);
         //AccountId=id1;
         system.debug('=======newAccountId is========='+AccountId); 
         
         //List<Account> i=[Select id from Account where id=:id1 limit 1];
                    
         //system.debug('=======18 digit AccountId is========='+i);    
       
         //system.debug('=======AccountId is========='+AccountId); 
Suneel#8Suneel#8
You didn't post the lines where you are assigning account id to the child custom object.15 digit id should not throw any error.It could be some other issue.Can you post full code and also the complete error message..Use below line to pull id parameter from URL

Id idey=ApexPages.CurrentPage().geParameters().get('id');
KaityKaity
Please find the whole code:  (Please find the line 287 in bold.)

public class myBusinessController {
    Account acc = new Account();
    public Business__c business{get;set;}
    public ID AccountId= null;
    public List<business__c> bus {get; set;}

    public String id1; 
    public String id2;  
    public String standardizedBusinessProcess;
    public String desiredBusinessOutcomes;
    public String applicationSupport;
    public String stakeholdersBuyins;
    public String currentlyOutsouce;
    public String systems;
    public String cloudBasedPlatforms;
    public String ITStrategy;
    public String investedinCloud;
    public String satisfiedWithCloud;
    public String ITApplicationsSharedBetweenLOB;
    public String users;
    public String risk;
    public String geographicalFootprint;
    public String disparityinITBudget;
    public String multiGeographyEngagement;
    public String nonFunctionalRequirement;
    public String specificNFR;
    public String seasonalUserLoad;
    public String changeManagementProgram;
    public String MyAccount;    
       
    public myBusinessController(ApexPages.StandardController controller){
    this.acc = (Account)controller.getRecord(); 
    id billAccountId = controller.getId();
    System.debug('ACCOUNT ID'+ billAccountId); 
    System.debug('WORLD OF CONTROLLER'+ this.acc);
   // bus.add(new business__c(Account__c = Account.id);

    System.debug('@@@@@@@@'+ this.MyAccount);
     /*Id id = ApexPages.currentPage().getParameters().get('id');
        business=(id == null) ? new Business__c() : 
            [SELECT Name FROM Business__c WHERE Id = :id];
        Id id=controller.getId();
        system.debug('=======id is========='+id);*/
        String hostVal  = ApexPages.currentPage().getHeaders().get('Host');
            system.debug('=======Host is========='+hostVal);
        String urlVal = Apexpages.currentPage().getUrl();
            system.debug('=======URL is========='+urlVal );
        String URLL = 'https://' + hostVal+ urlVal;
            system.debug('=======entire URL is========='+URLL);
         id1=urlVal.substring(75,91);
         System.debug('+++++15 digit id+++++'+id1);
         //AccountId=id1;
         system.debug('=======newAccountId is========='+AccountId); 
         
         //List<Account> i=[Select id from Account where id=:id1 limit 1];
         //id1 = '0019000000ld9fBAAQ';            
         //system.debug('=======18 digit AccountId is========='+i);    
         //this.AccountId=Id.valueOf(id1);
         //system.debug('=======AccountId is========='+AccountId); 
       //   public Integer myint{
        //  get{
         //    if(acc == null)
           // acc = [SELECT ID FROM Account where ID = :id1];
      //    }
        
    }
    
    public List<SelectOption> getvalue(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Yes','Yes'));
            options.add(new SelectOption('Partial','Partial'));
            options.add(new SelectOption('No','No'));
        return options;
    }
    public List<SelectOption> getvalue1(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Increase revenue','Increase revenue'));
            options.add(new SelectOption('Decrease costs (increase productivity)','Decrease costs (increase productivity)'));
            options.add(new SelectOption('Increase margins','Increase margins'));
            options.add(new SelectOption('Other','Other'));
        return options;
    }
    public List<SelectOption> getvalue2(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Yes','Yes'));
            options.add(new SelectOption('No','No'));
        return options;
    }
    
    public List<SelectOption> getvalue3(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Yes, cloud based','Yes, cloud based'));
            options.add(new SelectOption('Yes, traditional','Yes, traditional'));
            options.add(new SelectOption('No','No'));
        return options;
    }
    public List<SelectOption> getvalue4(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Low','Low'));
            options.add(new SelectOption('Med','Med'));
            options.add(new SelectOption('High','High'));
            options.add(new SelectOption('None','None'));
        return options;
    }
    public List<SelectOption> getvalue5(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Low','Low'));
            options.add(new SelectOption('None','None'));
            options.add(new SelectOption('High','High'));
        return options;
    }
    public List<SelectOption> getvalue6(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Low','<500K'));
            options.add(new SelectOption('Medi','500 to 2000K'));
            options.add(new SelectOption('High','>2000K'));
        return options;
    }
    public List<SelectOption> getvalue7(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Not at all','Not at all'));
            options.add(new SelectOption('Somewhat','Somewhat'));
            options.add(new SelectOption('Very Satisfied','Very Satisfied'));
        return options;
    }
    public List<SelectOption> getvalue8(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Risk Adverse','Risk Adverse'));
            options.add(new SelectOption('Neutral','Neutral'));
            options.add(new SelectOption('Risk Tolerant','Risk Tolerant'));
        return options;
    }
    public List<SelectOption> getvalue9(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Yes','Yes'));
            options.add(new SelectOption('No','No'));
        return options;
    }
    public List<SelectOption> getvalue10(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Important','Important'));
            options.add(new SelectOption('Not Important','Not Important'));
        return options;
    }
    public String getstandardizedBusinessProcess(){
        return standardizedBusinessProcess;
    }
    public void setstandardizedBusinessProcess(String standardizedBusinessProcess){
        this.standardizedBusinessProcess=standardizedBusinessProcess;
    }
    
    public String getdesiredBusinessOutcomes(){
        return desiredBusinessOutcomes;
    }
    public void setdesiredBusinessOutcomes(String desiredBusinessOutcomes){
        this.desiredBusinessOutcomes=desiredBusinessOutcomes;
    }
    
    public String getapplicationSupport(){
        return applicationSupport;
    }
    public void setapplicationSupport(String applicationSupport){
        this.applicationSupport=applicationSupport;
    }
    
    public String getstakeholdersBuyins(){
        return stakeholdersBuyins;
    }
    public void setstakeholdersBuyins(String stakeholdersBuyins){
        this.stakeholdersBuyins=stakeholdersBuyins;
    }
    
    public String getcurrentlyOutsouce(){
        return currentlyOutsouce;
    }
    public void setcurrentlyOutsouce(String currentlyOutsouce){
        this.currentlyOutsouce=currentlyOutsouce;
    }
    
    public String getsystems(){
        return systems;
    }
    public void setsystems(String systems){
        this.systems=systems;
    }
    
    public String getcloudBasedPlatforms(){
        return cloudBasedPlatforms;
    }
    public void setcloudBasedPlatforms(String cloudBasedPlatforms){
        this.cloudBasedPlatforms=cloudBasedPlatforms;
    }
    
    public String getITStrategy(){
        return ITStrategy;
    }
    public void setITStrategy(String ITStrategy){
        this.ITStrategy=ITStrategy;
    }
    
    public String getinvestedinCloud(){
        return investedinCloud;
    }
    public void setinvestedinCloud(String investedinCloud){
        this.investedinCloud=investedinCloud;
    }
    
    public String getsatisfiedWithCloud(){
        return satisfiedWithCloud;
    }
    public void setsatisfiedWithCloud(String satisfiedWithCloud){
        this.satisfiedWithCloud=satisfiedWithCloud;
    }
    
    public String getITApplicationsSharedBetweenLOB(){
        return ITApplicationsSharedBetweenLOB;
    }
    public void setITApplicationsSharedBetweenLOB(String ITApplicationsSharedBetweenLOB){
        this.ITApplicationsSharedBetweenLOB=ITApplicationsSharedBetweenLOB;
    }
    
    public String getusers(){
        return users;
    }
    public void setusers(String users){
        this.users=users;
    }
    
    public String getrisk(){
        return risk;
    }
    public void setrisk(String risk){
        this.risk=risk;
    }
    
    public String getgeographicalFootprint(){
        return geographicalFootprint;
    }
    public void setgeographicalFootprint(String geographicalFootprint){
        this.geographicalFootprint=geographicalFootprint;
    }
    
    public String getdisparityinITBudget(){
        return disparityinITBudget;
    }
    public void setdisparityinITBudget(String disparityinITBudget){
        this.disparityinITBudget=disparityinITBudget;
    }
    
    public String getmultiGeographyEngagement(){
        return multiGeographyEngagement;
    }
    public void setmultiGeographyEngagement(String multiGeographyEngagement){
        this.multiGeographyEngagement=multiGeographyEngagement;
    }
    
    public String getnonFunctionalRequirement(){
        return nonFunctionalRequirement;
    }
    public void setnonFunctionalRequirement(String nonFunctionalRequirement){
        this.nonFunctionalRequirement=nonFunctionalRequirement;
    }
    
    public String getspecificNFR(){
        return specificNFR;
    }
    public void setspecificNFR(String specificNFR){
        this.specificNFR=specificNFR;
    }
    
    public String getseasonalUserLoad(){
        return seasonalUserLoad;
    }
    public void setseasonalUserLoad(String seasonalUserLoad){
        this.seasonalUserLoad=seasonalUserLoad;
    }
    
     public String getchangeManagementProgram(){
        return changeManagementProgram;
    }
    public void setchangeManagementProgram(String changeManagementProgram){
        this.changeManagementProgram=changeManagementProgram;
    }
    
    public Void saveRecord(){
        Business__c nwbusiness =new Business__c ();
            nwbusiness.Account__c = '0019000000ld9fB';
            nwbusiness.Business_standardized_business_process__c=standardizedBusinessProcess;
           
            nwbusiness.Business_desired_business_outcomes__c=desiredBusinessOutcomes;
            nwbusiness.Business_application_s_support__c=applicationSupport;
            nwbusiness.Business_stakeholders_buy_ins__c=stakeholdersBuyins;
            nwbusiness.Business_currently_outsouce__c=currentlyOutsouce;
            nwbusiness.Business_systems__c=systems;
            nwbusiness.Business_understanding_of_cloud_based_pl__c=cloudBasedPlatforms;
            nwbusiness.Business_IT_strategy__c=ITStrategy;
            nwbusiness.Business_invested_in_cloud__c=investedinCloud;
            nwbusiness.Business_satisfied_with_Cloud__c=satisfiedWithCloud;
            nwbusiness.Business_IT_applications_shared_between__c=ITApplicationsSharedBetweenLOB;
            nwbusiness.Business_users__c=users;
            nwbusiness.Business_risk__c=risk;
            nwbusiness.Business_geographical_footprint__c=geographicalFootprint;
            nwbusiness.Business_disparity_in_IT_budget__c=disparityinITBudget;
            nwbusiness.Business_multi_geography_engagement__c=multiGeographyEngagement;
            nwbusiness.Business_non_functional_requirement__c=nonFunctionalRequirement;
            nwbusiness.Business_specific_NFR__c=specificNFR;
            nwbusiness.Business_seasonal_user_load__c=seasonalUserLoad;
            nwbusiness.Business_change_management_program__c=changeManagementProgram;
            
        
        try{
            insert nwbusiness;
        }catch(exception e){
            system.debug('+++++++error is++++++'+e);
        }
        
        //pagereference pageref= new pagereference(
        
    }
    
}
KaityKaity
Hi Suneel,

I have tried your suggestion in the code. But, I am finding Id as null.
14:46:15.048 (48755381)|USER_DEBUG|[36]|DEBUG|ACCOUNT ID Id IDnull

Any suggestion. 

Can you please verify the design. I am using the standard controller as Account here in the visualforce page. ios it correct? Or I should use the standard controller as 'Business__c' in my code.

Currently, I am using as:

 <apex:page standardController="Account" extensions="myBusinessController">

-Kaity
Suneel#8Suneel#8
Kaity,

Yes,you should be passing Account in StandardController attribute of apex:page tag
Are you passing Account id in the URL of VP page you are trying to access like below.

https://c.ap1.visual.force.com/apex/TestMasterDetailRelationship?id=0019000001C7qwi

Also you can use shorter form of declaring variables in Controller for better readability

public String str{get;set;}

And you can restructure your code like below and test.If you receive an error,please post complete message
 
public class myBusinessController {
	public Id accountId{get;set;}
	public myBusinessController(ApexPages.StandardController controller){
		accountId=controller.getId();
	}
	public PageReference saveRecord(){
		nwbusiness.Account__c = accountId;
	}
}

 
KaityKaity
Hi Suneel,
Account ID is not coming here. I have used, system.debug to see what is returning.

    public myBusinessController(ApexPages.StandardController controller){
     accountId=controller.getId();
System.debug('ACCOUNT ID Id ID'+ accountIdNew); 
DEBUG LOG: 
16:04:45.026 (26717156)|USER_DEBUG|[39]|DEBUG|ACCOUNT ID Id IDnull

Something we are missing here.

Thanks,
Kaity
 
Suneel#8Suneel#8
Kaity,Are you passing account id in the URL as I referred in the previous post?
KaityKaity
Hi Suneel,

I am creating the 'Business' object from the relatedlist of account by clicking the 'NEW' button. The whole controller code is as below:

public class myBusinessController {
    Account acc = new Account();
    
    public Id accountIdNew{get;set;}
    public Business__c business{get;set;}
    public ID AccountId= null;
    public List<business__c> bus {get; set;}

    public String id1; 
    public String id2;  
    public String standardizedBusinessProcess;
    public String desiredBusinessOutcomes;
    public String applicationSupport;
    public String stakeholdersBuyins;
    public String currentlyOutsouce;
    public String systems;
    public String cloudBasedPlatforms;
    public String ITStrategy;
    public String investedinCloud;
    public String satisfiedWithCloud;
    public String ITApplicationsSharedBetweenLOB;
    public String users;
    public String risk;
    public String geographicalFootprint;
    public String disparityinITBudget;
    public String multiGeographyEngagement;
    public String nonFunctionalRequirement;
    public String specificNFR;
    public String seasonalUserLoad;
    public String changeManagementProgram;
    public String MyAccount;    
       
    public myBusinessController(ApexPages.StandardController controller){
    this.acc = (Account)controller.getRecord(); 
   // id billAccountId = controller.getId();
    accountIdNew = controller.getId();

    
   System.debug('ACCOUNT ID Id ID'+ accountIdNew); 
   // System.debug('ACCOUNT ID'+ billAccountId); 
    System.debug('WORLD OF CONTROLLER'+ this.acc);
   // bus.add(new business__c(Account__c = Account.id);

    System.debug('@@@@@@@@'+ this.MyAccount);
     /*Id id = ApexPages.currentPage().getParameters().get('id');
        business=(id == null) ? new Business__c() : 
            [SELECT Name FROM Business__c WHERE Id = :id];
        Id id=controller.getId();
        system.debug('=======id is========='+id);*/
        String hostVal  = ApexPages.currentPage().getHeaders().get('Host');
            system.debug('=======Host is========='+hostVal);
        String urlVal = Apexpages.currentPage().getUrl();
            system.debug('=======URL is========='+urlVal );
        String URLL = 'https://' + hostVal+ urlVal;
            system.debug('=======entire URL is========='+URLL);
         id1=urlVal.substring(75,91);
         System.debug('+++++15 digit id+++++'+id1);
         //AccountId=id1;
         system.debug('=======newAccountId is========='+AccountId); 
         
         //List<Account> i=[Select id from Account where id=:id1 limit 1];
         //id1 = '0019000000ld9fBAAQ';            
         //system.debug('=======18 digit AccountId is========='+i);    
         //this.AccountId=Id.valueOf(id1);
         //system.debug('=======AccountId is========='+AccountId); 
       //   public Integer myint{
        //  get{
         //    if(acc == null)
           // acc = [SELECT ID FROM Account where ID = :id1];
      //    }
        
    }
    
    public List<SelectOption> getvalue(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Yes','Yes'));
            options.add(new SelectOption('Partial','Partial'));
            options.add(new SelectOption('No','No'));
        return options;
    }
    public List<SelectOption> getvalue1(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Increase revenue','Increase revenue'));
            options.add(new SelectOption('Decrease costs (increase productivity)','Decrease costs (increase productivity)'));
            options.add(new SelectOption('Increase margins','Increase margins'));
            options.add(new SelectOption('Other','Other'));
        return options;
    }
    public List<SelectOption> getvalue2(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Yes','Yes'));
            options.add(new SelectOption('No','No'));
        return options;
    }
    
    public List<SelectOption> getvalue3(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Yes, cloud based','Yes, cloud based'));
            options.add(new SelectOption('Yes, traditional','Yes, traditional'));
            options.add(new SelectOption('No','No'));
        return options;
    }
    public List<SelectOption> getvalue4(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Low','Low'));
            options.add(new SelectOption('Med','Med'));
            options.add(new SelectOption('High','High'));
            options.add(new SelectOption('None','None'));
        return options;
    }
    public List<SelectOption> getvalue5(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Low','Low'));
            options.add(new SelectOption('None','None'));
            options.add(new SelectOption('High','High'));
        return options;
    }
    public List<SelectOption> getvalue6(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Low','<500K'));
            options.add(new SelectOption('Medi','500 to 2000K'));
            options.add(new SelectOption('High','>2000K'));
        return options;
    }
    public List<SelectOption> getvalue7(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Not at all','Not at all'));
            options.add(new SelectOption('Somewhat','Somewhat'));
            options.add(new SelectOption('Very Satisfied','Very Satisfied'));
        return options;
    }
    public List<SelectOption> getvalue8(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Risk Adverse','Risk Adverse'));
            options.add(new SelectOption('Neutral','Neutral'));
            options.add(new SelectOption('Risk Tolerant','Risk Tolerant'));
        return options;
    }
    public List<SelectOption> getvalue9(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Yes','Yes'));
            options.add(new SelectOption('No','No'));
        return options;
    }
    public List<SelectOption> getvalue10(){
        List<SelectOption> options= new List<SelectOption>();
            options.add(new SelectOption('Important','Important'));
            options.add(new SelectOption('Not Important','Not Important'));
        return options;
    }
    public String getstandardizedBusinessProcess(){
        return standardizedBusinessProcess;
    }
    public void setstandardizedBusinessProcess(String standardizedBusinessProcess){
        this.standardizedBusinessProcess=standardizedBusinessProcess;
    }
    
    public String getdesiredBusinessOutcomes(){
        return desiredBusinessOutcomes;
    }
    public void setdesiredBusinessOutcomes(String desiredBusinessOutcomes){
        this.desiredBusinessOutcomes=desiredBusinessOutcomes;
    }
    
    public String getapplicationSupport(){
        return applicationSupport;
    }
    public void setapplicationSupport(String applicationSupport){
        this.applicationSupport=applicationSupport;
    }
    
    public String getstakeholdersBuyins(){
        return stakeholdersBuyins;
    }
    public void setstakeholdersBuyins(String stakeholdersBuyins){
        this.stakeholdersBuyins=stakeholdersBuyins;
    }
    
    public String getcurrentlyOutsouce(){
        return currentlyOutsouce;
    }
    public void setcurrentlyOutsouce(String currentlyOutsouce){
        this.currentlyOutsouce=currentlyOutsouce;
    }
    
    public String getsystems(){
        return systems;
    }
    public void setsystems(String systems){
        this.systems=systems;
    }
    
    public String getcloudBasedPlatforms(){
        return cloudBasedPlatforms;
    }
    public void setcloudBasedPlatforms(String cloudBasedPlatforms){
        this.cloudBasedPlatforms=cloudBasedPlatforms;
    }
    
    public String getITStrategy(){
        return ITStrategy;
    }
    public void setITStrategy(String ITStrategy){
        this.ITStrategy=ITStrategy;
    }
    
    public String getinvestedinCloud(){
        return investedinCloud;
    }
    public void setinvestedinCloud(String investedinCloud){
        this.investedinCloud=investedinCloud;
    }
    
    public String getsatisfiedWithCloud(){
        return satisfiedWithCloud;
    }
    public void setsatisfiedWithCloud(String satisfiedWithCloud){
        this.satisfiedWithCloud=satisfiedWithCloud;
    }
    
    public String getITApplicationsSharedBetweenLOB(){
        return ITApplicationsSharedBetweenLOB;
    }
    public void setITApplicationsSharedBetweenLOB(String ITApplicationsSharedBetweenLOB){
        this.ITApplicationsSharedBetweenLOB=ITApplicationsSharedBetweenLOB;
    }
    
    public String getusers(){
        return users;
    }
    public void setusers(String users){
        this.users=users;
    }
    
    public String getrisk(){
        return risk;
    }
    public void setrisk(String risk){
        this.risk=risk;
    }
    
    public String getgeographicalFootprint(){
        return geographicalFootprint;
    }
    public void setgeographicalFootprint(String geographicalFootprint){
        this.geographicalFootprint=geographicalFootprint;
    }
    
    public String getdisparityinITBudget(){
        return disparityinITBudget;
    }
    public void setdisparityinITBudget(String disparityinITBudget){
        this.disparityinITBudget=disparityinITBudget;
    }
    
    public String getmultiGeographyEngagement(){
        return multiGeographyEngagement;
    }
    public void setmultiGeographyEngagement(String multiGeographyEngagement){
        this.multiGeographyEngagement=multiGeographyEngagement;
    }
    
    public String getnonFunctionalRequirement(){
        return nonFunctionalRequirement;
    }
    public void setnonFunctionalRequirement(String nonFunctionalRequirement){
        this.nonFunctionalRequirement=nonFunctionalRequirement;
    }
    
    public String getspecificNFR(){
        return specificNFR;
    }
    public void setspecificNFR(String specificNFR){
        this.specificNFR=specificNFR;
    }
    
    public String getseasonalUserLoad(){
        return seasonalUserLoad;
    }
    public void setseasonalUserLoad(String seasonalUserLoad){
        this.seasonalUserLoad=seasonalUserLoad;
    }
    
     public String getchangeManagementProgram(){
        return changeManagementProgram;
    }
    public void setchangeManagementProgram(String changeManagementProgram){
        this.changeManagementProgram=changeManagementProgram;
    }
    
    public Void saveRecord(){
        Business__c nwbusiness =new Business__c ();
           //
           nwbusiness.Account__c = accountIdNew;
          // nwbusiness.Account__c = '0019000000ld9fB';
            nwbusiness.Business_standardized_business_process__c=standardizedBusinessProcess;
           
         /*   nwbusiness.Business_desired_business_outcomes__c=desiredBusinessOutcomes;
            nwbusiness.Business_application_s_support__c=applicationSupport;
            nwbusiness.Business_stakeholders_buy_ins__c=stakeholdersBuyins;
            nwbusiness.Business_currently_outsouce__c=currentlyOutsouce;
            nwbusiness.Business_systems__c=systems;
            nwbusiness.Business_understanding_of_cloud_based_pl__c=cloudBasedPlatforms;
            nwbusiness.Business_IT_strategy__c=ITStrategy;
            nwbusiness.Business_invested_in_cloud__c=investedinCloud;
            nwbusiness.Business_satisfied_with_Cloud__c=satisfiedWithCloud;
            nwbusiness.Business_IT_applications_shared_between__c=ITApplicationsSharedBetweenLOB;
            nwbusiness.Business_users__c=users;
            nwbusiness.Business_risk__c=risk;
            nwbusiness.Business_geographical_footprint__c=geographicalFootprint;
            nwbusiness.Business_disparity_in_IT_budget__c=disparityinITBudget;
            nwbusiness.Business_multi_geography_engagement__c=multiGeographyEngagement;
            nwbusiness.Business_non_functional_requirement__c=nonFunctionalRequirement;
            nwbusiness.Business_specific_NFR__c=specificNFR;
            nwbusiness.Business_seasonal_user_load__c=seasonalUserLoad;
            nwbusiness.Business_change_management_program__c=changeManagementProgram;
            
        */
        try{
            insert nwbusiness;
        }catch(exception e){
            system.debug('+++++++error is++++++'+e);
        }
        
        //pagereference pageref= new pagereference(
        
    }
    
}
 
Suneel#8Suneel#8
OK Kaity, but can you first check by directly accessing the VF page by populating the accunt id in URL

Also let me know how you configured to invoke this page from New button on the related list in Account page.
KaityKaity
Hi Sandeep,

I have not constructed any URL here.
I have overriden the 'NEW' button in the 'Business' object.  By navigating Setup--> Customize---> object---> Business

I checked, by hard coding 18 digits Id. the record got saved. Again I hard coded 15 digits Id, the record didnot save. Can you please check, can we save a record through hardcoding 15 digit id. Many thanks for your time and effort.

-Kaity
KaityKaity
The Debug log: Due to character limitation of 32000, i am sending the section of DEBUG log



 (53685233)|SYSTEM_METHOD_EXIT|[294]|myBusinessController.__sfdc_accountIdNew() 16:47:05.054 (54770884)|DML_BEGIN|[320]|Op:Insert|Type:Business__c|Rows:1 16:47:05.060 (60672910)|DML_END|[320] 16:47:05.060 (60757861)|VF_PAGE_MESSAGE|Required fields are missing: [Account] 16:47:05.060 (60837509)|EXCEPTION_THROWN|[320]|System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Account]: [Account] 16:47:05.061 (61954470)|SYSTEM_METHOD_ENTRY|[322]|String.valueOf(Object) 16:47:05.061 (61990944)|SYSTEM_METHOD_EXIT|[322]|String.valueOf(Object) 16:47:05.062 (62011814)|SYSTEM_METHOD_ENTRY|[322]|System.debug(ANY) 16:47:05.062 (62019673)|USER_DEBUG|[322]|DEBUG|+++++++error is++++++System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Account]: [Account] 16:47:05.062 (62025257)|SYSTEM_METHOD_EXIT|[d(Object) 1
Suneel#8Suneel#8
Kaity,

How were you able to select this VF page while overriding New button on custom object-Business?As this VF page is based on Account StandardController ,you will not be able to see this VF page in the dropdown 'Visualforce Page with'. Am I missing anything here?

Yes we can save the record by hardcoding15 digit id.I have just tried and it worked

First we need to test if this page works standalone by accessing your page like below and adding Business records.If it works,later you can progress to including this page in your app.Change your server node ap1 in below URL.Type the below URL in your address bar,add business records and check if they are getting saved.Ensure that you are using below lines in controller to get the account id instead of hardcoding the id

https://ap1.salesforce.com/apex/YOUR_VF_PAGE_NAME?id=YOUR_15_DIGIT_ACCOUNT_ID
 
public class myBusinessController {
	public Id accountId{get;set;}
	public myBusinessController(ApexPages.StandardController controller){
		accountId=controller.getId();
	}
	public PageReference saveRecord(){
		nwbusiness.Account__c = accountId;
	}
}

 
This was selected as the best answer
KaityKaity
Thanks Sandeep. Your concept is very clear. Actually, initially I have used Business as standard controller and then changed to Account. So, actually to implement the whole process, I have to use 'Business' as the Standard controller. I will try and let you know, if I face any issue.
Many Thanks
- Kaity
Suneel#8Suneel#8
Also in the below line you are gettting 18 digit id into accountId variable.You can verify it by displaying it through System.debug function.First please test the page by directly accessing it through URL and let me know if it is working.

accountId=controller.getId();
KaityKaity
Yes, it does return 18 digits ID.

|[8]|System.debug(ANY) 18:17:51.030 (30122728)|USER_DEBUG|[8]|DEBUG|MY BusinessId:a0U9000000BP8gMEAT 

Thanks.
KaityKaity
Hi Sandeep,
Can you please share your gmail or any contact Id, if possible. It was a good experience to work with you today.

-Kaity
Suneel#8Suneel#8
Kaity,My name is Suneel :) Sure you can reach me at pelluru_suneel1987@yahoo.co.in
Suneel#8Suneel#8
Kaity,Is your issue resolved?
KaityKaity
Yes, Sandeep. Thanks for your help.

-Kaity