Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Deduplicate Rules from existing matching rules #274

Open
mabella-dqe opened this issue Aug 27, 2021 · 0 comments
Open

Create Deduplicate Rules from existing matching rules #274

mabella-dqe opened this issue Aug 27, 2021 · 0 comments

Comments

@mabella-dqe
Copy link

Hello, I am trying to Create a Duplicate Rule from the metadataService :

DuplicateRule :

public class DuplicateRule extends Metadata {
        public String type = 'DuplicateRule';
        public String actionOnInsert;
        public String actionOnUpdate;
        public String alertText;
        public String description;
        public MetadataService.DuplicateRuleFilter duplicateRuleFilter;
        public MetadataService.DuplicateRuleMatchRule[] duplicateRuleMatchRules;
        public Boolean isActive;
        public String masterLabel;
        public String[] operationsOnInsert;
        public String[] operationsOnUpdate;
        public String securityOption;
        public Integer sortOrder;
        private String[] actionOnInsert_type_info = new String[]{'actionOnInsert',SOAP_M_URI,null,'1','1','false'};
        private String[] actionOnUpdate_type_info = new String[]{'actionOnUpdate',SOAP_M_URI,null,'1','1','false'};
        private String[] alertText_type_info = new String[]{'alertText',SOAP_M_URI,null,'1','1','true'};
        private String[] description_type_info = new String[]{'description',SOAP_M_URI,null,'1','1','true'};
        private String[] duplicateRuleFilter_type_info = new String[]{'duplicateRuleFilter',SOAP_M_URI,null,'1','1','true'};
        private String[] duplicateRuleMatchRules_type_info = new String[]{'duplicateRuleMatchRules',SOAP_M_URI,null,'0','-1','true'};
        private String[] isActive_type_info = new String[]{'isActive',SOAP_M_URI,null,'1','1','false'};
        private String[] masterLabel_type_info = new String[]{'masterLabel',SOAP_M_URI,null,'1','1','false'};
        private String[] operationsOnInsert_type_info = new String[]{'operationsOnInsert',SOAP_M_URI,null,'0','-1','false'};
        private String[] operationsOnUpdate_type_info = new String[]{'operationsOnUpdate',SOAP_M_URI,null,'0','-1','false'};
        private String[] securityOption_type_info = new String[]{'securityOption',SOAP_M_URI,null,'1','1','false'};
        private String[] sortOrder_type_info = new String[]{'sortOrder',SOAP_M_URI,null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{SOAP_M_URI,'true','false'};
        private String[] type_att_info = new String[]{'xsi:type'};
        private String[] field_order_type_info = new String[]{'actionOnInsert','actionOnUpdate','alertText','description','duplicateRuleFilter','duplicateRuleMatchRules','isActive','masterLabel','operationsOnInsert','operationsOnUpdate','securityOption','sortOrder'};
}

Creation of the MetaService :

MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.timeout_x = 60000;
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();

MetadataService.DuplicateRuleMatchRule dupMatchingRules = new MetadataService.DuplicateRuleMatchRule();
dupMatchingRules.matchRuleSObjectType = 'Lead';
dupMatchingRules.matchingRule = 'My_mathing_rule_name';

MetadataService.DuplicateRule dupRules = new MetadataService.DuplicateRule();
dupRules.actionOnInsert = 'Allow';
dupRules.actionOnUpdate = 'Allow';
dupRules.duplicateRuleMatchRules = new List<MetadataService.DuplicateRuleMatchRule>{dupMatchingRules};
dupRules.isActive = true;
dupRules.masterLabel = 'Lead duplicate rule';
dupRules.securityOption = 'EnforceSharingRules';
dupRules.sortOrder = 2;

List<MetadataService.Metadata> meta = new List<MetadataService.Metadata>{dupRules};

MetadataService.SaveResult results = service.createMetadata(meta)[0];

When I launch this code, in 'results' there is no error, but the 'results .success' is at false.
I don't know where the probleme is.

I hope that someone can help me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant