+ Start a Discussion
VempallyVempally 

Error: Compile Error: Field is not writeable: Quote.AccountId at line 20 column 9

Hi Everyone,

Following is the code which is giving the said error in test class...
 
@isTest

Public Class QuoteDescription_Test{
    Static testMethod void test1(){
   
        Account acc1 = new Account(name = 'Account1');
        insert acc1;
       
        Opportunity opp1 = new Opportunity ();
        opp1.Name = 'Opportunity1';
        opp1.StageName = 'Prospecting';
        opp1.CloseDate = Date.newInstance(2016, 2, 6);
        insert opp1;
        
        Account acc = [Select id, name from Account];
        Opportunity opp = [Select id, name from Opportunity];
        
        Quote quo1 = new Quote();
        quo1.Name = 'Quote1';
        quo1.Accountid = acc.id;
        quo1.Opportunityid = opp.id;
        insert quo1;
        
        quo1.Status = 'Accepted';
        update quo1;
        
        
    }

}

 
Best Answer chosen by Vempally
Amit Chaudhary 8Amit Chaudhary 8
Dnt Add AccountId on Quote it will set automaticly from Opportunity. pLease try below code
 
@isTest

Public Class QuoteDescription_Test
{
    Static testMethod void test1()
	{
        Account acc1 = new Account(name = 'Account1');
        insert acc1;
       
        Opportunity opp1 = new Opportunity ();
        opp1.Name = 'Opportunity1';
        opp1.StageName = 'Prospecting';
        opp1.CloseDate = Date.newInstance(2016, 2, 6);
        insert opp1;
        
        Account acc = [Select id, name from Account];
        Opportunity opp = [Select id, name from Opportunity];
        
        Quote quo1 = new Quote();
        quo1.Name = 'Quote1';
        //quo1.Accountid = acc.id;
        quo1.Opportunityid = opp.id;
        insert quo1;
        
        quo1.Status = 'Accepted';
        update quo1;
			
        
    }

}
Let us know if this will help you
 

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Dnt Add AccountId on Quote it will set automaticly from Opportunity. pLease try below code
 
@isTest

Public Class QuoteDescription_Test
{
    Static testMethod void test1()
	{
        Account acc1 = new Account(name = 'Account1');
        insert acc1;
       
        Opportunity opp1 = new Opportunity ();
        opp1.Name = 'Opportunity1';
        opp1.StageName = 'Prospecting';
        opp1.CloseDate = Date.newInstance(2016, 2, 6);
        insert opp1;
        
        Account acc = [Select id, name from Account];
        Opportunity opp = [Select id, name from Opportunity];
        
        Quote quo1 = new Quote();
        quo1.Name = 'Quote1';
        //quo1.Accountid = acc.id;
        quo1.Opportunityid = opp.id;
        insert quo1;
        
        quo1.Status = 'Accepted';
        update quo1;
			
        
    }

}
Let us know if this will help you
 
This was selected as the best answer
Naval Sharma4Naval Sharma4
Can you update few lines of your code.
Quote quo1 = new Quote(Accountid = acc.id);
quo1.Name = 'Quote1';
quo1.Opportunityid = opp.id;
insert quo1;
        
quo1.Status = 'Accepted';
update quo1;

 
Ajay K DubediAjay K Dubedi
Hi Vempally,

Please comment the LINE Nummber 20 i.e. "quo1.Accountid = acc.id;"

Quote will take the account from associated Opportunity by default, as AccountId on Quote is not creatable.


Thanks,
Ajay