• Kiran G
  • NEWBIE
  • 15 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 8
    Replies
Hi Everyone,
I need help with a test class for the apex class below. I have got to somewhere with some help but I am still getiing errors with the code.

Extension Class:
public with sharing class ProcurementExtension {
private ApexPages.StandardController controller;
 
    private Set<String> ProcurementFields = new Set<String>();
     
    public ProcurementExtension (ApexPages.StandardController controller) {
        this.controller = controller;
        Map<String, Schema.SobjectField> fields =
        Schema.SobjectType.Procurement__c.fields.getMap();
 

        for (String s : fields.keySet()) {
        // Only include accessible fields
            if (fields.get(s).getDescribe().isAccessible() &&
                fields.get(s).getDescribe().isCustom()) {
                    ProcurementFields.add(s);
            }
        }
    }
     
    public  List<String> availableFields {
        get {
            controller.reset();
            controller.addFields(new List<String>(ProcurementFields));
                return new List<String>(ProcurementFields);
        }
    }
}

Test Class:

@isTest
private class testProcurementExtension{
    Private static testMethod void ProcurementExtension(){
        Account acc=new Account(Account_Type__c='Product Vendor'); {need to also add Account_Type__c='Service Provider' which is also a filter criteria}
        acc.Name='TestAccount';
        acc.Customer_Tin_CST__c='Test CST';
        insert acc;
        acc=[SELECT id,Name, Customer_Tin_CST__c FROM Account WHERE id=:acc.Id];
        System.assertEquals(acc.Name,'TestAccount');
        System.assertEquals(acc.Customer_Tin_CST__c,'Test CST');
        Procurement__c objProcurement = new Procurement__c();
        objProcurement.Vendor__c = acc.id;        

        insert objProcurement;
        objProcurement=[SELECT id,Name FROM Procurement__c WHERE id=:objProcurement.Id];
        System.assertEquals(objProcurement.Name,'Test');
        

        
        Test.startTest();
          ApexPages.StandardController stdCon=new ApexPages.StandardController(objProcurement);
          ProcurementExtension pex=new ProcurementExtension(stdCon);
        Test.stopTest();

    }
    }

Error

System.AssertException: Assertion Failed: Expected: JLS P - 121215 - 100001, Actual: Test

Please note:
Vendor_c is a lookup to accounts with crieteria that the Account_Type__c='Product Vendor' or 'Service Provider''
Procurement.Name is a auto number.

Please help!
Hi,

I have a custom object called procurement with and extension which is used by a visual force page. It works fine but now i need to move it to production and after trying out a lot I am not able to write a test class that works. Please help me write a test for the below extension class . I have also pasted the test class that I tried but doesn't work. Not sure if I am going in the right direction.

Extension class
public with sharing class ProcurementExtension {
private ApexPages.StandardController controller;
 
    private Set<String> ProcurementFields = new Set<String>();
     
    public ProcurementExtension (ApexPages.StandardController controller) {
        this.controller = controller;
        Map<String, Schema.SobjectField> fields =
        Schema.SobjectType.Procurement__c.fields.getMap();
 

        for (String s : fields.keySet()) {
        // Only include accessible fields
            if (fields.get(s).getDescribe().isAccessible() &&
                fields.get(s).getDescribe().isCustom()) {
                    ProcurementFields.add(s);
            }
        }
    }
     
    public  List<String> availableFields {
        get {
            controller.reset();
            controller.addFields(new List<String>(ProcurementFields));
                return new List<String>(ProcurementFields);
        }
    }
}

Test Class I have so far

@isTest

private class testProcurementExtension
{static testMethod void ProcurementExtension(){

Procurement__c objProcurement = new Procurement__c();
    objProcurement.Name = 'Test';
    objProcurement.Account__c = 'Test Account';
    insert objProcurement;



// Start the test, this changes governor limit context to

        // that of trigger rather than test.
test.startTest();

        ApexPages.currentPage().getParameters().put('lc',objProcurement.id);
        
        


test.stopTest();

}

}
Hi Everyone,
I need help with a test class for the apex class below. I have got to somewhere with some help but I am still getiing errors with the code.

