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
ManvithaManvitha 

Method does not exist or incorrect signature: void getDuplicateResult() from the type Database.SaveResult

Hi All , Can someboy help me to resolve this issue?Method does not exist or incorrect signature: void getDuplicateResult() from the type Database.SaveResult ....I am using it in my test class 

 

Database.DMLOptions dmlOpts = new Database.DMLOptions();
dmlOpts.DuplicateRuleHeader.allowSave = true;
Database.SaveResult saveResult = Database.insert(duplicateAcc, dmlOpts);
System.assert(saveResult.isSuccess());
DuplicateRecordSet drs = [SELECT Id FROM DuplicateRecordSet WHERE Id =:saveResult.getDuplicateResult().getDuplicateRecordSetId()];
 

Mukesh pal 7Mukesh pal 7

In this case, it looks like you're trying to call a method called "getDuplicateResult" on an instance of the Database.SaveResult class, but that method doesn't actually exist. It's possible that you meant to call a different method with a similar name or signature.
To fix this error, you should first make sure that the method you're trying to call actually exists and that you're using the correct method name and signature. You can consult the Apex documentation or the codebase you're working with to find the correct method signature.
Alternatively, if you're trying to get information about duplicate records that were detected during a save operation, you may want to use the Database.DmlResult class instead. The Database.DmlResult class provides a getDuplicateResults method that returns a list of Database.DuplicateResult objects, which contain information about any duplicate records that were detected during the save operation.
Here's an example of how you could use the Database.DmlResult class to get information about duplicate records:

For Example:


Account acc = new Account(Name = 'Test Account');
Database.SaveResult result = Database.insert(acc, false);

if (result.isSuccess()) {
    System.debug('Account saved successfully.');
} else {
    for (Database.Error error : result.getErrors()) {
        if (error instanceof Database.DuplicateError) {
            Database.DuplicateError duplicateError = (Database.DuplicateError) error;
            List<Database.DuplicateResult> duplicateResults = duplicateError.getDuplicateResults();
            for (Database.DuplicateResult duplicateResult : duplicateResults) {
                System.debug('Duplicate record found: ' + duplicateResult.getDuplicateRecord());
            }
        } else {
            System.debug('Error: ' + error.getMessage());
        }
    }
}