• Hazel Egan
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 9
    Replies
I'm very new to Salesforce and have written a class to export an opportunity to csv. It now exports correctly but when trying to write a test class I'm getting the above error when trying to reference the method within my class. I'm also not sure what to write for the assert method. As I'm new to this I'm really lost, any help would be appreciated.

exportCSV class:

public with sharing class exportCSV {
    public string header{get;set;}
    public String currentRecordId {get;set;}
    public String rId {get;set;}
    public List<Opportunity> AllOpenOpportunities {get; private set;} 
    public exportCSV() {
        header = 'Acc_Ref__c,Purchase_Order_Number1__c,Position__c,Total_Hours_Required__c,Shift_Start_Date__c,Shift_End_Date__c,Number_of_Shifts__c,Hours_per_Shift__c,Shift_Time__c,Pay_Code__c,Opportunity_Unique_Reference__c\r';
        rId  = ApexPages.currentPage().getHeaders().get('Referer');
        Id currentRecordId = rId.right(15);
        AllOpenOpportunities = [SELECT id, Name, Acc_Ref__c, Purchase_Order_Number1__c, Position__c, Total_Hours_Required__c, Shift_Start_Date__c, Shift_End_Date__c,Number_of_Shifts__c,Hours_per_Shift__c,Shift_Time__c,Pay_Code__c, Opportunity_Unique_Reference__c
                            FROM Opportunity 
                            WHERE id =: currentRecordId];
    }
}


Test class so far:

@isTest                    
public class TestClassOne {

    public static testMethod void testMethodOne() {
        // Create Account Data
        Account acc = new Account(Name='TestAcc');
        insert acc;

        // Create Opportunity Data
        Opportunity opp = new Opportunity(Name='Test Opp', AccountId=acc.Id);
        insert opp;
        system.currentPageReference().getParameters().put('currentRecordId', opp.Id);
        exportCSV conObj = new exportCSV();
        Test.startTest();
        // Call Methods of the class
        conObj.exportCSV();
        Test.stopTest();
        // Write assert statements
    }   
}

 
I'm very new to Salesforce and have written a class to export an opportunity to csv. It now exports correctly but when trying to write a test class I'm getting the above error when trying to reference the method within my class. I'm also not sure what to write for the assert method. As I'm new to this I'm really lost, any help would be appreciated.

exportCSV class:

public with sharing class exportCSV {
    public string header{get;set;}
    public String currentRecordId {get;set;}
    public String rId {get;set;}
    public List<Opportunity> AllOpenOpportunities {get; private set;} 
    public exportCSV() {
        header = 'Acc_Ref__c,Purchase_Order_Number1__c,Position__c,Total_Hours_Required__c,Shift_Start_Date__c,Shift_End_Date__c,Number_of_Shifts__c,Hours_per_Shift__c,Shift_Time__c,Pay_Code__c,Opportunity_Unique_Reference__c\r';
        rId  = ApexPages.currentPage().getHeaders().get('Referer');
        Id currentRecordId = rId.right(15);
        AllOpenOpportunities = [SELECT id, Name, Acc_Ref__c, Purchase_Order_Number1__c, Position__c, Total_Hours_Required__c, Shift_Start_Date__c, Shift_End_Date__c,Number_of_Shifts__c,Hours_per_Shift__c,Shift_Time__c,Pay_Code__c, Opportunity_Unique_Reference__c
                            FROM Opportunity 
                            WHERE id =: currentRecordId];
    }
}


Test class so far:

@isTest                    
public class TestClassOne {

    public static testMethod void testMethodOne() {
        // Create Account Data
        Account acc = new Account(Name='TestAcc');
        insert acc;

        // Create Opportunity Data
        Opportunity opp = new Opportunity(Name='Test Opp', AccountId=acc.Id);
        insert opp;
        system.currentPageReference().getParameters().put('currentRecordId', opp.Id);
        exportCSV conObj = new exportCSV();
        Test.startTest();
        // Call Methods of the class
        conObj.exportCSV();
        Test.stopTest();
        // Write assert statements
    }   
}