• Aravind Y B 1
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 1
    Replies
Hi,i am new to salesforce, ineed to add above mention 'Other nan sales' Profile to the Profile.name section in this existing validation please help me with this one.

Validation Rule:

TEXT(Document_Type__c) == 'Product UW Grid' 

&& 

IF( $CustomMetadata.Switch_Setting__mdt.UW_Profile.Enable__c = TRUE , $Profile.Name  <>  'UW/Actuary',  NOT($Permission.Underwriting_Actuary) )
i didnt understand this scenario ,Can any one know how to create this by using flow and how to send chatter to this users SSAM Implementation Specialist or Account Manager ?

project is a Object & Create IP is field

Create a new chatter when: 
Create IP(field)  = 'True'
Chatter the SSAM Implementation Specialist or Account Manager
 @ Person
'The TIC has completed the creation of the IP Package for (Project Name)'
Link to Project
i didnt understand this scenario ,Can any one know how to create this ?

project is a Object & Create IP is field

Create a new chatter when: 
Create IP(field)  = 'True'
Chatter the SSAM Implementation Specialist or Account Manager
 @ Person
'The TIC has completed the creation of the IP Package for (Project Name)'
Link to Project
When ever i am trying to run this flow invocable by Apex  i am getting above error.

public class FindDuplicate {
    @InvocableMethod
    public static List<flowOutputs> FindDuplicate (List<flowInputs> flowinput){
        List<flowOutputs> output = new List<flowOutputs>();
        String ValidationType;    //    either Account/Contact
        Contact Contacttoadd;
        Account Accounttoadd;
        Boolean DuplicateChecked;
        for (flowInputs input : flowinput){
            ValidationType = input.ValidationType;
            Contacttoadd = input.AddContact;
            Accounttoadd = input.AddAccount;
            DuplicateChecked = input.DuplicateCheck;
        }
        system.debug('Accounttoadd'+Accounttoadd);
        if (ValidationType == 'Account' && DuplicateChecked == false){
            output.add(AccountValidation (Accounttoadd));
        }
        if (ValidationType == 'Account' && DuplicateChecked == true){
            output.add(InsertDuplicateAccount (Accounttoadd));
        }
        if (ValidationType == 'Contact' && DuplicateChecked == false){
            output.add(ContactValidation (Contacttoadd));
        }
        if (ValidationType == 'Contact' && DuplicateChecked == true){
            output.add(InsertDuplicateContact (Contacttoadd));
        }
        return output;
        //return null;
    }
    
    private static flowOutputs ContactValidation (Contact contactRecord){  
        Boolean duplicateRulesFound = true;
        system.debug('contactRecord'+contactRecord);
        flowOutputs output = new flowOutputs();
        Contact con1 = new Contact(FirstName = 'Already', LastName = 'Exists', Email = 'already@exists.com');
        List<Contact> conList = new List<Contact>{con1};
        
        List<Datacloud.FindDuplicatesResult> results;
        conList.add(contactRecord); 
        try {
            results = Datacloud.FindDuplicates.findDuplicates(conList);
        }catch(System.NullPointerException e) {
            output.isValid = true;
            output.errorType = null;
            output.errormsg = null;
            output.Id = null;
        }
        
        for (Integer i = 0; i < conList.size(); i++) {
            // Find the first duplicate result with a match result, then use the first match record.
            for (Datacloud.DuplicateResult dr : results[i].getDuplicateResults()) {
                system.debug(dr);
                if (dr.matchResults.size() > 0 && dr.getMatchResults()[0].matchRecords.size() > 0) {
                    //system.debug(dr);
                    system.debug(dr.getMatchResults()[0].matchRecords);
                    Datacloud.MatchRecord mt = dr.getMatchResults()[0].matchRecords[0];
                    string Id = mt.getRecord().Id;
                    system.debug('Id'+Id);
                    output.isValid = false;
                    output.errorType = dr.getDuplicateRule();
                    output.errormsg = dr.getErrorMessage();
                    output.Id = null;
                    break;
                }else{
                    output.isValid = true;
                    output.errormsg = null;
                    output.errorType = null;
                    output.Id = null;
                }
            }
            
        }
        system.debug('output'+output);
        return output;
    }
    
