0

I am trying to synchronize salesforce task comments to Jira issues comments and I am getting the following error when I am trying to save the apex class:

Error: Compile Error: No such column 'Assignee__c' on entity 'Task'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 9 column 21

I have the following Apex class:

global class JIRATaskWebserviceCalloutSyncFields {
    @future (callout=true)
    WebService static void syncfields(String JIRA_Key) {
        //Modify these variables:
        String username = 'yourusername';
        String password = 'yourpassword';
        String jiraURL = ' http://youjiraurl.com';

        sObject s = [SELECT Subject, Assignee__c, Priority, Requested_By__c FROM Task WHERE JIRA_Key__c = :JIRA_key LIMIT 1];
        String c_summary = (String) s.get('Subject');
        String c_assignee = (String) s.get('Assignee__c');
        String c_priority = (String) s.get('Priority');
        String c_requested_by = (String) s.get('Requested_By__c');

         String priorityId;
        //Map Salesforce Prority to JIRA Prority
        if (c_priority  == 'Blocker') {                 // Salesforce.com Priority
            priorityId = '1';                           // JIRA Priority ID
        } else if (c_priority  == 'Critical') {
            priorityId = '2';
        } else if (c_priority  == 'Major') {
            priorityId = '3';
        } else if (c_priority == 'Minor') {
            priorityId = '4';
        } else if (c_priority == 'Trivial') {
            priorityId = '5';
        }

        //Construct HTTP request and response
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();

        //Construct Authorization and Content header
        Blob headerValue = Blob.valueOf(username+':'+password);
        String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
        req.setHeader('Authorization', authorizationHeader);
        req.setHeader('Content-Type','application/json');


        //Construct Endpoint
        String endpoint = jiraURL+'/rest/api/2/issue/'+JIRA_Key;

        //Set Method and Endpoint and Body
        req.setMethod('PUT');
        req.setEndpoint(endpoint);
        req.setBody('{ \"fields\":{\"summary\": \"'+c_summary+'\", \"assigne\":{\"name\":\"'+c_assignee+'\"}, \"priority\":{\"id\":\"'+priorityId+'\"}, \"customfield_10400\":{\"value\":\"'+c_requested_by+'\"}}}');

        try {
            //Send endpoint to JIRA
            res = http.send(req);
        } catch(System.CalloutException e) {
            System.debug('ERROR:' + e);
            System.debug(res.toString());
        }
    }
}

In the error, the line 9 with the Assignee__C is basically a case field(apex class is also designed for case, and I replaced the case with Task),I trying to clone this onto Task. And Task doesn't have the Assignee__C field. How can get rid of this criteria in order to save the class

1
  • Thanx for the edit @adrian! – abhi Feb 6 '17 at 22:14
1

Just remove the references to it. You have three:

  1. Query

    SELECT Subject, Assignee__c, ...
    

    Change to:

    SELECT Subject, ...
    
  2. Getter

    String c_assignee = (String) s.get('Assignee__c');
    

    Just remove this line entirely

  3. JSON

    '...'+c_summary+'\", \"assigne\":{\"name\":\"'+c_assignee+'\"}, \"priority\":...'
    

    Remove the {"name": <c_assignee>} portion of this markup.

    '...'+c_summary+'\", \"priority\":...'
    

Also, it's much easier to work with JSON if you create classes to serialize to/from.

2
  • Hello @Adrian, Should I also remove "Requested by" and its respective references. I don't have that anywhere. – abhi Feb 6 '17 at 22:48
  • @abhi Surely you can extend the pattern to figure out how to remove that field as well... – Adrian Larson Feb 7 '17 at 1:37
1

If this class is only designed for Tasks simply remove the field, but you may want the Task Owner Name or owner.Name so use that

global class JIRATaskWebserviceCalloutSyncFields {
    @future (callout=true)
    WebService static void syncfields(String JIRA_Key) {
        //Modify these variables:
        String username = 'venkatdavuluri';
        String password = 'Wildcraft@987';
        String jiraURL = ' http://jira.hdwuotecenter.com';

        sObject s = [SELECT Subject, Owner.Name, Priority, Requested_By__c FROM Task WHERE JIRA_Key__c = :JIRA_key LIMIT 1];
        String c_summary = (String) s.get('Subject');
        String c_assignee = (String) s.get('Owner.Name');
        String c_priority = (String) s.get('Priority');
        String c_requested_by = (String) s.get('Requested_By__c');

        ...................

        req.setBody('{ \"fields\":{\"summary\": \"'+c_summary+'\", \"assigne\":{\"name\":\"'+c_assignee+'\"}, \"priority\":{\"id\":\"'+priorityId+'\"}, \"customfield_10400\":{\"value\":\"'+c_requested_by+'\"}}}');


      ....................      

    }
}

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.