• DavidRobinson4
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
Hello

We have a customer who has a need for a cloud based CMS system, to compliment force.com pages serverd from salesforce. The customer does not want to build the entire website on force.com, only specific components/pages, to have served as embedded pages on the website/CMS.

So far, I have found a few options, and for one reason of another, may not be the best fit.

Wordpress - To many security vunerabilities. Upgrade process manual. Has to be served on dedicated server. 
Magento - Paying for to many used features for eCommerce. Site is not eCommerce.
Joomla - Upgrade process manual. Has to be served on dedicated server.

Can anyone recommend a CMS product (paid or open source) which they would consider for a website build for a SME (Small-Medium Enterprise business website with medium traffic)

Regards

Dave

Hello

I am wanting to delete the lead record which triggers the after insert oif the field TriggerDelete__c=true

I get an soql 101 error due to it not being batchified from my test class inserting 200 records. 

Can anyone give me a pointer on how I would do this?
 

trigger Lead_HDL_AI on Lead (after insert) {
	
	//list<Lead> LeadList = [SELECT Id FROM Lead WHERE Id =:record.Id LIMIT 1];	

    for(Lead record: Trigger.new) {
        //Query Lead
        List<Lead> LeadList = [SELECT Id FROM Lead WHERE Id =:record.Id LIMIT 1]; 
        //Delete Lead
        if(record.TriggerDelete__c==true){try{DELETE LeadList;}catch(Exception e){}                          
        }
    }   
}

 
Hello Users

I have a need to bulkify the below trigger.

This works great with the UI, however with an API bulk inserting, is causing some issues with SOQL 101 governing limit.

The process is, on the before insert of a lead, it checks to see if

1) an existing lead is in the database with the same email (update a field on lead if found), then delete the lead record after insert 
2) if an email address exists on the contact record, update the contact record if found, and delete the lead after insert.
3) Write a custom object (LDS__c) record with some details. (not important)

I am failing at line 75, when i query the contact object to update within the for loop

Contact Contact1 = [Select Id from Contact where Id =: ContactId limit 1];

I am failing in my test class to push in bulk records

All help is appreciated.

Lead before insert trigger
 
