+ Start a Discussion
kvm1231kvm1231 

Test class for below trigger?

Hi,

Can you please let me know any one, how to write the test class for below trigger.

public class SalesForceToProductViaTrigger {
    @future(callout=true)
    public static void SendCustomer(Id recordId){
        Account acc;
        string queryString='select Id,Name';
        Map<String,SObjectField> fmap=Schema.SObjectType.Account.fields.getMap();
        DescribeFieldResult f;
        for(SObjectField field:fmap.values()){
            f=field.getDescribe();
            if(f.isCustom()){
                queryString+=','+f.getName();
            }
        }
        queryString+=' from Account where id=\''+recordId+'\'';
        acc=(Account)Database.query(queryString)[0];
        //SalesForceToProduct.SendCustomer(acc);
        SalesForceToProduct.SendCustomerNew(acc);
    }
    @future
    public static void updateIsUpdateToFalse(Id recordId){
        update new Account(id=recordId,IDSisUpdateFromWebService__c=false);
    }

}

Thanks in advance

​KVM
Amit Chaudhary 8Amit Chaudhary 8
Can you please post the trigger code as well from where you are calling above class ?

If you need test class for above class only then try like below
// Create Account record
 
Account acc = new Account();
acc.name ='test';
// Add all required field
insert acc;

SalesForceToProductViaTrigger.SendCustomer(acc.id);
SalesForceToProductViaTrigger.updateIsUpdateToFalse(acc.id);
I hope this will help you

I will recommend you to start using trailhead to learn about test classes
1) https://trailhead.salesforce.com/modules/apex_testing

Also please check below post
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
2) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm

Pleasse check below post sample test class
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html


Let us know if this will help you