Extension Class:
public with sharing class ProcurementExtension {
private ApexPages.StandardController controller;
 
    private Set<String> ProcurementFields = new Set<String>();
     
    public ProcurementExtension (ApexPages.StandardController controller) {
        this.controller = controller;
        Map<String, Schema.SobjectField> fields =
        Schema.SobjectType.Procurement__c.fields.getMap();
 

        for (String s : fields.keySet()) {
        // Only include accessible fields
            if (fields.get(s).getDescribe().isAccessible() &&
                fields.get(s).getDescribe().isCustom()) {
                    ProcurementFields.add(s);
            }
        }
    }
     
    public  List<String> availableFields {
        get {
            controller.reset();
            controller.addFields(new List<String>(ProcurementFields));
                return new List<String>(ProcurementFields);
        }
    }
}

Test Class:

@isTest
private class testProcurementExtension{
    Private static testMethod void ProcurementExtension(){
        Account acc=new Account(Account_Type__c='Product Vendor'); {need to also add Account_Type__c='Service Provider' which is also a filter criteria}
        acc.Name='TestAccount';
        acc.Customer_Tin_CST__c='Test CST';
        insert acc;
        acc=[SELECT id,Name, Customer_Tin_CST__c FROM Account WHERE id=:acc.Id];
        System.assertEquals(acc.Name,'TestAccount');
        System.assertEquals(acc.Customer_Tin_CST__c,'Test CST');
        Procurement__c objProcurement = new Procurement__c();
        objProcurement.Vendor__c = acc.id;        

        insert objProcurement;
        objProcurement=[SELECT id,Name FROM Procurement__c WHERE id=:objProcurement.Id];
        System.assertEquals(objProcurement.Name,'Test');
        

        
        Test.startTest();
          ApexPages.StandardController stdCon=new ApexPages.StandardController(objProcurement);
          ProcurementExtension pex=new ProcurementExtension(stdCon);
        Test.stopTest();

    }
    }

Error

System.AssertException: Assertion Failed: Expected: JLS P - 121215 - 100001, Actual: Test

Please note:
Vendor_c is a lookup to accounts with crieteria that the Account_Type__c='Product Vendor' or 'Service Provider''
Procurement.Name is a auto number.

Please help!
Hi,

I have a custom object called procurement with and extension which is used by a visual force page. It works fine but now i need to move it to production and after trying out a lot I am not able to write a test class that works. Please help me write a test for the below extension class . I have also pasted the test class that I tried but doesn't work. Not sure if I am going in the right direction.

Extension class
public with sharing class ProcurementExtension {
private ApexPages.StandardController controller;
 
    private Set<String> ProcurementFields = new Set<String>();
     
    public ProcurementExtension (ApexPages.StandardController controller) {
        this.controller = controller;
        Map<String, Schema.SobjectField> fields =
        Schema.SobjectType.Procurement__c.fields.getMap();
 

        for (String s : fields.keySet()) {
        // Only include accessible fields
            if (fields.get(s).getDescribe().isAccessible() &&
                fields.get(s).getDescribe().isCustom()) {
                    ProcurementFields.add(s);
            }
        }
    }
     
    public  List<String> availableFields {
        get {
            controller.reset();
            controller.addFields(new List<String>(ProcurementFields));
                return new List<String>(ProcurementFields);
        }
    }
}

Test Class I have so far

@isTest

private class testProcurementExtension
{static testMethod void ProcurementExtension(){

Procurement__c objProcurement = new Procurement__c();
    objProcurement.Name = 'Test';
    objProcurement.Account__c = 'Test Account';
    insert objProcurement;



// Start the test, this changes governor limit context to

        // that of trigger rather than test.
test.startTest();

        ApexPages.currentPage().getParameters().put('lc',objProcurement.id);
        
        


test.stopTest();

}

}
Hi,

I am Prasant.I am new to salesforce developemnet.I have learnet most of the salesforce concepts like Apex,triggers,API's and salesforce customization.I have practiced with varuous uses cases form this forum.However i still don't have experience of a full time project.So if any body can help me in this context.

Thanks in advance,
Prasant