/******************************************************************
Created By : David Robinson (Blirt)
*******************************************************************/
trigger Lead_HDL_BI on Lead (before insert) {
    
    public string LeadEmail;
    public boolean ContactFound;
    public string ContactId;
    public boolean LeadFound;
    public string LeadId;
    Id LeadRTNonSearchable  = [SELECT Id,Name,DeveloperName FROM RecordType WHERE DeveloperName='Non_Searchable' AND SObjectType='Lead' LIMIT 1].Id;
    Id LeadRTSearchable     = [SELECT Id,Name,DeveloperName FROM RecordType WHERE DeveloperName='Searchable' AND SObjectType='Lead' LIMIT 1].Id;
    
    //Query Contacts for matching email address
    List<Contact> ContactList = [
        SELECT Id 
        FROM Contact
        WHERE Email =: LeadEmail 
        ORDER BY LastModifiedDate DESC
        LIMIT 1
    ]; 
    
    //Query Leads for matching email address
    List<Lead> LeadList = [
        SELECT Id 
        FROM Lead
        WHERE Email =: LeadEmail 
        AND IsConverted = false //Only include Non Converted Leads
        AND (RecordTypeId =: LeadRTSearchable OR RecordTypeId = null) //Only include Searchable Leads or RT = null
        ORDER BY LastModifiedDate DESC
        LIMIT 1
    ];     
    
    for(Lead record: Trigger.new) {

        try{
            LeadEmail = record.Email.trim();
        }catch(Exception e){
        }
       
        if(record.LeadSource == 'Big Commerce Book Purchase') {
            record.Book_Purchaser__c = 'Yes';
        }           
        if(record.LeadSource == 'Blog Subscriber') {
            record.Blog_Subscriber__c = 'Yes';
        } 

        ContactId = null;
        
        try{
            ContactId = ContactList[0].Id;
            ContactFound=true;
        }catch(Exception e){
            ContactId = null;
            ContactFound=false;
        }
        
        LeadId = null;
        
        try{
            LeadId = LeadList[0].Id;
            LeadFound=true;
        }catch(Exception e){
            LeadId = null;
            LeadFound=false;
        }  
        //Only run when email address field has a value
        if(record.Email!=null){
            //Run if Contact with same email Found
            if(ContactFound=true){
                //Update Contact and Lead   
                if(record.LeadSource == 'Big Commerce Book Purchase') { 
                    try{
                        //Update Found Contact
                        Contact Contact1 = [Select Id from Contact where Id =: ContactId limit 1];
                        Contact1.Book_Purchaser__c = 'Yes';
                        Contact1.Book_Purchase_date__c = record.Book_Purchase_date__c;  
                        update Contact1;  
                        //Update New Lead
                        record.TriggerDelete__c=true;
                        //Insert log record
                        LDS__c LeadLog = new LDS__c(
                            CreatedDate__c=datetime.now()
                            ,Company__c=record.Company
                            ,Description__c='ContactFound=true, record.LeadSource == Big Commerce Book Purchase'
                            ,Email__c=record.Email
                            ,FirstName__c=record.FirstName
                            ,LastName__c=record.LastName
                            ,LeadSource__c=record.LeadSource
                            ,Book_Purchase_date__c=record.Book_Purchase_date__c
                            ,Blog_Subscription_date__c=record.Blog_Subscription_date__c
                        );
                        //insert LeadLog;                                
                    }catch(Exception e){
                    }                                       
                } 
                //Update Contact and Lead           
                if(record.LeadSource == 'Blog Subscriber') {
                    try{
                        //Update Found Contact
                        Contact Contact1 = [Select Id from Contact where Id =: ContactId limit 1];
                        Contact1.Blog_Subscriber__c = 'Yes'; 
                        Contact1.Blog_Subscription_date__c = record.Blog_Subscription_date__c; 
                        update Contact1;
                        //Update New Lead
                        record.TriggerDelete__c=true;
                        //Insert log record
                        LDS__c LeadLog = new LDS__c(
                            CreatedDate__c=datetime.now()
                            ,Company__c=record.Company
                            ,Description__c='ContactFound=true, record.LeadSource == Blog Subscriber'
                            ,Email__c=record.Email
                            ,FirstName__c=record.FirstName
                            ,LastName__c=record.LastName
                            ,LeadSource__c=record.LeadSource
                            ,Book_Purchase_date__c=record.Book_Purchase_date__c
                            ,Blog_Subscription_date__c=record.Blog_Subscription_date__c
                        );
                        insert LeadLog;                                         
                    }catch(Exception e){
                    }                         
                } 
            }
            //Run if Lead with same email Found
            if(LeadFound=true){
                //Update Lead
                if(record.LeadSource == 'Big Commerce Book Purchase') { 
                    try{
                        //Update Found Lead
                        Lead Lead1 = [Select Id from Lead where Id =: LeadId limit 1];
                        Lead1.Book_Purchaser__c = 'Yes'; 
                        Lead1.Book_Purchase_date__c = record.Book_Purchase_date__c; 
                        update Lead1;                      
                        //Update New Lead
                        record.TriggerDelete__c=true;
                        //Insert log record
                        LDS__c LeadLog = new LDS__c(
                            CreatedDate__c=datetime.now()
                            ,Company__c=record.Company
                            ,Description__c='LeadFound=true, record.LeadSource == Big Commerce Book Purchase'
                            ,Email__c=record.Email
                            ,FirstName__c=record.FirstName
                            ,LastName__c=record.LastName
                            ,LeadSource__c=record.LeadSource
                            ,Book_Purchase_date__c=record.Book_Purchase_date__c
                            ,Blog_Subscription_date__c=record.Blog_Subscription_date__c
                        );
                        insert LeadLog;                         
                    }catch(Exception e){
                    }                 
                } 
                //Update Lead           
                if(record.LeadSource == 'Blog Subscriber') {
                    try{
                        //Update Found Lead
                        Lead Lead1 = [Select Id from Lead where Id =: LeadId limit 1];
                        Lead1.Blog_Subscriber__c = 'Yes'; 
                        Lead1.Blog_Subscription_date__c = record.Blog_Subscription_date__c;
                        update Lead1;                       
                        //Update New Lead
                        record.TriggerDelete__c=true;
                        //Insert log record
                        LDS__c LeadLog = new LDS__c(
                            CreatedDate__c=datetime.now()
                            ,Company__c=record.Company
                            ,Description__c='LeadFound=true, record.LeadSource == Blog Subscriber'
                            ,Email__c=record.Email
                            ,FirstName__c=record.FirstName
                            ,LastName__c=record.LastName
                            ,LeadSource__c=record.LeadSource
                            ,Book_Purchase_date__c=record.Book_Purchase_date__c
                            ,Blog_Subscription_date__c=record.Blog_Subscription_date__c
                        );
                        insert LeadLog;                             
                    }catch(Exception e){
                    }                                              
                } 
            }            
        }
    }
}

