This one is driving me crazy!
Find the code here:
List<BMCServiceDesk__Urgency__c> urgencies = [Select id, name from BMCServiceDesk__Urgency__c];
Debugging this with system.debug(urgencies.size());
I get:
14:20:36:056 USER_DEBUG [80]|DEBUG|0
Now if I query this exactly within the developer console as below:
Select id, name from BMCServiceDesk__Urgency__c
I'm returned with 4 IDs:
What's going on!? I've tried numerous different query methods that all work within the Dev Console but not within my class?
Thanks for looking.
Full code snippet:
global class NewRelicInboundEmailAlerts implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail (Messaging.InboundEmail email, Messaging.InboundEnvelope env) {
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
NewRelicAlert alert;
if (email.binaryAttachments != null && email.binaryAttachments.size() > 0)
{
for (integer i = 0 ; i < email.binaryAttachments.size() ; i++)
{
if (email.binaryAttachments[i].filename.contains('.json')) {
alert = NewRelicAlert.parse(email.binaryAttachments[i].body.toString());
}
}
}
BMCServiceDesk__Incident__c incident = new BMCServiceDesk__Incident__c();
// Deal with the description
String description = '';
description = 'New Relic Incident.\n';
description += '\n\t Account ID: ' + alert.account_id;
description += '\n\t Account Name: ' + alert.account_name;
description += '\n\t Condition ID: ' + alert.condition_id;
description += '\n\t Condition Name: ' + alert.condition_name;
description += '\n\t Condition ID: ' + alert.current_state;
description += '\n\t Condition Name: ' + alert.details;
description += '\n\t Condition ID: ' + alert.event_type;
description += '\n\t Incident Acknowledge URL: ' + alert.incident_acknowledge_url;
description += '\n\t Incident ID: ' + alert.incident_id;
description += '\n\t Incident URL: ' + alert.incident_url;
description += '\n\t Owner: ' + alert.owner;
description += '\n\t Product: ' + alert.targets[0].product;
description += '\n\t Type: ' + alert.targets[0].type_Z;
description += '\n\t Policy Name: ' + alert.policy_name;
description += '\n\t Policy URL: ' + alert.policy_url;
description += '\n\t Severity: ' + alert.severity;
description += '\n\t Violation Chart URL: ' + alert.violation_chart_url;
incident.BMCServiceDesk__incidentDescription__c = description;
// Deal with the category
List<BMCServiceDesk__Category__c> categories = [Select ID from BMCServiceDesk__Category__c where Name = :alert.targets[0].product];
if (categories.size() > 0) {
System.debug('Categories');
System.debug(categories[0].id);
incident.BMCServiceDesk__FKCategory__c = categories[0].id;
} else {
incident.BMCServiceDesk__FKCategory__c = 'a174E0000014bjt';
}
// Deal with the owner
List<User> owners = [Select ID from User where Name = :alert.owner];
if (owners.size() > 0) {
System.debug('Owner');
System.debug(owners[0].id);
incident.OwnerId = owners[0].id;
}
//ALL WORKS UP UNTIL THIS POINT:
// Deal with the priority
List<BMCServiceDesk__Urgency__c> urgencies = [Select id, name from BMCServiceDesk__Urgency__c];
List<BMCServiceDesk__Impact__c> impacts = [Select id, name from BMCServiceDesk__Impact__c];
String urgencyValue = '';
String impactValue = '';
if (alert.severity.equals('CRITICAL')) {
urgencyValue = 'HIGH';
impactValue = 'HIGH';
} else {
urgencyValue = 'MEDIUM';
impactValue = 'MEDIUM';
}
system.debug(urgencies.size());
system.debug(impacts.size());
for (BMCServiceDesk__Urgency__c urgency : urgencies) {
system.debug('urgency');
system.debug(urgency);
if (urgency.name.equals(urgencyValue)) {
incident.BMCServiceDesk__FKUrgency__c = urgency.id;
}
}
for (BMCServiceDesk__Impact__c impact : impacts) {
system.debug('impact');
system.debug(impact);
if (impact.name.equals(impactValue)) {
incident.BMCServiceDesk__FKImpact__c = impact.id;
}
}
// Deal with the source
incident.BMCServiceDesk__contactType__c = 'New Relic';
insert incident;
// Set the result to true. No need to send an email back to the user
// with an error message
result.success = true;
// Return the result for the Apex Email Service
return result;
}
}
with sharing
orwithout sharing
? Is the class executing with you as the context user?