• JRP SC
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hello,

Need some help in creating test class for the following extension bellow. I am using an Account standardcontroller.
 
public class GetContactFromAccount {
    
    public Contact contact {get;set;}
    public Account account {get;set;}
    private final ApexPages.StandardController controller;
    
    public getContactFromAccount(ApexPages.StandardController controller){
        this.controller = controller;
        account = (Account)controller.getRecord();
        contact = new Contact();
    }    
    
    public PageReference save(){
        insert account;
        contact.MailingStreet = account.BillingStreet;
        contact.MailingCity = account.BillingCity;
        contact.MailingState = account.BillingState;
        contact.MailingPostalCode = account.BillingPostalCode;
        contact.MailingState = account.BillingCountry;        
        contact.AccountId = account.Id;
        contact.Type__c = 'Subscriber';
        insert contact;
        Pagereference pageRef = New PageReference('/'+account.Id);
        System.debug(contact);
        return pageRef;
    }
    
}

Thank you!