function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Meena25Meena25 

duplicate value found: duplicates value on record with id:

I am getting this error on line 0 in my apex code. This is for spring '19 PD1 maintenance

@RestResource(urlMapping='/secureApexRest')
global with sharing class SecureApexRest {
    @HttpGet
    global static Contact doGet(){
        Id recordId = RestContext.request.params.get('id');
        Contact result;
        if (recordId == null){
            throw new FunctionalException('Id parameter is required');
        }
        List<Contact> results;
        try{
            results = [SELECT id, Name, Secret_Key__c FROM Contact WHERE id=:recordId WITH SECURITY_ENFORCED];
        }catch(QueryException e){}
        
        if (!results.isEmpty()) {
            result = results[0];
        }
        return result;
    }
    public class FunctionalException extends Exception{}
    public class SecurityException extends Exception{}
}

Best Answer chosen by Meena25
Raj VakatiRaj Vakati
The reason for this error is .. 
  1. You might have two apex class with the same name "SecureApexRest "  .. please check is there any apex class is there .. if so delete and recreate 
  2. Can you check is there apex that is existing with the rest api  with the "/secureApexRest"  ..

All Answers

Raj VakatiRaj Vakati
The reason for this error is .. 
  1. You might have two apex class with the same name "SecureApexRest "  .. please check is there any apex class is there .. if so delete and recreate 
  2. Can you check is there apex that is existing with the rest api  with the "/secureApexRest"  ..
This was selected as the best answer
Meena25Meena25
Yes indeed, with developer console loading, saving issues, i had created 2.. Thanks