• Sanskar Vaidya 8
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
I need to edit the Account Details of a particular account record. I'm showing the account details on one VF page and along with it a command button that say 'Edit'. On click of edit i need to be directed to a new Custom Edit vf page where I can edit the Account Records of the particular account i selected on the previous page. If anyone can guide me with the code it would be a great help.
I've completed the first part where I need to show the account details of the account selected. But i'm unable to open a new custom page with the EDIT options. How do I pass the ID and do the rest stuff please elaborate..
ABC containers require the ability to automatically associate a contact created in their salesforce instance with the respective account based on the email domain specified in the primary email address of the contact. The association should happen real time as soon as a record is created in a system.
TODO:
1. Develop necessary test code to attain maximum code coverage (90% minimum with 4 test cases)

Here, we already have a field named website in Account and Email in contact. We need to make sure that we have to compare domains of the two and then map accordingly as far as i've understood the question. Please explain me with the code as I'm a complete beginner in triggers and salesforce. Below is my tentative code which might be completely wrong too, it's a try from my side.

```
trigger AssociateContact on Contact (before insert) {
    List<String> Emaildomain = new List<String>();
    for (Contact con : trigger.new){
        String[] str = con.Email.Split('@');
        Emaildomain.add('%'+str[1]);
    }
    
    List<Account> accounts = [Select Id, Website From Account Where Website LIKE :Emaildomain];
    Map <String, Id> domain = new Map<String, Id>();
    
    for (Account acc : accounts){    
        for (String dom : acc.Website.Split('.'))
            domain.put(dom, acc.Id);
    }
    for (Contact con : trigger.new){
        if (domain.get(con.Email) !=  null){
            con.AccountId = domain.get(con.Email);
        }
    }
}
```
 
Can anyone provide Test class for following scenario.Consider all positive negative Bulk testing for the given batch class.

Use Case ::
Removal of duplicate Leads
1. During the Campaigning, It might happen that representative creates duplicate leads in an org.
2. So admin want to build a process which will run every 3 hours/day & remove the duplicate leads from the org.
3. The criteria to find the duplicate records should be configurable. Ex. If there are two leads in a system with same Email address then keep the first lead entry & remove all the other leads. So the field like Email, Name which will be deciding the uniqueness should be configurable.


--------------------------------------------------BATCH class----------------------------------------------
global class RemoveDuplicateLeads implements Database.Batchable<sObject>, Database.Stateful {
/**
Map will Keep count of Lead which are having same field
*/
Map<String,Integer> countMap = new Map<String,Integer>();
/**
Constructor to initialize the countMap. Which will be useful for every batch operation.
*/
global RemoveDuplicateLeads() {
Database.QueryLocatorIterator iterator =
Database.getQueryLocator('select ' + System.Label.Lead_Field + ' from Lead').iterator();
while (iterator.hasNext())
{
Lead leadRecord = (Lead) iterator.next();
if(leadRecord.get(System.Label.Lead_Field) != null) {
countMap.put((String)leadRecord.get(System.Label.Lead_Field), 0);
}
}
}

/**
This method will start the batch execution.
@return Database.QueryLocator - This will contain all Leads.
*/
global Database.QueryLocator start(Database.BatchableContext BC) {
return Database.getQueryLocator('select ' + System.Label.Lead_Field + ' from lead');
}

/**
This method will execute for every batch and deletes the duplicate leads.
@return Nothing.
*/
global void execute(Database.BatchableContext BC, List<sObject> scope) {
List<Lead> leadList = new List<Lead>();
for(SObject lead : scope) {
if(lead.get(System.Label.Lead_Field) != null) {
if(countMap.get((String)lead.get(System.Label.Lead_Field)) >= 1 ) {
leadList.add((Lead)lead);
} else {
countMap.put((String)lead.get(System.Label.Lead_Field),1);
}
}
}
Database.delete(leadList,false);
}
/**
This method will execute at end of Batch apex process.
@return Nothing.
*/
global void finish(Database.BatchableContext BC) {
}
}
  • August 20, 2018
  • Like
  • 0