0
votes

I am new to salesforce development. I am trying to create a visualforce page which helps to insert a new record into the custom object. Custom object has master-detail relationship with account. I am having issue when assiging a default value to the Account. The account already exists in the accounts table. Here is the Apex class I am trying.

public class RelatedAccount{
    
    public Account parent {get; set;}
public RelatedAccount(ApexPages.StandardController controller){
Transaction__c child = (Transaction__c)controller.getRecord();
     if (child.Account__c != null) { parent = [Select ID,Name FROM Account  WHERE Account.Name = :'1Company Inc.,' LIMIT 1];
 child.Account__c = parent; 
}


}}

I am getting the error : "Illegal assignment from Account to Id"

Thanks In advance.

1

1 Answers

1
votes

This should work:

child.Account__c = parent.Id

In your case you try to put the "whole" account object object into the Lookup field. But this just needs the Id of the parent account.