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
RejonesRejones 

Apex Trigger Test

 

I built this trigger and it works fine in the sandbox before I can move it to production it has to meet 75% or better.  Can anyone help me write a test class for this trigger so that I can get it moved to production?  Here is the trigger.

 

 

1

2
  3
  4
  5
  6
  7
  8
  9 10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47

trigger   OpportunitySubmitForApproval on Opportunity (after insert) {
 
  List<Approval.ProcessSubmitRequest> approvalReqList=new   List<Approval.ProcessSubmitRequest>();
 
 
  for (Opportunity opp: Trigger.New)
 
  {
 
  if (opp.Incentive_Offer__c =='Yes' &&
  opp.RecordTypeID == '012V00000000ESK')
 
  {
 
  // create the new approval request to submit
 
  Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
 
  req.setComments('Submitted for approval. Please approve.');
 
  req.setObjectId(opp.Id);
 
  approvalReqList.add(req);
 
  }
 
  }
 
 
 
  // submit the approval request for processing
 
  List<Approval.ProcessResult> resultList =   Approval.process(approvalReqList);
 
  // display if the reqeust was successful
 
  for(Approval.ProcessResult result: resultList )
 
  {
 
  System.debug('Submitted for approval successfully: '+result.isSuccess());
 
  }
  
  
  }

HariDineshHariDinesh

Hi,

 

Here you have Hardcoded with Id which is not suggestible and will not work properly with different environments.

 

So first please make sure get Record type id dynamically which is best practice.

 

And Below links will be helpful to understand about test Coverage

 

http://teachmesalesforce.wordpress.com/2011/05/07/how-to-write-a-trigger-test/

http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods