• rcardoso
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

Hi!

 

I'm trying to get the existing ID when a DmlException: DUPLICATE_VALUE is throw.

but i'm getting null.

my code looks like this: 

Case c = new Case();
//set some fields
try{
  insert c;
}catch(DmlException e){
  if(e.getDmlType(0) == StatusCode.DUPLICATE_VALUE){
    return e.getDmlId(0); //its null here! =(
  }else{
    throw e;
} } return c.id;

 

I could to put a

c = [Select id from Case where other_fields = other_values];

but i can't be sure if it will get the same record.

 

If I check the logs i find: 

System.DmlException: Upsert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: Claim_id__c duplicates value on record with id: 500J0000001ylwB: []

 

Any ideas how do i get the id without manipulating the message string? 

500J0000001ylwB

Hi!

 

I'm trying to get the existing ID when a DmlException: DUPLICATE_VALUE is throw.

but i'm getting null.

my code looks like this: 

Case c = new Case();
//set some fields
try{
  insert c;
}catch(DmlException e){
  if(e.getDmlType(0) == StatusCode.DUPLICATE_VALUE){
    return e.getDmlId(0); //its null here! =(
  }else{
    throw e;
} } return c.id;

 

I could to put a

c = [Select id from Case where other_fields = other_values];

but i can't be sure if it will get the same record.

 

If I check the logs i find: 

System.DmlException: Upsert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: Claim_id__c duplicates value on record with id: 500J0000001ylwB: []

 

Any ideas how do i get the id without manipulating the message string? 

500J0000001ylwB
I want to get the QueueId from the Queue Sobject and assign it to the Case OwnerId field in Apex.

The QueueId will be based on the SobjectType and the Queue Name.

I am using this query for the purpose.
QueueSobject que = [Select Id, SobjectType, QueueId, Queue.Name from QueueSobject where SobjectType = 'Case' AND Queue.Name = 'Water Application Support'];

But since the Queue Name is not unique (unlike RecordType where you can't have same RecordTypeName for an object), if there are two Queues with the same name and related to same SobjectType, the query will fail to return a single record and my assignment of OwnerId will throw an exception.

Salesforce allows you to create duplicate queue records with the same Name and related SobjectType. There will be no difference between these two records except for their Ids.

But I don't want to hard-code the Id value in the query.

Please suggest me in this to get the appropriate QueueId.

Thanks,
Karthik.