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
Uday KUday K 

Test Class error when inserting QuoteDocument Object

Hello friends,

 

I have inserted QuoteDocument object in test class like below.

        Quote Qu = New Quote();
        qu.Name = 'Test Quote';
        qu.OpportunityId = opp.Id;
        Insert qu;

        string before = 'Testing base 64 encode';
        Blob beforeblob = Blob.valueOf(before);
      
        QuoteDocument qdoc = New QuoteDocument();
        qdoc.QuoteId = qu.Id;

        qdoc.Document = body;
        insert qdoc;

 In the hightlighted its giving error :

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, This field is required: [VersionData]

 

Can someone tell What is VersionData Field, How to pass value in test class. I have searched in salesforce documentation also, I didn't find any such Field of VersionData in QuoteDocument object.

 

Looking ahead for earlier response...

 

Thanks in Advance,

Uday

Best Answer chosen by Admin (Salesforce Developers) 
Sfd developerSfd developer

Hi,

 

The VersionData field didn't appear to be present in the object, but the 'document' field existed and it must be in blob type

 

Try this,

 

qdoc.Document = beforeblob; or

 

qdoc.Document = Blob.toPdf('Test Document'); 

 

 

All Answers

Sfd developerSfd developer

Hi,

 

The VersionData field didn't appear to be present in the object, but the 'document' field existed and it must be in blob type

 

Try this,

 

qdoc.Document = beforeblob; or

 

qdoc.Document = Blob.toPdf('Test Document'); 

 

 

This was selected as the best answer
Uday KUday K

Hello Sfd developer,

 

It worked great.

 

Thanks a tonnn.

Uday