+ Start a Discussion

Test class for below trigger?


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

public class SalesForceToProductViaTrigger {
    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()){
        queryString+=' from Account where id=\''+recordId+'\'';
    public static void updateIsUpdateToFalse(Id recordId){
        update new Account(id=recordId,IDSisUpdateFromWebService__c=false);


Thanks in advance

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;

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