0

I have a scheduled class that runs over my Incident records each day to check if any have been resolved for 30,31,32 days.

If it finds any, it should update the status to closed.

An Incident record looks up to the Status object.

The status on Incident is a lookup field called BMCServiceDesk__FKStatus__c

I've been told I need to get the BMCServiceDesk__FKStatus__crecord named "Closed" which has an Id of a4Bw0000000CcCNEA0 somewhere near the start of my code. I need some help on how to do this as I've tried creating a new list for BMCServiceDesk__Status__c object, but it says that i have "Illegal assignment from List to List"

global class Set_Status_Closed_Scheduled  Implements Schedulable // If an Incident has in a static Resolved state for 30 days, change it to Closed
{
global void execute (SchedulableContext sc)
{
    changeStatusToClosed();
}
public void changeStatusToClosed()
{
    // Get Status ID for the ‘Closed’ status.

    List<BMCServiceDesk__Status__c> ClosedStatus = new List <BMCServiceDesk__Status__c>();

    ClosedStatus = [SELECT Id FROM BMCServiceDesk__Status__c WHERE Name = 'Closed'];

    List<BMCServiceDesk__Incident__c> listIncident = new List <BMCServiceDesk__Incident__c>();

    List<BMCServiceDesk__Incident__c> updateListIncident = new list <BMCServiceDesk__Incident__c>();


    // Below query fetches records from 30 to 32 days. As per our discussion the incident should be closed
    //only after 30 days. So modify below filter logic.
    listIncident = [SELECT Id FROM BMCServiceDesk__Incident__c
                    WHERE (BMCServiceDesk__Status_ID__c = 'Resolved'
                           OR BMCServiceDesk__TemplateName__c = 'Incident Resolved')
                    AND BMCServiceDesk__FKRequestDefinition__c = ''
                    AND (BMCServiceDesk__StatusChangeDate__c = LAST_N_DAYS:30
                         OR BMCServiceDesk__StatusChangeDate__c = LAST_N_DAYS:31
                         OR BMCServiceDesk__StatusChangeDate__c = LAST_N_DAYS:32) LIMIT 100];
    for(BMCServiceDesk__Incident__c up: listIncident)
    {

        up.BMCServiceDesk__FKStatus__c = 'a4Bw0000000CcCNEA0';

        updateListIncident.add(up);
    }

    update updateListIncident;
}

}
6
  • 3
    ClosedStatus list should be of type BMCServiceDesk__Status__c.
    – Mr.Frodo
    Commented Apr 13, 2017 at 11:23
  • Still have the same issue @Mr.Frodo. I've updated my code though thanks
    – Glenn Daly
    Commented Apr 13, 2017 at 11:30
  • Your list construction still constructs a list of BMCServiceDesk__Category__c Commented Apr 13, 2017 at 11:51
  • Thanks, don't appear to be any issues in dev console now :)
    – Glenn Daly
    Commented Apr 13, 2017 at 11:55
  • @GlennDaly Please don't edit your question to make changes suggested in comments and answers. It makes it very hard for other people to see/verify what your problem was. For example, unless I had looked through the edit history on your question, I wouldn't have known that IllusiveBrian got the right answer (you had edited your question to fix the issue by the time I got here).
    – Derek F
    Commented Apr 13, 2017 at 12:45

1 Answer 1

2

Your new operator is constructing a List<BMCServiceDesk_Category__c> and assigning it to a List<BMCServiceDesk_Status__c>, which is causing your error. That whole line is completely unnecessary though, you can remove it. I've updated your code to remove the unnecessary initializations, and also adjusted the query to use "greater than or equal" and "less than or equal" to dates in order to make it more maintainable.

public void changeStatusToClosed()
{
    // Get Status ID for the ‘Closed’ status.

    List<BMCServiceDesk__Status__c> ClosedStatus = [SELECT Id FROM BMCServiceDesk__Status__c WHERE Name = 'Closed'];

    //You can also use ID ClosedStatus = [select ID...].ID if there is only one

    List<BMCServiceDesk__Incident__c> listIncident = [SELECT Id FROM BMCServiceDesk__Incident__c
                    WHERE (BMCServiceDesk__Status_ID__c = 'Resolved'
                           OR BMCServiceDesk__TemplateName__c = 'Incident Resolved')
                    AND BMCServiceDesk__FKRequestDefinition__c = ''
                    AND (BMCServiceDesk__StatusChangeDate__c >= LAST_N_DAYS:30
                         AND BMCServiceDesk__StatusChangeDate__c <= LAST_N_DAYS:32) LIMIT 100];
    for(BMCServiceDesk__Incident__c up: listIncident)
    {

        up.BMCServiceDesk__FKStatus__c = ClosedStatus[0].ID;//'a4Bw0000000CcCNEA0';
    }

    update listIncident;
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .