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
davidesidavidesi 

Help with Update Parent Account

I have a visual force page which shows a list of Accounts. Then the user select one account, and when he clicks the button it should assign that selected account as the Parent account in another Account.

 

 

Account a=[Select Id,Name from Account WHERE id=:ApexPages.currentPage().getParameters().get('id')];

Account parentAccount = [Select Id,TIN_Company__c, Name from Account WHERE id=:selectedValue];

 

a.Parent=parentAccount ;

 

try{

Update a;

}catch (Exception e){

}

 

When I execute that code I get no error, In the log I can see the name and Id of both accounts, but no update is performed.

What am I doing bad?

 

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
georggeorg

Hi instead of line

 

a.Parent = parentAccout;

 

use

 

a.parentId = parentAccount.Id and update it.

 

See the relation between account and parent is by lookup whenever there is a lookup the reference is through id's

 

Hope this may help else please reply back.

 

Thanks

George

 

All Answers

georggeorg

Hi instead of line

 

a.Parent = parentAccout;

 

use

 

a.parentId = parentAccount.Id and update it.

 

See the relation between account and parent is by lookup whenever there is a lookup the reference is through id's

 

Hope this may help else please reply back.

 

Thanks

George

 

This was selected as the best answer
souvik9086souvik9086

Try like this

 

a.ParentId = parentAccount.Id;

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks