You need to sign in to do that
Don't have an account?
shankar sudalaimani
Stcuk in TestCls
Hi all,
I stucked in writing test class for trigger please help me am newbie
MyTrigger:
MyTestClass for above Trigger:
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; } }
Hi Shankar,
What is the problem you are facing?
Thanks
Vivian
Are your getting any error after executing test class ?
Try to do minor change in your test class like below.