    private static flowOutputs InsertDuplicateContact (contact c){
        // If the duplicate rule is an alert rule, we can try to bypass it
        flowOutputs output = new flowOutputs();
        Database.DMLOptions dml = new Database.DMLOptions(); 
        dml.DuplicateRuleHeader.AllowSave = true;
        Database.SaveResult sr2 = Database.insert(c, dml);
        if (sr2.isSuccess()) {
            System.debug('Duplicate Contact has been inserted in Salesforce!');
            output.isValid = true;
            output.Id = sr2.id;
            output.errormsg = null;
            output.errorType = null;
        }else{
            output.isValid = false;
            output.Id = null;
            output.errormsg = string.join(sr2.errors,',');
            output.errorType = null;
        }
        return output;
    }
    
    
    private static flowOutputs InsertDuplicateAccount (Account a){
        // If the duplicate rule is an alert rule, we can try to bypass it
        flowOutputs output = new flowOutputs();
        Database.DMLOptions dml = new Database.DMLOptions(); 
        dml.DuplicateRuleHeader.AllowSave = true;
        Database.SaveResult sr2 = Database.insert(a, dml);
        if (sr2.isSuccess()) {
            System.debug('Duplicate account has been inserted in Salesforce!');
            output.isValid = true;
            output.Id = sr2.id;
            output.errormsg = null;
            output.errorType = null;
        }else{
            output.isValid = false;
            output.Id = null;
            output.errormsg = string.join(sr2.errors,',');
            output.errorType = null;
        }
        return output;
    }
    
    private static flowOutputs AccountValidation (Account accountRecord){
        system.debug('accountRecord'+accountRecord);
        flowOutputs output = new flowOutputs();
        List<Account> acctList = new List<Account>();
        List<Datacloud.FindDuplicatesResult> results;
        accountRecord.Situs_State__c = String.valueOf(accountRecord.Situs_State__c);
        accountRecord.Group_Status__c = String.valueOf(accountRecord.Group_Status__c);
        accountRecord.Group_Type__c = String.valueOf(accountRecord.Group_Type__c);
        accountRecord.BillingCountry = String.valueOf(accountRecord.BillingCountry);
        accountRecord.BillingState = String.valueOf(accountRecord.BillingState);
        acctList.add(accountRecord); 
                     system.debug('accountRecord'+acctList);
        try {
            results = Datacloud.FindDuplicates.findDuplicates(acctList);
             system.debug('accountRecord'+results);
        }catch (System.NullPointerException e){
            output.isValid = true;
            output.errorType = null ;
            output.errormsg = null;
            output.Id = null;
             system.debug('accountRecord'+output);

        }
        for (Integer i = 0; i < acctList.size(); i++) {
            // Find the first duplicate result with a match result, then use the first match record.
            for (Datacloud.DuplicateResult dr : results[i].getDuplicateResults()) {
                system.debug(dr);
                if (dr.matchResults.size() > 0 && dr.getMatchResults()[0].matchRecords.size() > 0) {
                    system.debug(dr.getMatchResults()[0].matchRecords);
                    Datacloud.MatchRecord mt = dr.getMatchResults()[0].matchRecords[0];
                    system.debug('output'+mt);
                    string Id = mt.getRecord().Id;
                    system.debug('Id'+Id);
                    output.isValid = true;
                    output.errorType = dr.getDuplicateRule();
                    output.errormsg = dr.getErrorMessage();
                    output.Id = null;
                    system.debug('output'+output);
                    break;
                }else{
                    output.isValid = true;
                    output.errormsg = null;
                    output.errorType = null;
                    output.Id = null;
                    system.debug('output'+output);
                }
            }
            
        }
        
        system.debug('output'+output);
        return output;
    }
    
    public class flowInputs {
        @InvocableVariable(label='Either Account or Contact' required = true)
        public String ValidationType;
        
        @InvocableVariable
        public Contact AddContact;
        
        @InvocableVariable
        public Account AddAccount;
        
        @InvocableVariable
        public Boolean DuplicateCheck;   
    }
    
    public class flowOutputs{
        
        @InvocableVariable
        public Boolean isValid;
        
        @InvocableVariable
        public String errorType;
        
        @InvocableVariable
        public String errormsg;
        
        @InvocableVariable
        public String Id;
    }
}
Hi,i am new to salesforce, ineed to add above mention 'Other nan sales' Profile to the Profile.name section in this existing validation please help me with this one.

Validation Rule:

TEXT(Document_Type__c) == 'Product UW Grid' 

&& 

IF( $CustomMetadata.Switch_Setting__mdt.UW_Profile.Enable__c = TRUE , $Profile.Name  <>  'UW/Actuary',  NOT($Permission.Underwriting_Actuary) )