You need to sign in to do that
Don't have an account?

Test Class
I am noew to Salesforce and wanted to write the test class for the below code.......
Need help...
public class UnclaimedGiftsattachment
{
public Unclaimed_Gifts__c objcase{get;set;}
public Attachment myAttachment{get;set;}
public string fileName{get;set;}
public Blob fileBody{get;set;}
public UnclaimedGiftsattachment(Apexpages.standardcontroller controller)
{
objcase = new Unclaimed_Gifts__c();
myAttachment =new Attachment();
}
public pagereference save()
{
insert objcase;
System.debug('@@@@@fileBody'+fileBody);
myAttachment = new Attachment();
if (fileBody !=null){
Integer i=0;
myAttachment.clear();
myAttachment.Body = fileBody;
myAttachment.Name = 'Logo_'+objcase.id+'.jpeg' ;
myAttachment.ParentId = objcase.id;
insert myAttachment;
}
pagereference pr = new pagereference('/'+objcase.id);
return pr;
}
}
Need help...
public class UnclaimedGiftsattachment
{
public Unclaimed_Gifts__c objcase{get;set;}
public Attachment myAttachment{get;set;}
public string fileName{get;set;}
public Blob fileBody{get;set;}
public UnclaimedGiftsattachment(Apexpages.standardcontroller controller)
{
objcase = new Unclaimed_Gifts__c();
myAttachment =new Attachment();
}
public pagereference save()
{
insert objcase;
System.debug('@@@@@fileBody'+fileBody);
myAttachment = new Attachment();
if (fileBody !=null){
Integer i=0;
myAttachment.clear();
myAttachment.Body = fileBody;
myAttachment.Name = 'Logo_'+objcase.id+'.jpeg' ;
myAttachment.ParentId = objcase.id;
insert myAttachment;
}
pagereference pr = new pagereference('/'+objcase.id);
return pr;
}
}
@IsTest
private class TestUnclaimedGiftsattachment {
static testMethod void MyTest(){
//Inserting some test data.
Unclaimed_Gifts__c UGifts = new Unclaimed_Gifts__c( Amount__c=100);
insert UGifts;
Attachment myAttach = new Attachment();
myAttach.ParentId = UGifts.id;
myAttach.name = 'Test File Name';
myAttach.body = blob.valueOf('Test Attachement');
insert myAttach;
PageReference pref = Page.NewUnclaimedGiftsPage;
//Starting test
Test.startTest();
Unclaimed_Gifts__c ObjTest = new Unclaimed_Gifts__c ();
pref = ObjTest.save();
Test.stoptest();
}
}
Its throwing me the error.....'Error: Compile Error: Method does not exist or incorrect signature: [Unclaimed_Gifts__c].save() at line 19 column 17'
I want this to resolve ASAP......Thanks in advance.
This code will work for you.
Thanks for the answer for this, It was really very helpful for me. I am working on some email services and need help again. Can u ple help me over this as well.
Link for my new quwestion is ...
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000Az4IIAS