Lead after insert (delete record)
 
/******************************************************************
Created By : David Robinson (Blirt)
*******************************************************************/
trigger Lead_HDL_AI on Lead (after insert) {
    for(Lead record: Trigger.new) {
        //Query Lead
        List<Lead> LeadList = [SELECT Id FROM Lead WHERE Id =:record.Id LIMIT 1]; 
        //Delete Lead
        if(record.TriggerDelete__c==true){try{DELETE LeadList;}catch(Exception e){}                          
        }
    }   
}



Lead test class
 
/******************************************************************
Created By : David Robinson Blirt
*******************************************************************/
@isTest
private without sharing class Lead_HDL_TC{

    /******************************************************************
    Declare all record variables here. 
    Examples: 
        private static Account AC1;
        private static Tax__c TA1;
    ********************************************************************/
    
    private static Account AC1;
    private static Contact CO1;
    private static Lead L1;
    private static Lead L2;
    private static Lead L3;
    private static Lead L4;
    private static Lead L5;
      
    /******************************************************************
    Write your Test Methods Here. You can write as many as you like
    ********************************************************************/

    static testMethod void TestBatch() {
        try {
            insert createLeads(200);
            System.assert(false, 'Exception expected');
        } catch (DmlException e) {
            System.assertEquals(200 - 100, e.getNumDml());
        }
    }

    //static testMethod void Increment() {
    //    insert createLeads(98);
    //    try {
    //        insert createLeads(5);
    //        System.assert(false, 'Exception expected');
    //    } catch (DmlException e) {
    //        System.assertEquals(100 - 98 + 5, e.getNumDml());
    //    }
    //}

    private static Lead[] createLeads(Integer n) {
        Lead[] leads = new Lead[] {};
        for(Integer i = 0; i < n; i++) {
            leads.add(new Lead(
		            FirstName='F1'+ i
		            ,LastName='L1'+ i
		            ,Email='test@test'+ i +'.com'
		            ,Status='Open'
		            ,Company='Test1'
		            ,LeadSource='Big Commerce Book Purchase'
		            ,TriggerDelete__c=false   
	            ));
        }
        return leads;
    }

    private static testMethod void TestUI() {   
        
        /***********************************************************
        * INSERT TEST METHODS HERE
        ************************************************************/
        insertTestAccounts(); 
        insertTestContacts();
        //insertTestLeads();                           
        
    } 
    
    /******************************************************************
    Write your InsertRecord functions here.
    ********************************************************************/

    // INSERT ACCOUNTS
    
    public static void insertTestAccounts()
    {

        List<Account> remRecords= [SELECT Id FROM Account];  
        DELETE remRecords;
        System.assertEquals(0,[SELECT count() FROM Account]);
                      
        List<Account> Accounts = new List<Account>();      
        
        AC1 = NEW Account(
             Name='Test1'
        );

        Accounts.add(AC1);                           
        
        INSERT Accounts;
        UPDATE Accounts;
        
        System.assertEquals(1,[SELECT count() FROM Account]);
    }  

    // INSERT CONTACTS
    
    public static void insertTestContacts()
    {

        List<Contact> remRecords= [SELECT Id FROM Contact];  
        DELETE remRecords;
        System.assertEquals(0,[SELECT count() FROM Contact]);
                      
        List<Contact> Contacts = new List<Contact>();      
        
        CO1 = NEW Contact(
            FirstName='F1'
            ,LastName='L1'
            ,Account=AC1
            ,Email='test@test.com'
        );
   
        Contacts.add(CO1);                           
        
        INSERT Contacts;
        UPDATE Contacts;
        
        System.assertEquals(1,[SELECT count() FROM Contact]);
    }       

    // INSERT LEADS
    
    public static void insertTestLeads()
    {

        //List<Lead> remRecords= [SELECT Id FROM Lead];  
        //DELETE remRecords;
        //System.assertEquals(0,[SELECT count() FROM Lead]);
                      
        List<Lead> Leads = new List<Lead>();      
        
        L1 = NEW Lead(
            FirstName='F1'
            ,LastName='L1'
            ,Email='test@test.com'
            ,Status='Open'
            ,Company='Test1'
            ,LeadSource='Big Commerce Book Purchase'
            ,TriggerDelete__c=false
            
        );

        L2 = NEW Lead(
            FirstName='F1'
            ,LastName='L1'
            ,Email='test@test.com'
            ,Status='Open'
            ,Company='Test1'
            ,LeadSource='Blog Subscriber'
            ,TriggerDelete__c=false
            
        );

        L3 = NEW Lead(
            FirstName='F1'
            ,LastName='L1'
            ,Email='test41234234234324324@test.com'
            ,Status='Open'
            ,Company='Test1'
            ,LeadSource='Some Other Source'
            ,TriggerDelete__c=false
            
        );

        L4 = NEW Lead(
            FirstName='F1'
            ,LastName='L1'
            ,Email='test@test.com'
            ,Status='Open'
            ,Company='Test1'
            ,LeadSource='Blog Subscriber'
            ,TriggerDelete__c=false
            
        );

        L5 = NEW Lead(
            FirstName='F1'
            ,LastName='L1'
            ,Email='test12121@1212121test.com'
            ,Status='Open'
            ,Company='Test1'
            ,LeadSource='Blog Subscriber'
            ,TriggerDelete__c=true
            
        );
   
        Leads.add(L1);   
        Leads.add(L2); 
        Leads.add(L3);                          
        Leads.add(L4);  
        Leads.add(L5); 
                
        INSERT Leads;
        //UPDATE Leads;
        
        //System.assertEquals(5,[SELECT count() FROM Lead]);

    }      

}



 

