You need to sign in to do that
Don't have an account?
Keith Stephens 18
Trigger testing
Hello all,
I am new with Apex and Salesforce so bare with me.
Up until now all the triggers I have written work just fine in Dev/QA and production.
But now I have this one trigger that needs a test class, but I am not sure where to being.
If someone can help me develop a test class that for the trigger below, then I should be able to understand how to test my triggers in the future. How to get the data needed to test the triggers ect...
Thanks,
Keith.
I am new with Apex and Salesforce so bare with me.
Up until now all the triggers I have written work just fine in Dev/QA and production.
But now I have this one trigger that needs a test class, but I am not sure where to being.
If someone can help me develop a test class that for the trigger below, then I should be able to understand how to test my triggers in the future. How to get the data needed to test the triggers ect...
Thanks,
Keith.
trigger MostRecentCenter on Procedure__c (after insert, after update) { try{ Set<Id> procIds = new Set<Id>(); Set<Id> caseIds = new Set<Id>(); List<Case> lstCase = new List<Case>(); for(Procedure__c proc : Trigger.New) { if(proc.CreatedDate != null) { procIds.add(proc.LastModifiedById); caseIds.add(proc.Case__c); } } Map<string, Procedure__c> procMap = new map<string, Procedure__c> ( [SELECT CenterID__c, Center__c from Procedure__c where LastModifiedById IN: procIds Order by CreatedDate Desc] ); Map<string, Case> caseMap = new map<string, Case> ( [SELECT Id, Most_Recent_Center__c FROM Case WHERE Id IN: caseIds] ); for(Procedure__c pd: trigger.new) { //system.debug(pd.id); if(procMap.containsKey(pd.id)) { //Id centerID = (Id)procMap.get(pd.id).Center__c; //Case cs = (Case)[SELECT Id, Most_Recent_Center__c FROM Case WHERE Id = :pd.Case__c]; //cs.Most_Recent_Center__c = centerID; caseMap.get(pd.Case__c).Most_Recent_Center__c = procMap.get(pd.id).Center__c; lstCase.add(caseMap.get(pd.Case__c)); } } //system.debug(lstCase.size()); if(lstCase.size()>0) update lstCase; // } //End of trigger.isBefore }catch(Exception e){ //Package suspended, uninstalled or expired, exit gracefully. System.debug('MostRecentCenter'); } }
Try Below Code. IF this helps you then mark it solved.
Thanks
Hemant
All Answers
Try Below Code. IF this helps you then mark it solved.
Thanks
Hemant
thank you a bunch.
Keith.