• ArunKumar Kumkumath
  • NEWBIE
  • 20 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 11
    Replies
HI,
I am using a simple trigger in my application to fetch duplicate accounts based on the account name, city and street.
This trigger is working perfect while a new account is saved. If there is a match it is alerting the user and if no duplicates found, it is saved in SF.

But for edit account, it is working correct when there is a duplicate is present. If there is no duplicate account present in SF it is alerting an incorrect message followed with an error message to the user.
  • You cannot create a duplicate account here as the Name 'Test Acc1' and Phone '(000) 000-0000' already belongs to a different account.
  • The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 301j0000000bv9s. Flow error messages: <b>An unhandled fault has occurred in this flow</b><br>An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information. Contact your administrator for help
Could you please help me out on this..?
Below is the trigger code...

trigger AccountDuplicateTrigger on Account (before insert, before update)
{        
    for(Account a:Trigger.new)    
    {
        if(Trigger.isBefore)
        {       
            string dupItem = '';
             List<Account> acc= new List<Account>();      
            if(Trigger.isInsert)
            {                   
                if(a.Name !='')
                {                                                              
                       if((a.BillingStreet != null) && (acc.isEmpty()))
                       {
                            acc=[select ID from account where Name=:a.Name and BillingStreet=:a.BillingStreet];
                            if(acc.isEmpty()==False)                                                              
                                  dupItem='Name \''+ String.escapeSingleQuotes(a.Name)+'\' and Billing street \''+
                                  String.escapeSingleQuotes(a.BillingStreet)+'\'';
                      }
                      if((a.BillingCity != null) && (acc.isEmpty()))
                      {
                            acc=[select ID from account where Name=:a.Name and BillingCity=:a.BillingCity];    
                            if(acc.isEmpty()==False)
                                dupItem='Name \''+ String.escapeSingleQuotes(a.Name)+'\' and Billing city \''+
                                String.escapeSingleQuotes(a.BillingCity)+'\'';
                      }
                      //Alerts the user if any matching record present in the system and can't allows to save it.                       
                      if(acc.isEmpty()==False) {
                           if(!test.isRunningTest())
                           {
                                a.adderror('You cannot create a duplicate account here as the '+dupItem+' already belongs to a different account.');     
                           }
                     }   
             }
      } 
      else if(Trigger.isUpdate)
      {
            if(a.Name !='')
                {                                                                
                       if((a.BillingStreet != null) && (acc.isEmpty()))
                       {
                            acc=[select ID from account where Name=:a.Name and BillingStreet=:a.BillingStreet];
                            if(acc.isEmpty()==False)                                                              
                                  dupItem='Name \''+ String.escapeSingleQuotes(a.Name)+'\' and Billing street \''+
                                  String.escapeSingleQuotes(a.BillingStreet)+'\'';
                      }
                      if((a.BillingCity != null) && (acc.isEmpty()))
                      {
                            acc=[select ID from account where Name=:a.Name and BillingCity=:a.BillingCity];    
                            if(acc.isEmpty()==False)
                                dupItem='Name \''+ String.escapeSingleQuotes(a.Name)+'\' and Billing city \''+
                                String.escapeSingleQuotes(a.BillingCity)+'\'';
                      }
                      //Alerts the user if any matching record present in the system and can't allows to save it.                       
                      if(acc.isEmpty()==False) {
                           if(!test.isRunningTest())
                           {
                                a.adderror('You cannot create a duplicate account here as the '+dupItem+' already belongs to a different account.');     
                           }
                     }   
             }
      } 
}
}
}
Can you please help me out on this..? I am trying to write a test class for a simple trigger. But some of the lines (italics) are not covered under the code coverage. Can anyone please guide me... Also i have not written any test classes for this trigger but it is showing coverage without a test class..?

trigger AccountDuplicateTrigger on Account (before insert)
{        
    for(Account a:Trigger.new)    
    {
        if(Trigger.isInsert)
        {                   
            if(a.Name !='') 
            {       
                string dupItem = '';
                List<Account> acc= new List<Account>();                   
                if((a.BillingStreet != null) && (acc.isEmpty())) 
                {
                    acc=[select ID from account where Name=:a.Name and BillingStreet=:a.BillingStreet]; 
                    if(acc.isEmpty()==False)                                                              
                        dupItem='Name \''+ String.escapeSingleQuotes(a.Name)+'\' and Billing street \''+
                        String.escapeSingleQuotes(a.BillingStreet)+'\'';

                }
                if((a.BillingCity != null) && (acc.isEmpty())) 
                {
                    acc=[select ID from account where Name=:a.Name and BillingCity=:a.BillingCity];    
                    if(acc.isEmpty()==False) 
                        dupItem='Name \''+ String.escapeSingleQuotes(a.Name)+'\' and Billing city \''+
                        String.escapeSingleQuotes(a.BillingCity)+'\'';

                }                                      
                else{                
                }
                
                //Alerts the user                    
                if(acc.isEmpty()==False) {
                    a.adderror('You cannot create a duplicate account here as the '+dupItem+' already belongs to a different account.');     
                }

            }
        }
    }
}
Hi all,

Is it possible to customize the Lead Find Duplicates functionality ?

I have a new requirement from my client to add a custom page block and show some results from a REST API on the same landing page. I didn't see any salesforce out of the box feature for this.

As i am a beginner to this technology... please any one suggest some ideas to customize this...

Thanks in advance.
ArunKumar K
HI,
I am using a simple trigger in my application to fetch duplicate accounts based on the account name, city and street.
This trigger is working perfect while a new account is saved. If there is a match it is alerting the user and if no duplicates found, it is saved in SF.