Hello

I am wanting to delete the lead record which triggers the after insert oif the field TriggerDelete__c=true

I get an soql 101 error due to it not being batchified from my test class inserting 200 records. 

Can anyone give me a pointer on how I would do this?
 

trigger Lead_HDL_AI on Lead (after insert) {
	
	//list<Lead> LeadList = [SELECT Id FROM Lead WHERE Id =:record.Id LIMIT 1];	

    for(Lead record: Trigger.new) {
        //Query Lead
        List<Lead> LeadList = [SELECT Id FROM Lead WHERE Id =:record.Id LIMIT 1]; 
        //Delete Lead
        if(record.TriggerDelete__c==true){try{DELETE LeadList;}catch(Exception e){}                          
        }
    }   
}

 
Hello Users

I have a need to bulkify the below trigger.

This works great with the UI, however with an API bulk inserting, is causing some issues with SOQL 101 governing limit.

The process is, on the before insert of a lead, it checks to see if

1) an existing lead is in the database with the same email (update a field on lead if found), then delete the lead record after insert 
2) if an email address exists on the contact record, update the contact record if found, and delete the lead after insert.
3) Write a custom object (LDS__c) record with some details. (not important)

I am failing at line 75, when i query the contact object to update within the for loop

Contact Contact1 = [Select Id from Contact where Id =: ContactId limit 1];

I am failing in my test class to push in bulk records

All help is appreciated.

Lead before insert trigger
 
