function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bharath kumar 52bharath kumar 52 

Test class for a trigger with "callouts"?

Hi All,

I have written a trigger which will supply the location details to a vf page. How can i create a test class for such a trigger?

trigger SetAssetLocation on Asset (after insert, after update) {
    for (Asset a : trigger.new)
        if (a.Location__Latitude__s == null)
            AssetLocation.getLocations(a.id);
    

}
Best Answer chosen by bharath kumar 52
BALAJI CHBALAJI CH
Hi Bharath,
If you just insert an Asset in the Test Class, the Trigger will fire for Code coverage.
Please find below Test Class.
 
@isTest
public class Test_SetAssetLocation {
    
    public static TestMethod void test1()
    {
        Account ac = new Account(name = 'TestAccount');
        insert ac;
        
        Asset a = new Asset();
        a.Name = 'Asset1';
        a.AccountId = ac.id;
        insert a;
        
        a.Name = 'Asset11';
        update a;
    }
}

Let us know if that helps you.

Best regards,
BALAJI

All Answers

BALAJI CHBALAJI CH
Hi Bharath,
If you just insert an Asset in the Test Class, the Trigger will fire for Code coverage.
Please find below Test Class.
 
@isTest
public class Test_SetAssetLocation {
    
    public static TestMethod void test1()
    {
        Account ac = new Account(name = 'TestAccount');
        insert ac;
        
        Asset a = new Asset();
        a.Name = 'Asset1';
        a.AccountId = ac.id;
        insert a;
        
        a.Name = 'Asset11';
        update a;
    }
}

Let us know if that helps you.

Best regards,
BALAJI
This was selected as the best answer
bharath kumar 52bharath kumar 52

Thank you Balaji.

That helps :)