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
Sai deep 13Sai deep 13 

Hi every one Can you please help to write test class for this apex class , Here is my apex class .its urgent please hrelp

public class PatientDemo1_Class {
    public string fileName{get;set;}  
    public Blob fileBody{get;set;}  
Account acc = new Account();
    public Account getacc(){
        acc.Name='PRG';
        return acc;
    }
    public pagereference Saveaccount(){
        insert acc;
        Attachment myAttachment  = new Attachment();  
             myAttachment.Body = fileBody;  
             myAttachment.Name = fileName;  
             myAttachment.ParentId = Acc.Id;  
            insert myAttachment;
        return page.Demo1Thanks;
    }
}

Thanks and regards
Saideep
ShirishaShirisha (Salesforce Developers) 
Hi Sai,

Greetings!

Can you please check the below sample code to insert the Attachment record in Test class and also,please insert the Account record before inserting Attachment to get the AccountId.

http://nmreddy1.blogspot.com/2013/10/writing-apex-test-method-for-insert.html

Kindly let me know if it helps you and close your query by marking it as best answer so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Sai deep 13Sai deep 13
Thank You Siri for responding, I will look a head with the following link