I attempted to modify what @Martin F. gave me in my first question but its still above my head. I went back and tried again. My attempt worked but it kept running an infinite loop and created 117 Jira issues. So it seems I need to check if the Approved__C checkbox was initially unchecked/false. I found some posts about 'Trigger.oldMap' and tried to incorporate it in the code. This also has not worked. Here is a sample of what I came up with. I read another post that the Trigger.oldMap doesn't work with Future callouts, the class that goes with this trigger is a future callout

Error line:

if(c.Approved__c && !Trigger.oldMap(c.Id).Approved__c)

Error message:

Variable does not exist: Trigger at line 9 column 25

I am completely stumped after trying to read about the trigger.oldMap use and actually editing the code to try to fix the problem. How can I fix this code so it compiles?

    trigger CreateIssue on CDR__c (after update) {

// Check whether current user is not JIRA agent so that we don't create an infinite loop.
if (JIRA.currentUserIsNotJiraAgent()) {

for (CDR__c c : Trigger.new) {

//Check each record if approved by approval process
if(c.Approved__c && !Trigger.oldMap(c.Id).Approved__c){ //ERROR Variable does not exist: Trigger at line 9 column 25

  // Define parameters to be used in calling Apex Class
  String objectType = 'CDR__c'; // Please change this according to the object type
  String objectId = c.id;
  String projectKey = 'CDR'; //Please change this according to the JIRA project key
  String issueType = '10001';   //Please change this according to the JIRA issue type ID
  // Calls the actual callout to create the JIRA issue.
  JIRAConnectorWebserviceCalloutCreate.createIssue(JIRA.baseUrl, JIRA.systemId, objectType, objectId, projectKey, issueType);

  • 2
    Trigger.oldMap.get(c.Id).Approved__c should compile. – Keith C Jan 5 '18 at 17:06
  • @KeithC & AdrianLarson. I don't know how many hours I have spent trying to learn how to get this to compile. Truly appreciate it! – PJ Greene Jan 5 '18 at 17:23
  • No problem. The compiler error messages can be misleading. – Keith C Jan 5 '18 at 17:30

Instead of:

//            ^ you can't call a map as if it were a function


//            ^ you call a method on the map instead

A more verbose version of what you are trying to do may be illustrative:

Map<Id, CDR__c> oldMap = trigger.oldMap;
CDR__c oldRecord = oldMap.get(c.Id);
Boolean wasApproved = oldRecord.Approved__c;

if (c.Approved__c && !wasApproved)
    // do stuff

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.