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
shankar sudalaimanishankar sudalaimani 

Stcuk in TestCls

Hi all,
I stucked in writing test class for trigger please help me am newbie

MyTrigger:
trigger onCustomerUpdate on Account (after update) {
	try
	{
		// Get all Lead Sharing records
		SPG_Approval_request__c[] SPGRecords = [Select Id, Customer_Name__c from SPG_Approval_request__c where Customer_Name__c in :trigger.newMap.keySet()];
		
		Set<Id> SPGIds = new Set<Id>();
		for(SPG_Approval_request__c SPG : SPGRecords)
			SPGIds.add(SPG.Id);
		/*	
		// Get the existing sharing rules for the lead sharings and delete them
		for(SPG_Approval_request__Share[] SPGRecordShares : [Select Id from SPG_Approval_request__Share where parentId in :SPGIds and RowCause = 'Derived_From_Customer__c'])
			delete SPGRecordShares;
		*/
		System.debug('DML Rows Processed : ' + Limits.getDMLRows());
		// Insert the new sharing rules 
		inheritSharingForSPG.inheritSharingFromCustomer(SPGIds);		
	}
	catch(Exception e)
	{
		trigger.new[0].addError('Following Exception Occurred: ' + e.getMessage() + '\n. Please contact the system administrator with the error message.');
	}	
}

MyTestClass for above Trigger:
@isTest
public class onCustomerUpdateTest {
    static testMethod void TestMethodonCustomerUpdate(){
        Account a=new account();
        a.name='Test Account';
        insert a;
        SPG_Approval_request__c  s=new SPG_Approval_request__c();
        s.Customer_Name__c=a.Id;
        s.Document_Name__c='DB';
        insert s;
        a.name='change';
        update a;

         }
}

 
Vivian Charlie 1208Vivian Charlie 1208

Hi Shankar,

 

What is the problem you are facing?

 

Thanks

Vivian

shankar sudalaimanishankar sudalaimani
It's shows 0% code coverage .i don't know why ,Vivan.Please, tell me some suggestion
brahmaji tammanabrahmaji tammana
Please post  inheritSharingForSPG code.
Amit Chaudhary 8Amit Chaudhary 8
Hi Shankar ,

Are your getting any error after executing test class ?

Try to do minor change in your test class like below.
@isTest
public class onCustomerUpdateTest 
{
    static testMethod void TestMethodonCustomerUpdate()
	{
        Account a=new account();
        a.name='Test Account';
        insert a;
		
        SPG_Approval_request__c  s=new SPG_Approval_request__c();
        s.Customer_Name__c=a.Id;
        s.Document_Name__c='DB';
        insert s;
		
		try
		{
			a.name='change';
			update a;
		}
		Catch(Exception ee)
		{
			
		}
    }
}