/******************************************************************
Created By : David Robinson (Blirt)
*******************************************************************/
trigger Lead_HDL_BI on Lead (before insert) {
    
    public string LeadEmail;
    public boolean ContactFound;
    public string ContactId;
    public boolean LeadFound;
    public string LeadId;
    Id LeadRTNonSearchable  = [SELECT Id,Name,DeveloperName FROM RecordType WHERE DeveloperName='Non_Searchable' AND SObjectType='Lead' LIMIT 1].Id;
    Id LeadRTSearchable     = [SELECT Id,Name,DeveloperName FROM RecordType WHERE DeveloperName='Searchable' AND SObjectType='Lead' LIMIT 1].Id;
    
    //Query Contacts for matching email address
    List<Contact> ContactList = [
        SELECT Id 
        FROM Contact
        WHERE Email =: LeadEmail 
        ORDER BY LastModifiedDate DESC
        LIMIT 1
    ]; 
    
    //Query Leads for matching email address
    List<Lead> LeadList = [
        SELECT Id 
        FROM Lead
        WHERE Email =: LeadEmail 
        AND IsConverted = false //Only include Non Converted Leads
        AND (RecordTypeId =: LeadRTSearchable OR RecordTypeId = null) //Only include Searchable Leads or RT = null
        ORDER BY LastModifiedDate DESC
        LIMIT 1
    ];     
    
    for(Lead record: Trigger.new) {

        try{
            LeadEmail = record.Email.trim();
        }catch(Exception e){
        }
       
        if(record.LeadSource == 'Big Commerce Book Purchase') {
            record.Book_Purchaser__c = 'Yes';
        }           
        if(record.LeadSource == 'Blog Subscriber') {
            record.Blog_Subscriber__c = 'Yes';
        } 

        ContactId = null;
        
        try{
            ContactId = ContactList[0].Id;
            ContactFound=true;
        }catch(Exception e){
            ContactId = null;
            ContactFound=false;
        }
        
        LeadId = null;
        
        try{
            LeadId = LeadList[0].Id;
            LeadFound=true;
        }catch(Exception e){
            LeadId = null;
            LeadFound=false;
        }  
        //Only run when email address field has a value
        if(record.Email!=null){
            //Run if Contact with same email Found
            if(ContactFound=true){
                //Update Contact and Lead   
                if(record.LeadSource == 'Big Commerce Book Purchase') { 
                    try{
                        //Update Found Contact
                        Contact Contact1 = [Select Id from Contact where Id =: ContactId limit 1];
                        Contact1.Book_Purchaser__c = 'Yes';
                        Contact1.Book_Purchase_date__c = record.Book_Purchase_date__c;  
                        update Contact1;  
                        //Update New Lead
                        record.TriggerDelete__c=true;
                        //Insert log record
                        LDS__c LeadLog = new LDS__c(
                            CreatedDate__c=datetime.now()
                            ,Company__c=record.Company
                            ,Description__c='ContactFound=true, record.LeadSource == Big Commerce Book Purchase'
                            ,Email__c=record.Email
                            ,FirstName__c=record.FirstName
                            ,LastName__c=record.LastName
                            ,LeadSource__c=record.LeadSource
                            ,Book_Purchase_date__c=record.Book_Purchase_date__c
                            ,Blog_Subscription_date__c=record.Blog_Subscription_date__c
                        );
                        //insert LeadLog;                                
                    }catch(Exception e){
                    }                                       
                } 
                //Update Contact and Lead           
                if(record.LeadSource == 'Blog Subscriber') {
                    try{
                        //Update Found Contact
                        Contact Contact1 = [Select Id from Contact where Id =: ContactId limit 1];
                        Contact1.Blog_Subscriber__c = 'Yes'; 
                        Contact1.Blog_Subscription_date__c = record.Blog_Subscription_date__c; 
                        update Contact1;
                        //Update New Lead
                        record.TriggerDelete__c=true;
                        //Insert log record
                        LDS__c LeadLog = new LDS__c(
                            CreatedDate__c=datetime.now()
                            ,Company__c=record.Company
                            ,Description__c='ContactFound=true, record.LeadSource == Blog Subscriber'
                            ,Email__c=record.Email
                            ,FirstName__c=record.FirstName
                            ,LastName__c=record.LastName
                            ,LeadSource__c=record.LeadSource
                            ,Book_Purchase_date__c=record.Book_Purchase_date__c
                            ,Blog_Subscription_date__c=record.Blog_Subscription_date__c
                        );
                        insert LeadLog;                                         
                    }catch(Exception e){
                    }                         
                } 
            }
            //Run if Lead with same email Found
            if(LeadFound=true){
                //Update Lead
                if(record.LeadSource == 'Big Commerce Book Purchase') { 
                    try{
                        //Update Found Lead
                        Lead Lead1 = [Select Id from Lead where Id =: LeadId limit 1];
                        Lead1.Book_Purchaser__c = 'Yes'; 
                        Lead1.Book_Purchase_date__c = record.Book_Purchase_date__c; 
                        update Lead1;                      
                        //Update New Lead
                        record.TriggerDelete__c=true;
                        //Insert log record
                        LDS__c LeadLog = new LDS__c(
                            CreatedDate__c=datetime.now()
                            ,Company__c=record.Company
                            ,Description__c='LeadFound=true, record.LeadSource == Big Commerce Book Purchase'
                            ,Email__c=record.Email
                            ,FirstName__c=record.FirstName
                            ,LastName__c=record.LastName
                            ,LeadSource__c=record.LeadSource
                            ,Book_Purchase_date__c=record.Book_Purchase_date__c
                            ,Blog_Subscription_date__c=record.Blog_Subscription_date__c
                        );
                        insert LeadLog;                         
                    }catch(Exception e){
                    }                 
                } 
                //Update Lead           
                if(record.LeadSource == 'Blog Subscriber') {
                    try{
                        //Update Found Lead
                        Lead Lead1 = [Select Id from Lead where Id =: LeadId limit 1];
                        Lead1.Blog_Subscriber__c = 'Yes'; 
                        Lead1.Blog_Subscription_date__c = record.Blog_Subscription_date__c;
                        update Lead1;                       
                        //Update New Lead
                        record.TriggerDelete__c=true;
                        //Insert log record
                        LDS__c LeadLog = new LDS__c(
                            CreatedDate__c=datetime.now()
                            ,Company__c=record.Company
                            ,Description__c='LeadFound=true, record.LeadSource == Blog Subscriber'
                            ,Email__c=record.Email
                            ,FirstName__c=record.FirstName
                            ,LastName__c=record.LastName
                            ,LeadSource__c=record.LeadSource
                            ,Book_Purchase_date__c=record.Book_Purchase_date__c
                            ,Blog_Subscription_date__c=record.Blog_Subscription_date__c
                        );
                        insert LeadLog;                             
                    }catch(Exception e){
                    }                                              
                } 
            }            
        }
    }
}

