• rlupu
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 5
    Replies
I wonder if it's possible to schedule mass deletion with Salesforce.
(something like 'at midnight, delete all Contact records which custom field con_stat='Obsolete')
 
If anyone can help, thank you.
  • June 09, 2008
  • Like
  • 0

The Salesforce implementation I'm trying to work with contains:
- lead_source_code__c as a custom text field of the Lead object
- Lead_Source_Code__c as a custom object that contains a custom lookup(Lead) field called lead__c


Whenever a new lead becomes candidate for insertion,
- I have to check the database for unconverted leads that have the same identification key (name+company+email) as the new lead
- If there are such leads, I have to pick up the most recent one and to check if the lead_source_code of the incoming lead has
  already been part of the collection of lead_source_codes of the chosen existing lead.
- If it hasn't, then the new lead_source_code must be added to the collection of the existing lead and the incoming lead creation
  must be prevented.

Below is part of the code that I'm trying to use for this purpose.

trigger AddLeadSourceToCollection on Lead (before insert)
{
    for (Lead ld:System.Trigger.new)
    {
       //find the most recent unconverted lead that has the same identification key  as the new lead
            Lead[] unconv_lds_coll=[select id,createddate from lead where isdeleted=false and isconverted=false and firstname=:ld.firstname and lastname=:ld.lastname and company=:ld.company and email=:ld.email order by createddate asc];
            datetime most_rec;
            ID ld_id;
            for (Lead unconv_ld:unconv_lds_coll)
            {
              most_rec=unconv_ld.createddate;
              ld_id =unconv_ld.id;
            }
       //Find out whether the value of the Lead_Source_Code field of the new lead
       //has already existed
       //in the collection of Lead_Source_Codes of the unconverted lead you previously found.
       //If it hasn't existed, it must be added and the new lead shouldn't be created any more.
            integer ldsrc_exists;
            ldsrc_exists=[select count() from Lead_Source_Code__c where isdeleted=false and lead__c=:ld_id and name=:ld.lead_source_code__c];
            if (ldsrc_exists==0)
            {
              Lead_Source_Code__c ldsrc=new Lead_Source_Code__c(lead__c=ld_id, name=ld.lead_source_code__c);
              insert ldsrc;
            }
       ld.addError('The new lead was not inserted.');   
    }
}


It seems natural to me that the addError method, which prevents the creation of the new lead, rolls back the part that was supposed
to add the new lead_source_code to the collection of the existing lead. However, I don't know any other way to prevent the
creation of the new lead and allow the addition of the new lead_source_code.

If any of you can help, please do it.
Thank you

 

 

  • June 09, 2008
  • Like
  • 0

I have to write some code for a Salesforce Enterprise edition that doesn’t allow me to create/modify/drop triggers or Apex classes by using the interface.

I created in Eclipse the class which code is written below. When attempting to save it, I get this message:'Test coverage of selected Apex Class and Trigger is 46%, at least 75% test coverage is required'. I know I’m missing something here, but I cannot realize what.

Can someone help please? Thank you.

global class test_records

{

    WebService static String create_test_records()

    {

        String mystr;

        try

       {

           Account a=new Account(name='test_acc');

           insert a;

           ID a_id=[select id from account where name='test_acc'].id;

           Purchases__c p=new Purchases__c(accountid__c=a_id);

           insert p;

           ID p_id=[select id from purchases__c where accountid__c=:a_id].id;

           PurchaseItems__c i1=new PurchaseItems__c(purchaseid__c=p_id, package__c='Item A', price__c=10, quantity__c=1,

                                                                               Barcode_Email_Status__c='Not Sent',

                                                                               Barcode_Email_Recipient__c='x@y.com');

           insert i1;

           PurchaseItems__c i2=new PurchaseItems__c(purchaseid__c=p_id, package__c='Item B', price__c=20, quantity__c=2,

                                                                              Barcode_Email_Status__c='Not Sent',

                                                                              Barcode_Email_Recipient__c='x@y.com');

            insert i2;

            mystr='done';

       }

       catch (System.DMLException e)

       {

          mystr='dml error';

       }

       return mystr;

    }

    static testMethod void test_create_test_records()

    {

        System.assertEquals('done',create_test_records());

    }

}

  • March 26, 2008
  • Like
  • 0

I have to write some code for a Salesforce Enterprise edition that doesn’t allow me to create/modify/drop triggers or Apex classes by using the interface.

I managed to create a trigger by using Eclipse.The Salesforce interface shows me that the trigger code is completely saved and is valid. However, I cannot activate the trigger either by using the Salesforce interface or Eclipse.

I think I miss something here. Can someone help, please?

Thank you

  • March 26, 2008
  • Like
  • 0
I wonder if it's possible to schedule mass deletion with Salesforce.
(something like 'at midnight, delete all Contact records which custom field con_stat='Obsolete')
 
If anyone can help, thank you.
  • June 09, 2008
  • Like
  • 0

I have to write some code for a Salesforce Enterprise edition that doesn’t allow me to create/modify/drop triggers or Apex classes by using the interface.

I created in Eclipse the class which code is written below. When attempting to save it, I get this message:'Test coverage of selected Apex Class and Trigger is 46%, at least 75% test coverage is required'. I know I’m missing something here, but I cannot realize what.

Can someone help please? Thank you.

global class test_records

{

    WebService static String create_test_records()

    {

        String mystr;

        try

       {

           Account a=new Account(name='test_acc');

           insert a;

           ID a_id=[select id from account where name='test_acc'].id;

           Purchases__c p=new Purchases__c(accountid__c=a_id);

           insert p;

           ID p_id=[select id from purchases__c where accountid__c=:a_id].id;

           PurchaseItems__c i1=new PurchaseItems__c(purchaseid__c=p_id, package__c='Item A', price__c=10, quantity__c=1,

                                                                               Barcode_Email_Status__c='Not Sent',

                                                                               Barcode_Email_Recipient__c='x@y.com');

           insert i1;

           PurchaseItems__c i2=new PurchaseItems__c(purchaseid__c=p_id, package__c='Item B', price__c=20, quantity__c=2,

                                                                              Barcode_Email_Status__c='Not Sent',

                                                                              Barcode_Email_Recipient__c='x@y.com');

            insert i2;

            mystr='done';

       }

       catch (System.DMLException e)

       {

          mystr='dml error';

       }

       return mystr;

    }

    static testMethod void test_create_test_records()

    {

        System.assertEquals('done',create_test_records());

    }

}

  • March 26, 2008
  • Like
  • 0

I have to write some code for a Salesforce Enterprise edition that doesn’t allow me to create/modify/drop triggers or Apex classes by using the interface.

I managed to create a trigger by using Eclipse.The Salesforce interface shows me that the trigger code is completely saved and is valid. However, I cannot activate the trigger either by using the Salesforce interface or Eclipse.

I think I miss something here. Can someone help, please?

Thank you

  • March 26, 2008
  • Like
  • 0