3

I have a [visualforce] page with a [standard controller] and a an [extension] that [queries] a child and grandchild of the standard controller. The grandchild records have a [duplicate] match rule. However, my visualforce form only updates existing records. Users do not create new records in it. By the time they get to my visualforce page to edit, they have already said "save and ignore" when they first created the record.

How can I make my visualforce page ignore the duplicate result match? Or, is there a way to create a "save" that shows an alert anyway? I am new to apex and this community. Explanations of your response will be highly appreciated.

I tried adding isallowsave(true) but that did not work

public PageReference saveAll() {
     update childlist;   
      List<Child__c> children = new 
    List<GrandChild__c>();
         for (Child__c c : childList) {
             grandchildlist.addAll(c.GrandChild__r);
           **isallowsave(true);**
         }
     update grandchildlist; 

    update SiteO;

     return controller.save();

}
6

You need to use the DmlOptions.DuplicateRuleHeader class. The isAllowSave method is used to determine if a rule allows saving or not (e.g. provide a warning or an error).

The following modification should suffice:

public PageReference saveAll() {
     update childlist;   
      List<Child__c> children = new 
    List<GrandChild__c>();
         for (Child__c c : childList) {
             grandchildlist.addAll(c.GrandChild__r);
         }
     Database.DmlOptions opts = new Database.DmlOptions();
     opts.DuplicateRuleHeader.allowSave = true;
     Database.update(grandchildlist, opts);
    update SiteO;

     return controller.save();

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.