• Priya 777
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 2
    Replies
I have a table where it creates PDF depends on number of values , i would like to generate this  in a way that i have to push the few of the values to next page and show it with Subtotal and Discounted Total estimated charges on one page when the values are like this .Do i have to use a specific format for this ?

<?xml version="1.0" encoding="UTF-8"?>
<template pageSize="LETTER" pageOrientation="portrait" pageMargins="40 60 40 50" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="fx-report-schema_1_0.xsd">
  <header>
    <table marginLeft="50" marginTop="20" border="false false false false" columnWidths="*">
    <tableBody>
        <row>
      <cell style="header-footer"  border="false false false false"><image width=
      </image></cell>
        </row>
        </tableBody></table>
  </header>

  <body>
    <table marginTop="30" columnWidths="110 150 * 90">
      <tableBody>
        <row>
            <cell fontSize="10" bold="true" border="false false false false">Customer:</cell>
            <cell fontSize="10" bold="false" border="false false false false">{{FX5__Job__r.FX5__CustomerAccount__r.Name}}</cell>
            <cell alignment="right" fontSize="10" bold="true" border="false false false false">Field Ticket No:</cell>
            <cell fontSize="10" bold="false" border="false false false false">{{Name}}</cell>
        </row>
        <row>
            <cell fontSize="10" bold="true" border="false false false false">Customer Field Rep:</cell>
            <cell fontSize="10" bold="false" border="false false false false">{{Customer_Printed_Name__c}}</cell>
            <cell alignment="right" fontSize="10" bold="true" border="false false false false">Service District:</cell>
            <cell fontSize="10" bold="false" border="false false false false">{{FX5__Job__r.FX5__Office__r.Short_Company_Name__c}}</cell>
        </row>
        <row>
            <cell fontSize="10" bold="true" border="false false false false">Well Name:</cell>
            <cell fontSize="10" bold="false" border="false false false false">{{FX5__Job__r.Well_Name_Report__c}}</cell>
            <cell alignment="right" fontSize="10" bold="true" border="false false false false">Service Line:</cell>
            <cell fontSize="10" bold="false" border="false false false false">{{FX5__Job__r.RecordType.Name}}</cell>
        </row>
        <row>
            <cell fontSize="10" bold="true" border="false false false false">Field:</cell>
            <cell fontSize="10" bold="false" border="false false false false">{{FX5__Job__r.Field__c}}</cell>
            <cell alignment="right" fontSize="10" bold="true" border="false false false false">Date:</cell>
            <cell fontSize="10" bold="false" border="false false false false">{{formatDate FX5__Ticket_Date__c format="MM/DD/YY"}}</cell>
        </row>
        <row>
            <cell fontSize="10" bold="true" border="false false false false">County, State:</cell>
            <cell fontSize="10" bold="false" border="false false false false">{{FX5__Job__r.County_Parish_State__c}}  {{FX5__Job__r.Well_Zip_Code__c}}</cell>
            <cell alignment="right" fontSize="10" bold="true" border="false false false false">Sales Representative:</cell>
            <cell fontSize="10" bold="false" border="false false false false">{{FX5__Job__r.Sales_Contact__r.Name}}</cell>
        </row>
        <row>
            <cell fontSize="10" bold="true" border="false false false false">API Number:</cell>
            <cell fontSize="10" bold="false" border="false false false false">{{FX5__Job__r.Well_API__c}}</cell>
            <cell alignment="right" fontSize="10" bold="true" border="false false false false">District Representative:</cell>
            <cell fontSize="10" bold="false" border="false false false false">{{FX5__Job__r.District_Representative__r.Name}}</cell>
        </row>
        <row>
            <cell fontSize="10" bold="true" border="false false false false">Job Type:</cell>
            <cell fontSize="10" bold="false" border="false false false false">{{FX5__Job__r.SAP_Job_Type__c}}</cell>
            <cell alignment="right" fontSize="10" bold="true" border="false false false false">C&amp;J Field Representative:</cell>
            <cell fontSize="10" bold="false" border="false false false false">{{C_J_Field_Representative_1a__r.FirstName}}  {{C_J_Field_Representative_1a__r.LastName}}</cell>
        </row>
        <row>
            <cell fontSize="10" bold="true" border="false false false false">CT Unit:</cell>
            <cell fontSize="10" bold="false" border="false false false false">{{Fleet_or_Unit__c}}</cell>
            <cell alignment="right" fontSize="10" bold="true" border="false false false false"></cell>
            <cell fontSize="10" bold="false" border="false false false false"></cell>
        </row>
      </tableBody>
    </table>
{{#filter FX5__Ticket_Items__r "Exclude_from_Customer_Reports__c" is=false}}
       {{#group items "Report_Category__c" desc=false sort="Report_Category_Order__c"}}   
       {{#if items.length}}
      
          <table marginTop="10" columnWidths="35 * 35 45 40 40 50 60">
            <tableBody>
            <row>
                <cell alignment="center" bold="true" fillColor="#D9D9D9" fontSize="10" colSpan="8">{{Report_Category__c}} Items</cell>
              <emptyCell></emptyCell>
              <emptyCell></emptyCell>
              <emptyCell></emptyCell>
              <emptyCell></emptyCell>
              <emptyCell></emptyCell>
              <emptyCell></emptyCell>
              <emptyCell></emptyCell>
            </row>
            <row >
              <cell bold="true" alignment="left" fillColor="#D9D9D9" fontSize="8">Item #</cell>
              <cell bold="true" alignment="center" fillColor="#D9D9D9" fontSize="8">Description</cell>
              <cell bold="true" alignment="center" fillColor="#D9D9D9" fontSize="8">Qty</cell>
              <cell bold="true" alignment="center" fillColor="#D9D9D9" fontSize="8">Price</cell>
              <cell bold="true" alignment="center" fillColor="#D9D9D9" fontSize="8">UOM</cell>
              <cell bold="true" alignment="center" fillColor="#D9D9D9" fontSize="8">Discount</cell>
              <cell bold="true" alignment="center" fillColor="#D9D9D9" fontSize="8">Gross</cell>
              <cell bold="true" alignment="center" fillColor="#D9D9D9" fontSize="8">Net</cell>
            </row>
        
            {{#each items}}    
              <row >
                <cell alignment="left" fontSize="8">{{FX5__Item_Code__c}}</cell>
                <cell alignment="left" fontSize="8">{{FX5__Description__c}}</cell>
                <cell alignment="center" fontSize="8">{{FX5__Input_Qty__c}}</cell>
                <cell alignment="right" fontSize="8">{{formatCurrency FX5__Price__c symbol="$" precision="2" separator="," decimal="."}}</cell>
                <cell alignment="center" fontSize="8">{{Catalog_Item_UOM__r.Name}}</cell>
                <cell alignment="center" fontSize="8">{{formatPercent FX5__Discount_Percent__c decimalPlaces=2}}</cell>
                <cell alignment="right" fontSize="8">{{formatCurrency Subtotal__c symbol="$" precision="2" separator="," decimal="."}}</cell>
                <cell alignment="right" fontSize="8">{{formatCurrency Extended_Amount__c symbol="$" precision="2" seperator="," decimal="." }}</cell>
              </row>
            {{/each}}
           
            <row >
              <cell fillColor="#D9D9D9" italics="true" color="black" bold="true" fontSize="9" colSpan="7" alignment="right">Subtotal:</cell>
              <emptyCell fillColor="#D9D9D9"></emptyCell>
              <emptyCell fillColor="#D9D9D9"></emptyCell>
              <emptyCell fillColor="#D9D9D9"></emptyCell>
              <emptyCell fillColor="#D9D9D9"></emptyCell>
              <emptyCell fillColor="#D9D9D9"></emptyCell>
              <emptyCell fillColor="#D9D9D9"></emptyCell>
              <cell fillColor="#D9D9D9" alignment="right" color="black" bold="true" fontSize="9">{{sum items "Extended_Amount__c" symbol="$" precision="2" seperator="," decimal="."}}</cell>
            </row>
            </tableBody>
        </table>
  {{/if}}
            {{/group}}
            {{/filter}}     
    <table columnWidths="* 60" marginTop="10">
      <tableBody>
        <row>
          <cell fillColor="#D9D9D9" fontSize="9" bold="true" alignment="right" italics="true">Discounted Total Estimated Charges</cell>
          <cell fillColor="#D9D9D9" fontSize="9" bold="true" alignment="right">${{sum FX5__Ticket_Items__r "Extended_Amount__c"}}</cell>
        </row>
          <row>
              <cell border="false false false false" colSpan="2" fontSize="7">This is a cost estimate only.  Actual charges are to based on equipment, chemicals, materials, and personnel required to complete the job. This does not include sales tax or well services tax that may be included at the time of invoicing.</cell>
              <emptyCell></emptyCell>
          </row>
      </tableBody>
    </table>



User-added image
Hi can anyone please help me with this test class .I was able to create content version but not content document link 

Apex class:

public class ContentVersionTriggerHelper {
    public static void linkContentVersion (List<contentversion> contentversionList) {
        try{
            //To store the taxonomy name
            Set <string>taxonomySet = new set <string>(); 
            //To store Taxonomy name and ID - Name is the Key
            map <string, string> taxonomyMap = new map <string,string>();
            list<contentversion> contentversionCaseList = new list<contentversion> ();
            for (contentversion objCV: contentversionList){
                system.debug('$$$objCV'+objCV.ContentDocumentId);
                // check if Taxonomy exists
                if(objCV.Taxonomy_Reference__c!=null && objCV.CurrentUserProfile__c  == 'Integration User'){ 
                    taxonomySet.add(objCV.Taxonomy_Reference__c);
                //check if case Id exist
                }else if(objCV.Case_Reference__c!=null && objCV.CurrentUserProfile__c == 'Integration User'){ 
                    contentversionCaseList.add(objCV);
                }
            }
            if(!taxonomySet.isEmpty()){
                for(Document_Type__c objDT : [select Id,name from Document_Type__c where name=:taxonomySet]){
                    taxonomyMap.put(objDT.name,objDT.Id);
                }
                //create case documents and link files
                insertCaseDocumentandLink(contentversionList,taxonomyMap); 
            }
            if(!contentversionCaseList.isEmpty()){ 
                // Directly link files to case
                insertContentDocumentLink(contentversionCaseList);
            }
        }catch (exception ex){
            system.debug('Exception occured in ContentVersionTriggerHelperClass' + ex.getLineNumber()  +ex.getMessage());         
            insert new Error_Framework__c(
                Error_Message__c=ex.getStackTraceString(), 
                Event_Category__c='Contentversion After Insert', 
                Description__c='Exception Occured in linkContentVersion Method', 
                User__c=UserInfo.getUserId(), 
                Object_Name__c='ContentDocumentLink/CaseDocument', 
                Source_Code_Location__c='ContentVersionTriggerHelper'
            );
        }
        return;
    }
   
   
    public static void insertCaseDocumentandLink(List<contentversion> contentversionList, map <string, string> taxonomyMap ) {
        system.debug('$$$insertCaseDocumentandLink'+contentversionList +' '+ taxonomyMap);
        //To store the  Case_Documents__c to be inserted
        list <Case_Documents__c> insertCaseDocumentList = new list <Case_Documents__c>();
        //To store the  ContentDocumentLink to be inserted
        list <ContentDocumentLink> insertContentDocumentLinkList = new list <ContentDocumentLink>();
            for (contentversion objCV: contentversionList){
                if(taxonomyMap.containskey(objCV.Taxonomy_Reference__c)){//checking if taxnomy exists
                    Case_Documents__c newDocument = new Case_Documents__c();
                    newDocument.Document_Status__c='Draft'; 
                    newDocument.Document_Type__c=taxonomyMap.get(objCV.Taxonomy_Reference__c);
                    newDocument.Effective_Date__c=system.today();
                    newDocument.Number_Of_Files__c=0;
                    newDocument.Case_Number__c = objCV.Case_Reference__c;
                    newDocument.Send_to_Oneview__c = false;
                    system.debug('$$$ContentDocumentId'+objCV.ContentDocumentId);
                    newDocument.Content_Document_Reference__c = objCV.ContentDocumentId;
                    insertCaseDocumentList.add(newDocument);
                }
                
            } 
            if(!insertCaseDocumentList.isEmpty()){
                insert insertCaseDocumentList;
                for (Case_Documents__c objCD: insertCaseDocumentList){
                    ContentDocumentLink caseDocLink = new ContentDocumentLink();
                    caseDocLink.LinkedEntityId = objCD.Id;
                    caseDocLink.contentDocumentId = objCD.Content_Document_Reference__c; 
                    //Viewer permission. The user can explicitly view but not edit the shared file.
                    caseDocLink.ShareType = 'V'; 
                    insertContentDocumentLinkList.add(caseDocLink);
                }
                if(!insertContentDocumentLinkList.isEmpty()){
                    insert insertContentDocumentLinkList;
                }
            }
            return;
    }
  //  This is not covered in Test class .
    public static void insertContentDocumentLink (List<contentversion> contentversionList){
        system.debug('$$$insertContentDocumentLink'+contentversionList);
        //To store the  ContentDocumentLink to be inserted
        list <ContentDocumentLink> insertContentDocumentLinkList = new list <ContentDocumentLink>();
        for (contentversion objCV: contentversionList){
                ContentDocumentLink caseDocLink = new ContentDocumentLink();
                caseDocLink.LinkedEntityId = objCV.Case_Reference__c;
                caseDocLink.contentDocumentId = objCV.ContentDocumentId; 
                //Viewer permission. The user can explicitly view but not edit the shared file.
                caseDocLink.ShareType = 'V'; 
                insertContentDocumentLinkList.add(caseDocLink);
        }
         if(!insertContentDocumentLinkList.isEmpty()){
                insert insertContentDocumentLinkList;
           }
        return;
    }
}
===========================================================================

Test class

@isTest
public class Test_ContentVersionInsertAction {
    /*************************************************************************************************************
* Apex Class Name     : ContentVersionInsertAction 
* Version             : 1.0 
* Created Date        : 12/02/2018
* Function            : Test class for ContentVersionInsertAction
* Modification Log    :
* Developer           :             Date                    Description
* ----------------------------------------------------------------------------                 
* Priyanka Indurthi            12/02/2018                   Original Version
************************************************************************************************************/
    
    static testmethod void testmethod1(){
        Test.startTest();
        Service_Mapping_Utility__c smu = new Service_Mapping_Utility__c(Case_Record_Type__c='Wires', 
                                                                        Case_Product_Name__c='Domestic Implementations',
                                                                        Case_Action__c='Drawdown Setup',
                                                                        Is_Auth__c=true,
                                                                        Hand_Off__c=true,
                                                                        Authentication_Required__c='High');
        insert smu;
        
        case newCase = new case(SelectProduct__c= smu.id,
                                Case_Type__c = 'Domestic Implementations',
                                Case_Received_Date__c = system.today());
        insert newCase;
        
        Document_Type__c docType = new Document_Type__c(LOB__c = 'Commercial Bank',
                                                        External_Id__c = 'Commercial BankEntityFinancial StatementsInterim Financial Statements',
                                                        Category__c = 'Entity');
        insert docType;
        
        
        profile pr = [select id from profile where name = 'Integration User'];
        user intgUser = new user(firstname = 'testFirstName',
                                 lastname = 'testLastName',
                                 profileid = pr.id,
                                 email = 'testuser@testclass.com',
                                 Username = 'testfirst.lastname@testclass.com',
                                 Alias = 'TfTl',
                                 CommunityNickname = 'test' ,
                                 TimeZoneSidKey = 'America/New_York', 
                                 LocaleSidKey = 'en_US', 
                                 EmailEncodingKey = 'UTF-8',
                                 LanguageLocaleKey = 'en_US'
                                );
        insert intgUser;
        system.runAs(intgUser){ 
            ContentVersion cv = new ContentVersion(
                Title = 'Test',
                PathOnClient = 'Test.jpg',
                VersionData = blob.valueof('Test Content Data'),
                IsMajorVersion = true,
                Case_Reference__c = newcase.id,
                Taxonomy_Reference__c = [select id,name from Document_Type__c where id =:docType.id][0].name
            );
            insert cv;
            
            ContentVersion contentVersionSelect = [SELECT Id, Title, ContentDocumentId FROM ContentVersion WHERE Id = :cv.Id LIMIT 1];
            List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];
            System.assertEquals(documents.size(), 1);
        }
       
         Test.stopTest();
    }   
}
​Hi For this trigger will it be possible it through following way .please let me know  

trigger ContactDuplicatePreventer on Contact (before insert, before update) {
    Map<String, Contact> ConMap = new Map<String, Contact>();
        for (Contact Contact : System.Trigger.new) {
      
               if ((Contact.Email != null) &&
                (System.Trigger.isInsert ||
                (Contact.Email !=
                    System.Trigger.oldMap.get(Contact.Id).Email))) {
       
   
            if (ConMap.containsKey(Contact.Email)) {
                Contact.Email.addError('Another Contact has the same email address.');
            } else {
                ConMap.put(Contact.Email, Contact);
            }
       }
    }
   
    for (Contact Contact : [SELECT Email FROM Contact
                      WHERE Email IN : ConMap.KeySet()]) {
        Contact newContact = ConMap.get(Contact.Email);
        newContact.Email.addError('A Contact with this E-mail address already exists.');
    }
}

Hi For this trigger will it be possible it through following way .please let me know  

Suppose i have alredy existing User contact with Email address xyz@gmail.com which is active 
If i try to create the 2 nd User with same email address xyz@gmail.com it will through error that email already exists because the first user  is active.

I want to make my trigger to work like if  xyz@gmail.com(1st user) is inactive for first user it should allow me to use the same email address for creating the second user with xyz@gmail.com.
trigger DCStargeting on Account (before insert,before update,after insert,after update) {
    Set<id> userIds = new Set<Id>();
    for (Account o : Trigger.new){
        userIds.add(o.OwnerId);
        if(o.Floorplan_Source2__c!=null&&o.Floorplan_Source2__c!=o.Current_Floor_Plan__c){
            o.Current_Floor_Plan__c=o.Floorplan_Source2__c;
        o.DCS_targeting_date__c= Date.today();
                      
        }
    }
}
Hi is their any documentation for Testing Salesforce with Ghostlab for Synchronization ,Please let me know i'm having issues with synchronization with browsers when i login to  salesfroce  with Ghostlab .Is there any way i can resolve it .
Hi I don't know why My Test Class coverage is less Please let me know where i'm goin worng new for developing .
Test Class:
trigger ContactDuplicatePreventer on Contact (before insert, before update) {
    Map<String, Contact> ConMap = new Map<String, Contact>();
        for (Contact Contact : System.Trigger.new) {
      
               if ((Contact.Email != null) &&
                (System.Trigger.isInsert ||
                (Contact.Email !=
                    System.Trigger.oldMap.get(Contact.Id).Email))) {
       
   
            if (ConMap.containsKey(Contact.Email)) {
                Contact.Email.addError('Another Contact has the same email address.');
            } else {
                ConMap.put(Contact.Email, Contact);
            }
       }
    }
   
    for (Contact Contact : [SELECT Email FROM Contact
                      WHERE Email IN : ConMap.KeySet()]) {
        Contact newContact = ConMap.get(Contact.Email);
        newContact.Email.addError('A Contact with this E-mail address already exists.');
    }
}
If Actual is Less than Target for Auction Vehicle Sold ,we have to  show 0$  in   Payout $ Potential** 

If Actual Is Greater than or equal to Target for Auction Vehicle Sold ,I have to show the Amount  for Payout $ Potential.**

(We have one more logic on it Auction Vehicle sold Maximum is $5,000)

The following is the logic ,

<apex:param value="{! IF(IF(NULLVALUE(PDPWrapList.Percent_of_Target__c,0) >= 100,(NULLVALUE(PDPWrapList.Eligible_RMS_Sold__c * auctionVehiclesIncentive,0)),0) > 5000,5000, IF(NULLVALUE(PDPWrapList.Percent_of_Target__c,0) >= 100,(NULLVALUE(PDPWrapList.Eligible_RMS_Sold__c * auctionVehiclesIncentive,0)),0) )}"/> 

Below hilighted Part is i'm working on 

User-added image
Below is the Trigger , trying to write Test class for it but i don't have any hands on Experience Can anyone help me with this 

public class NotifyRegionalSalesTeam_cls {
    
    public static void notifyRegionalSalesLeaderOnContactType(List<Independent_Dealer_Review__c> newDealerReviewList,Map<id,Independent_Dealer_Review__c> oldDealerReviewMap,user usr,boolean isInsert){
       List<Messaging.singleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
       Messaging.singleEmailMessage mail = new Messaging.singleEmailMessage();                                                         
       Map<id,List<Independent_Dealer_Review__c>> accToDealerReviewsMap = new Map<id,List<Independent_Dealer_Review__c>>();
       boolean firstRun = false;
       integer count = 0;
       integer mapSize = 0;
       EmailTemplate template = [select id,name from Emailtemplate where name = 'Ind. Dealer Contact Type as Phone vf'];

         for(Independent_Dealer_Review__c temp:newDealerReviewList){
             if(temp.Ind_Dealer_Contact_Type__c == 'Phone' && isInsert){
              if(accToDealerReviewsMap.containsKey(temp.Account__c)){
                  accToDealerReviewsMap.get(temp.Account__c).add(temp);
              }else{
                  accToDealerReviewsMap.put(temp.Account__c,new List<Independent_Dealer_Review__c> {temp});
                } 
                 mapSize++;
             }
             if(!isInsert){
                 count ++;
                 if((temp.Ind_Dealer_Contact_Type__c == 'Phone' && count == 1 && oldDealerReviewMap.get(temp.id).Ind_Dealer_Contact_Type__c != 'Phone') || (temp.Ind_Dealer_Contact_Type__c == 'Phone' && count == 2)){
              if(accToDealerReviewsMap.containsKey(temp.Account__c)){
                  accToDealerReviewsMap.get(temp.Account__c).add(temp);
              }else{
                  accToDealerReviewsMap.put(temp.Account__c,new List<Independent_Dealer_Review__c> {temp});
                } 
                 mapSize++;
              }
             }
             system.debug('***accToDealerReviewsMap**' +accToDealerReviewsMap);
            if(mapSize == 2 && firstRun == false){
                firstRun = true;
               list<string> toAddresses = new List<string>();
                if(temp.Regional_Sales_Leader__c != null){
                    toAddresses.add(temp.Regional_Manger_Email__c);
                }
                
           if(toAddresses.size() > 0){
               mail.settargetObjectid(usr.id);
               mail.setTreatTargetObjectAsRecipient(false);
               mail.setwhatid(temp.id);
               mail.settoAddresses(toAddresses);
               mail.setsaveAsActivity(false);
               mail.settemplateId(template.id);
               mails.add(mail);  
             }               
           }
         }   
        
        if(mails.size() > 0){
           system.debug('sending Email');
            messaging.sendEmail(mails);           
        }
      }
    
    public static void notifyRegionalSalesManageronRSLCheck(List<Independent_Dealer_Review__c> newDealerReviewList,Map<id,Independent_Dealer_Review__c> oldDealerReviewMap,user usr,boolean isInsert){
       List<Messaging.singleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
       Messaging.singleEmailMessage mail = new Messaging.singleEmailMessage();                                                         
       Map<id,List<Independent_Dealer_Review__c>> accToDealerReviewsMap = new Map<id,List<Independent_Dealer_Review__c>>();
       boolean firstRun = false;
       integer count = 0;
       integer mapSize = 0;
       EmailTemplate template = [select id,name from Emailtemplate where name = 'Independent Dealer Review RSL Checked vf'];

         for(Independent_Dealer_Review__c temp:newDealerReviewList){
             if(temp.Escalate_to_RSD__c   == TRUE && isInsert){
              if(accToDealerReviewsMap.containsKey(temp.Account__c)){
                  accToDealerReviewsMap.get(temp.Account__c).add(temp);
              }else{
                  accToDealerReviewsMap.put(temp.Account__c,new List<Independent_Dealer_Review__c> {temp});
                } 
                 mapSize++;
             }
             if(!isInsert){
                 count ++;
                 if((temp.Escalate_to_RSD__c== TRUE && count == 1 && oldDealerReviewMap.get(temp.id).Escalate_to_RSD__c   != TRUE) || (temp.Escalate_to_RSD__c == TRUE && count == 2)){
              if(accToDealerReviewsMap.containsKey(temp.Account__c)){
                  accToDealerReviewsMap.get(temp.Account__c).add(temp);
              }else{
                  accToDealerReviewsMap.put(temp.Account__c,new List<Independent_Dealer_Review__c> {temp});
                } 
                 mapSize++;
              }
             }
             system.debug('***accToDealerReviewsMap**' +accToDealerReviewsMap);
            if(mapSize == 2 && firstRun == false){
                firstRun = true;
               list<string> toAddresses = new List<string>();
                if(temp.Regional_Sales_Leader__c != null){
                    toAddresses.add(temp.Regional_Manger_Email__c);
                }
                
           if(toAddresses.size() > 0){
               mail.settargetObjectid(usr.id);
               mail.setTreatTargetObjectAsRecipient(false);
               mail.setwhatid(temp.id);
               mail.settoAddresses(toAddresses);
               mail.setsaveAsActivity(false);
               mail.settemplateId(template.id);
               mails.add(mail);  
             }               
           }
         }   
        
        if(mails.size() > 0){
           system.debug('sending Email');
            messaging.sendEmail(mails);           
        }
      }

}
​Hi For this trigger will it be possible it through following way .please let me know  

trigger ContactDuplicatePreventer on Contact (before insert, before update) {
    Map<String, Contact> ConMap = new Map<String, Contact>();
        for (Contact Contact : System.Trigger.new) {
      
               if ((Contact.Email != null) &&
                (System.Trigger.isInsert ||
                (Contact.Email !=
                    System.Trigger.oldMap.get(Contact.Id).Email))) {
       
   
            if (ConMap.containsKey(Contact.Email)) {
                Contact.Email.addError('Another Contact has the same email address.');
            } else {
                ConMap.put(Contact.Email, Contact);
            }
       }
    }
   
    for (Contact Contact : [SELECT Email FROM Contact
                      WHERE Email IN : ConMap.KeySet()]) {
        Contact newContact = ConMap.get(Contact.Email);
        newContact.Email.addError('A Contact with this E-mail address already exists.');
    }
}

Hi For this trigger will it be possible it through following way .please let me know  

Suppose i have alredy existing User contact with Email address xyz@gmail.com which is active 
If i try to create the 2 nd User with same email address xyz@gmail.com it will through error that email already exists because the first user  is active.

I want to make my trigger to work like if  xyz@gmail.com(1st user) is inactive for first user it should allow me to use the same email address for creating the second user with xyz@gmail.com.
How to write trigger to avoid duplicate email when bulkfying the trigger

my trigger is:

trigger AvoidDuplicate on contact (before insert,before update)
{
   if(Trigger.isInsert||Trigger.isUpdate)
      for(contact a:trigger.new)
     {
         integer count=[select count from contact where email=:a.email];
         if(count>0)
          {
                 a.Email.adderror('This email already exists');
          }
     }
}

this is working fine when inserting single records

but it shows error when working with dataloader...... Please help to to over come this error


I would appriciate for any kind of replay...............