But for edit account, it is working correct when there is a duplicate is present. If there is no duplicate account present in SF it is alerting an incorrect message followed with an error message to the user.
  • You cannot create a duplicate account here as the Name 'Test Acc1' and Phone '(000) 000-0000' already belongs to a different account.
  • The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 301j0000000bv9s. Flow error messages: <b>An unhandled fault has occurred in this flow</b><br>An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information. Contact your administrator for help
Could you please help me out on this..?
Below is the trigger code...

trigger AccountDuplicateTrigger on Account (before insert, before update)
{        
    for(Account a:Trigger.new)    
    {
        if(Trigger.isBefore)
        {       
            string dupItem = '';
             List<Account> acc= new List<Account>();      
            if(Trigger.isInsert)
            {                   
                if(a.Name !='')
                {                                                              
                       if((a.BillingStreet != null) && (acc.isEmpty()))
                       {
                            acc=[select ID from account where Name=:a.Name and BillingStreet=:a.BillingStreet];
                            if(acc.isEmpty()==False)                                                              
                                  dupItem='Name \''+ String.escapeSingleQuotes(a.Name)+'\' and Billing street \''+
                                  String.escapeSingleQuotes(a.BillingStreet)+'\'';
                      }
                      if((a.BillingCity != null) && (acc.isEmpty()))
                      {
                            acc=[select ID from account where Name=:a.Name and BillingCity=:a.BillingCity];    
                            if(acc.isEmpty()==False)
                                dupItem='Name \''+ String.escapeSingleQuotes(a.Name)+'\' and Billing city \''+
                                String.escapeSingleQuotes(a.BillingCity)+'\'';
                      }
                      //Alerts the user if any matching record present in the system and can't allows to save it.                       
                      if(acc.isEmpty()==False) {
                           if(!test.isRunningTest())
                           {
                                a.adderror('You cannot create a duplicate account here as the '+dupItem+' already belongs to a different account.');     
                           }
                     }   
             }
      } 
      else if(Trigger.isUpdate)
      {
            if(a.Name !='')
                {                                                                
                       if((a.BillingStreet != null) && (acc.isEmpty()))
                       {
                            acc=[select ID from account where Name=:a.Name and BillingStreet=:a.BillingStreet];
                            if(acc.isEmpty()==False)                                                              
                                  dupItem='Name \''+ String.escapeSingleQuotes(a.Name)+'\' and Billing street \''+
                                  String.escapeSingleQuotes(a.BillingStreet)+'\'';
                      }
                      if((a.BillingCity != null) && (acc.isEmpty()))
                      {
                            acc=[select ID from account where Name=:a.Name and BillingCity=:a.BillingCity];    
                            if(acc.isEmpty()==False)
                                dupItem='Name \''+ String.escapeSingleQuotes(a.Name)+'\' and Billing city \''+
                                String.escapeSingleQuotes(a.BillingCity)+'\'';
                      }
                      //Alerts the user if any matching record present in the system and can't allows to save it.                       
                      if(acc.isEmpty()==False) {
                           if(!test.isRunningTest())
                           {
                                a.adderror('You cannot create a duplicate account here as the '+dupItem+' already belongs to a different account.');     
                           }
                     }   
             }
      } 
}
}
}
Can you please help me out on this..? I am trying to write a test class for a simple trigger. But some of the lines (italics) are not covered under the code coverage. Can anyone please guide me... Also i have not written any test classes for this trigger but it is showing coverage without a test class..?

trigger AccountDuplicateTrigger on Account (before insert)
{        
    for(Account a:Trigger.new)    
    {
        if(Trigger.isInsert)
        {                   
            if(a.Name !='') 
            {       
                string dupItem = '';
                List<Account> acc= new List<Account>();                   
                if((a.BillingStreet != null) && (acc.isEmpty())) 
                {
                    acc=[select ID from account where Name=:a.Name and BillingStreet=:a.BillingStreet]; 
                    if(acc.isEmpty()==False)                                                              
                        dupItem='Name \''+ String.escapeSingleQuotes(a.Name)+'\' and Billing street \''+
                        String.escapeSingleQuotes(a.BillingStreet)+'\'';

                }
                if((a.BillingCity != null) && (acc.isEmpty())) 
                {
                    acc=[select ID from account where Name=:a.Name and BillingCity=:a.BillingCity];    
                    if(acc.isEmpty()==False) 
                        dupItem='Name \''+ String.escapeSingleQuotes(a.Name)+'\' and Billing city \''+
                        String.escapeSingleQuotes(a.BillingCity)+'\'';

                }                                      
                else{                
                }
                
                //Alerts the user                    
                if(acc.isEmpty()==False) {
                    a.adderror('You cannot create a duplicate account here as the '+dupItem+' already belongs to a different account.');     
                }

            }
        }
    }
}
Hi all,

Is it possible to customize the Lead Find Duplicates functionality ?

I have a new requirement from my client to add a custom page block and show some results from a REST API on the same landing page. I didn't see any salesforce out of the box feature for this.

As i am a beginner to this technology... please any one suggest some ideas to customize this...

Thanks in advance.
ArunKumar K
1.plz answer best pratice of TESTCLASSES
2.plz answer best pratice of TRIGGERS
3. APEX CLASS
There's a search box on the top of Salesforce, is it possible to override(re-implement) it? Like catcing the click event, poping up dialog, customize the search result page...

I went over the Visualforce development guide, it seems I can't do this by Virsualforce. Any suggestion?

Thanks in advance.

Charley

Find Duplicates button on Leads will find duplicates on which criteria?