Lead after insert (delete record)
 
/******************************************************************
Created By : David Robinson (Blirt)
*******************************************************************/
trigger Lead_HDL_AI on Lead (after insert) {
    for(Lead record: Trigger.new) {
        //Query Lead
        List<Lead> LeadList = [SELECT Id FROM Lead WHERE Id =:record.Id LIMIT 1]; 
        //Delete Lead
        if(record.TriggerDelete__c==true){try{DELETE LeadList;}catch(Exception e){}                          
        }
    }   
}



Lead test class
 
/******************************************************************
Created By : David Robinson Blirt
*******************************************************************/
@isTest
private without sharing class Lead_HDL_TC{

    /******************************************************************
    Declare all record variables here. 
    Examples: 
        private static Account AC1;
        private static Tax__c TA1;
    ********************************************************************/
    
    private static Account AC1;
    private static Contact CO1;
    private static Lead L1;
    private static Lead L2;
    private static Lead L3;
    private static Lead L4;
    private static Lead L5;
      
    /******************************************************************
    Write your Test Methods Here. You can write as many as you like
    ********************************************************************/

    static testMethod void TestBatch() {
        try {
            insert createLeads(200);
            System.assert(false, 'Exception expected');
        } catch (DmlException e) {
            System.assertEquals(200 - 100, e.getNumDml());
        }
    }

    //static testMethod void Increment() {
    //    insert createLeads(98);
    //    try {
    //        insert createLeads(5);
    //        System.assert(false, 'Exception expected');
    //    } catch (DmlException e) {
    //        System.assertEquals(100 - 98 + 5, e.getNumDml());
    //    }
    //}

    private static Lead[] createLeads(Integer n) {
        Lead[] leads = new Lead[] {};
        for(Integer i = 0; i < n; i++) {
            leads.add(new Lead(
		            FirstName='F1'+ i
		            ,LastName='L1'+ i
		            ,Email='test@test'+ i +'.com'
		            ,Status='Open'
		            ,Company='Test1'
		            ,LeadSource='Big Commerce Book Purchase'
		            ,TriggerDelete__c=false   
	            ));
        }
        return leads;
    }

    private static testMethod void TestUI() {   
        
        /***********************************************************
        * INSERT TEST METHODS HERE
        ************************************************************/
        insertTestAccounts(); 
        insertTestContacts();
        //insertTestLeads();                           
        
    } 
    
    /******************************************************************
    Write your InsertRecord functions here.
    ********************************************************************/

    // INSERT ACCOUNTS
    
    public static void insertTestAccounts()
    {

        List<Account> remRecords= [SELECT Id FROM Account];  
        DELETE remRecords;
        System.assertEquals(0,[SELECT count() FROM Account]);
                      
        List<Account> Accounts = new List<Account>();      
        
        AC1 = NEW Account(
             Name='Test1'
        );

        Accounts.add(AC1);                           
        
        INSERT Accounts;
        UPDATE Accounts;
        
        System.assertEquals(1,[SELECT count() FROM Account]);
    }  

    // INSERT CONTACTS
    
    public static void insertTestContacts()
    {

        List<Contact> remRecords= [SELECT Id FROM Contact];  
        DELETE remRecords;
        System.assertEquals(0,[SELECT count() FROM Contact]);
                      
        List<Contact> Contacts = new List<Contact>();      
        
        CO1 = NEW Contact(
            FirstName='F1'
            ,LastName='L1'
            ,Account=AC1
            ,Email='test@test.com'
        );
   
        Contacts.add(CO1);                           
        
        INSERT Contacts;
        UPDATE Contacts;
        
        System.assertEquals(1,[SELECT count() FROM Contact]);
    }       

    // INSERT LEADS
    
    public static void insertTestLeads()
    {

        //List<Lead> remRecords= [SELECT Id FROM Lead];  
        //DELETE remRecords;
        //System.assertEquals(0,[SELECT count() FROM Lead]);
                      
        List<Lead> Leads = new List<Lead>();      
        
        L1 = NEW Lead(
            FirstName='F1'
            ,LastName='L1'
            ,Email='test@test.com'
            ,Status='Open'
            ,Company='Test1'
            ,LeadSource='Big Commerce Book Purchase'
            ,TriggerDelete__c=false
            
        );

        L2 = NEW Lead(
            FirstName='F1'
            ,LastName='L1'
            ,Email='test@test.com'
            ,Status='Open'
            ,Company='Test1'
            ,LeadSource='Blog Subscriber'
            ,TriggerDelete__c=false
            
        );

        L3 = NEW Lead(
            FirstName='F1'
            ,LastName='L1'
            ,Email='test41234234234324324@test.com'
            ,Status='Open'
            ,Company='Test1'
            ,LeadSource='Some Other Source'
            ,TriggerDelete__c=false
            
        );

        L4 = NEW Lead(
            FirstName='F1'
            ,LastName='L1'
            ,Email='test@test.com'
            ,Status='Open'
            ,Company='Test1'
            ,LeadSource='Blog Subscriber'
            ,TriggerDelete__c=false
            
        );

        L5 = NEW Lead(
            FirstName='F1'
            ,LastName='L1'
            ,Email='test12121@1212121test.com'
            ,Status='Open'
            ,Company='Test1'
            ,LeadSource='Blog Subscriber'
            ,TriggerDelete__c=true
            
        );
   
        Leads.add(L1);   
        Leads.add(L2); 
        Leads.add(L3);                          
        Leads.add(L4);  
        Leads.add(L5); 
                
        INSERT Leads;
        //UPDATE Leads;
        
        //System.assertEquals(5,[SELECT count() FROM Lead]);

    }      

}