• dmason
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 12
    Replies

 

Hey All 

 

hope is well, i need some advice / pointers

 

I understand that with the new 14 release we can create triggers on the user object (not sure if this is the case)

 

Aim - In this example https://www.youtube.com/watch?v=QrtVN8vZGJU you can see that “Jim Smith” is going through the  de-activation process . What i want to do, is when you press save, an apex trigger  is triggered and automatically re-assigns “Jim Smith” Leads into this appropriate manager

 

Looking around, It shouldn't be an issue to grab the users's id, and the manager id and change ownership of those leads to the new user, but i may be mistaken and i need some help.

 

The Main issues that potentally could stop this from working is 

 

1.  If there isn't a manager listed you could not assign.

2.  If the manager is also inactive you will not be able to assign the leads (you can only assign records to active users).

3.  If any of the leads have not been edited by the current user and there is validation on the lead that hasn't been completed then the lead will not get reassigned.

  • October 08, 2013
  • Like
  • 0

Hey All 

 

hope is well, i need some advice / pointers

 

I understand that with the new 14 release we can create triggers on the user object (not sure if this is the case)

 

Aim - In this example https://www.youtube.com/watch?v=QrtVN8vZGJU you can see that “Jim Smith” is going through the  de-activation process . What i want to do, is when you press save, an apex trigger  is triggered and automatically re-assigns “Jim Smith” Leads into this appropriate manager

 

Looking around, It shouldn't be an issue to grab the users's id, and the manager id and change ownership of those leads to the new user, but i may be mistaken and i need some help.

 

The Main issues that potentally could stop this from working is 

 

1.  If there isn't a manager listed you could not assign.

2.  If the manager is also inactive you will not be able to assign the leads (you can only assign records to active users).

3.  If any of the leads have not been edited by the current user and there is validation on the lead that hasn't been completed then the lead will not get reassigned.

  • October 08, 2013
  • Like
  • 0

Hey All

just a quick question

Aim – User  is leaving the organisation, so i need to deactivate the user, before de-activating i want to assign all his records example leads & opportunities to his manager .

I want to achieve all this via code instead of using the data loader.

Is this viable ? 

  • September 20, 2013
  • Like
  • 0

 

Hi guys 

 

I need some help I have created the following apex trigger below, However the trigger currently looks at exact matches on the company name


Is there any way that i could incorporate some kind of wildcard, so the search isn’t exact ?

 

From reading the forums, it looks like i need to go along the lines of "

 

String myValue = '%' + s + '%'
List<Lead> = new List<Lead>([Select Id, companyName from leads where customField like :myvalue]);
 
Can anyone point me in the correct direction ?
 
 

Trigger DuplicateLeadPreventer on Lead

                               (before insert, before update) {

//Get map of record types we care about from Custom Setting

 Map<String, Manage_Lead_Dupes_C__c> leadrtmap = Manage_Lead_Dupes_C__c.getAll();

//Since only certain leads will match, put them in a separate list

 List<Lead> LeadstoProcess = new List<Lead> ();

 

 //Company to Lead Map

 Map<String, Lead> leadMap = new Map<String, Lead>();

     for (Lead lead : Trigger.new) {

  

     //Only process for Leads in our RecordTypeMap

         if (leadrtmap.keyset().contains(lead.RecordTypeId) ) {

                    

        // Make sure we don't treat an Company name that

       // isn't changing during an update as a duplicate.

  

              if (

                 (lead.company != null) &&

                 (Trigger.isInsert ||

                 (lead.company != Trigger.oldMap.get(lead.Id).company))

                 )

                 {

                                      

                    // Make sure another new lead isn't also a duplicate

          

                        if (leadMap.containsKey(lead.company)) {

                            lead.company.addError('Another new lead has the '

                                            + 'same company name.');

                        } else {

                            leadMap.put(lead.company , lead);

                            LeadstoProcess.add(lead);

                        }

                }

    } //end RT If Check

    } //End Loop

              

    /*

     Using a single database query, find all the leads in

     the database that have the same company address as any

     of the leads being inserted or updated.

  

   */

  

    Set<String> ExistingCompanies = new Set<String> ();

 

            for (Lead l: [Select Id, Company from Lead WHERE Company IN :leadMap.keyset()

                             AND RecordTypeId IN :leadrtmap.keyset()]) {

                          ExistingCompanies.add(l.Company);

                }

 

    //Now loop through leads to process, since we should only loop if matches

    for (Lead l : LeadstoProcess) {

        if (ExistingCompanies.contains(l.company) ) {

             l.company.addError('A lead with this company '

                               + 'name already exists.');

        }

    }

}

  • April 16, 2013
  • Like
  • 0

Hey Guys

I need some help

 

I have built the following apex trigger ( See below) however i need to apply the company search on a certain records types.

The Record types in question are  “FDMS Lead Generation  &  FDMS Sales Lead”, where do i add this into the code?

My apex trigger is


Trigger DuplicateLeadPreventer on Lead

                               (before insert, before update) {

 

    Map<String, Lead> leadMap = new Map<String, Lead>();

    for (Lead lead : System.Trigger.new) {

                               

        // Make sure we don't treat an Company name that 

       // isn't changing during an update as a duplicate. 

   

  if ((lead.company != null) &&

                (System.Trigger.isInsert ||

                (lead.company !=

                    System.Trigger.oldMap.get(lead.Id).company))) {

                               

            // Make sure another new lead isn't also a duplicate 

   

            if (leadMap.containsKey(lead.company)) {

                lead.company.addError('Another new lead has the '

                                    + 'same company name.');

            } else {

                leadMap.put(lead.company , lead);

            }

       }

    }

               

    // Using a single database query, find all the leads in 

   

    // the database that have the same company address as any 

   

    // of the leads being inserted or updated. 

   

    for (Lead lead : [SELECT company FROM Lead

                      WHERE company IN :leadMap.KeySet()]) {

        Lead newLead = leadMap.get(lead.company);

        newLead.company.addError('A lead with this company '

                               + 'name already exists.');

    }

}
  

  • April 11, 2013
  • Like
  • 0

HI

Guys i am new to apex class so my apologises if i am using the incorrect terminology

 

Aim : Preventing Duplicate Records from Saving


after hours of research i have found an apex code which i think could meet my criteria if the code is adapted.

 

Concept-

Already existing lead in database
Company Name : Test LTD
postcode : SS34EN

 

Trying to add new lead into database
Company name : Test Limited
postcode : SS34EN

apex class would look at the company name and postcode and apply some fuzzy logic, and if it sees that the new lead is already the same as the existing lead  then don’t allow the new lead to be saved onto the database.
I want this to be applied to leads being manually entered and also on a bulk insert

The apex code i have found is , from the code below, does my idea seem viable ?

 

public class leadDupePreventerTests{

        static testMethod void testLeadDupPreventer() {

              

      // First make sure there are no leads already in the system

      // that have the email addresses used for testing

      Set<String> testEmailAddress = new Set<String>();

      testEmailAddress.add('test1@duptest.com');

      testEmailAddress.add('test2@duptest.com');

      testEmailAddress.add('test3@duptest.com');

      testEmailAddress.add('test4@duptest.com');

      testEmailAddress.add('test5@duptest.com');

      System.assert([SELECT count() FROM Lead

                     WHERE Email IN :testEmailAddress] == 0);

              

      // Seed the database with some leads, and make sure they can

      // be bulk inserted successfully.

      Lead lead1 = new Lead(LastName='Test1', Company='Test1 Inc.',

                            Email='test1@duptest.com');

      Lead lead2 = new Lead(LastName='Test2', Company='Test2 Inc.',

                            Email='test4@duptest.com');

      Lead lead3 = new Lead(LastName='Test3', Company='Test3 Inc.',

                            Email='test5@duptest.com');

      Lead[] leads = new Lead[] {lead1, lead2, lead3};

      insert leads;

              

      // Now make sure that some of these leads can be changed and

      // then bulk updated successfully. Note that lead1 is not

      // being changed, but is still being passed to the update

      // call. This should be OK.

      lead2.Email = 'test2@duptest.com';

      lead3.Email = 'test3@duptest.com';

      update leads;

              

      // Make sure that single row lead duplication prevention works

      // on insert.

      Lead dup1 = new Lead(LastName='Test1Dup',

                           Company='Test1Dup Inc.',

                           Email='test1@duptest.com');

      try {

         insert dup1;

         System.assert(false);

      } catch (DmlException e) {

         System.assert(e.getNumDml() == 1);

         System.assert(e.getDmlIndex(0) == 0);

         System.assert(e.getDmlFields(0).size() == 1);

         System.assert(e.getDmlFields(0)[0] == 'Email');

         System.assert(e.getDmlMessage(0).indexOf(

            'A lead with this email address already exists.') > -1);

      }

              

      // Make sure that single row lead duplication prevention works

      // on update.

      dup1 = new Lead(Id = lead1.Id, LastName='Test1Dup',

                      Company='Test1Dup Inc.',

                      Email='test2@duptest.com');

      try {

         update dup1;

         System.assert(false);

      } catch (DmlException e) {

         System.assert(e.getNumDml() == 1);

         System.assert(e.getDmlIndex(0) == 0);

         System.assert(e.getDmlFields(0).size() == 1);

         System.assert(e.getDmlFields(0)[0] == 'Email');

         System.assert(e.getDmlMessage(0).indexOf(

            'A lead with this email address already exists.') > -1);

            }

       

      // Make sure that bulk lead duplication prevention works on

      // insert. Note that the first item being inserted is fine,

      // but the second and third items are duplicates. Note also

      // that since at least one record insert fails, the entire

      // transaction will be rolled back.

      dup1 = new Lead(LastName='Test1Dup', Company='Test1Dup Inc.',

                      Email='test4@duptest.com');

      Lead dup2 = new Lead(LastName='Test2Dup',

                           Company='Test2Dup Inc.',

                           Email='test2@duptest.com');

      Lead dup3 = new Lead(LastName='Test3Dup',

                           Company='Test3Dup Inc.',

                           Email='test3@duptest.com');

      Lead[] dups = new Lead[] {dup1, dup2, dup3};

      try {

         insert dups;

         System.assert(false);

      } catch (DmlException e) {

         System.assert(e.getNumDml() == 2);

         System.assert(e.getDmlIndex(0) == 1);

         System.assert(e.getDmlFields(0).size() == 1);

         System.assert(e.getDmlFields(0)[0] == 'Email');

         System.assert(e.getDmlMessage(0).indexOf(

            'A lead with this email address already exists.') > -1);

         System.assert(e.getDmlIndex(1) == 2);

         System.assert(e.getDmlFields(1).size() == 1);

         System.assert(e.getDmlFields(1)[0] == 'Email');

         System.assert(e.getDmlMessage(1).indexOf(

            'A lead with this email address already exists.') > -1);

      }

       

      // Make sure that bulk lead duplication prevention works on

      // update. Note that the first item being updated is fine,

      // because the email address is new, and the second item is

      // also fine, but in this case it's because the email

      // address doesn't change. The third case is flagged as an

      // error because it is a duplicate of the email address of the

      // first lead's value in the database, even though that value

      // is changing in this same update call. It would be an

      // interesting exercise to rewrite the trigger to allow this

      // case. Note also that since at least one record update

      // fails, the entire transaction will be rolled back.

      dup1 = new Lead(Id=lead1.Id, Email='test4@duptest.com');

      dup2 = new Lead(Id=lead2.Id, Email='test2@duptest.com');

      dup3 = new Lead(Id=lead3.Id, Email='test1@duptest.com');

      dups = new Lead[] {dup1, dup2, dup3};

      try {

         update dups;

         System.assert(false);

      } catch (DmlException e) {

         System.debug(e.getNumDml());

         System.debug(e.getDmlMessage(0));

         System.assert(e.getNumDml() == 1);

         System.assert(e.getDmlIndex(0) == 2);

         System.assert(e.getDmlFields(0).size() == 1);

         System.assert(e.getDmlFields(0)[0] == 'Email');

         System.assert(e.getDmlMessage(0).indexOf(

            'A lead with this email address already exists.') > -1);

            }

              

      // Make sure that duplicates in the submission are caught when

      // inserting leads. Note that this test also catches an

      // attempt to insert a lead where there is an existing

      // duplicate.

      dup1 = new Lead(LastName='Test1Dup', Company='Test1Dup Inc.',

                      Email='test4@duptest.com');

      dup2 = new Lead(LastName='Test2Dup', Company='Test2Dup Inc.',

                      Email='test4@duptest.com');

      dup3 = new Lead(LastName='Test3Dup', Company='Test3Dup Inc.',

                      Email='test3@duptest.com');

      dups = new Lead[] {dup1, dup2, dup3};

      try {

         insert dups;

         System.assert(false);

      } catch (DmlException e) {

         System.assert(e.getNumDml() == 2);

         System.assert(e.getDmlIndex(0) == 1);

         System.assert(e.getDmlFields(0).size() == 1);

         System.assert(e.getDmlFields(0)[0] == 'Email');

         System.assert(e.getDmlMessage(0).indexOf(

            'Another new lead has the same email address.') > -1);

         System.assert(e.getDmlIndex(1) == 2);

         System.assert(e.getDmlFields(1).size() == 1);

         System.assert(e.getDmlFields(1)[0] == 'Email');

         System.assert(e.getDmlMessage(1).indexOf(

            'A lead with this email address already exists.') > -1);

      }

              

      // Make sure that duplicates in the submission are caught when

      // updating leads. Note that this test also catches an attempt

      // to update a lead where there is an existing duplicate.

      dup1 = new Lead(Id=lead1.Id, Email='test4@duptest.com');

      dup2 = new Lead(Id=lead2.Id, Email='test4@duptest.com');

      dup3 = new Lead(Id=lead3.Id, Email='test2@duptest.com');

      dups = new Lead[] {dup1, dup2, dup3};

      try {

         update dups;

         System.assert(false);

      } catch (DmlException e) {

         System.assert(e.getNumDml() == 2);

         System.assert(e.getDmlIndex(0) == 1);

         System.assert(e.getDmlFields(0).size() == 1);

         System.assert(e.getDmlFields(0)[0] == 'Email');

         System.assert(e.getDmlMessage(0).indexOf(

            'Another new lead has the same email address.') > -1);

         System.assert(e.getDmlIndex(1) == 2);

         System.assert(e.getDmlFields(1).size() == 1);

         System.assert(e.getDmlFields(1)[0] == 'Email');

         System.assert(e.getDmlMessage(1).indexOf(

            'A lead with this email address already exists.') > -1);

      }

   }

}

 




 

 

  • April 11, 2013
  • Like
  • 0

Hey Guys

 

I am new to Apex coding so please be gentle

 

I need some help

 

Basically i have a huge backlog in my pipeline report, i thought of a way that i can overcome this but i am not sure its its viable

 

What i want to achieve is that is if the opportunity stage are any of the following

Qualified
Proposal
Application Docs Out
Application docs in (Complete)
Sent to Risk
Approved by Risk

 

and there has been no activity ( last modified date in the last 6months from todays date) then change the stage to "Opportunity lost"

 

Is this easily achievable ?

If any one can supply some basic coding for one /two of the stages above it would be truly appreciated

 

Many thanks

  • February 01, 2013
  • Like
  • 0

<->

Hey Guys

 

I am new to Apex coding so please be gentle

 

I need some help

 

Basically i have a huge backlog in my pipeline report, i thought of a way that i can overcome this but i am not sure its its viable

 

What i want to achieve is that is if the opportunity stage are any of the following

Qualified
Proposal
Application Docs Out
Application docs in (Complete)
Sent to Risk
Approved by Risk

 

and there has been no activity ( last modified date in the last 6months from todays date) then change the stage to "Opportunity lost"

 

Is this easily achievable ?

If any one can supply some basic coding for one /two of the stages above it would be truly appreciated

 

Many thanks

  • February 01, 2013
  • Like
  • 0
HI Guy

I have a problem and i am hoping you will be able to advise me of the best solution
I have three fields “FDGL Lease Term, FDGL Monthly Terminal Payment, FDGL Equipment”. From these fields i am trying to populate a field called “FDGL Commission”
i have created a formula which “is below” Which works perfectly fine, however there are 300 different combinations of the formula, and i know that i have a maximum character length of 5000 per formula field, and the formula below is 170 characters long in length
 
How can i get all the different combinations into a formula field ? someone has suggested using APEX , but i never experimented with this before.
Has anyone got any ideas, or sample coding , which will can point me in the correct direction
 
VALUE(IF(AND(ISPICKVAL( FDGL_Lease_Term__c ,"24"),ISPICKVAL( FDGL_Monthly_Terminal_Payment__c , "21.95"), ISPICKVAL( FDGL_Equipment__c, "930BCC Contactless")),"300", ""))
  • January 31, 2013
  • Like
  • 0

 

Hey All 

 

hope is well, i need some advice / pointers

 

I understand that with the new 14 release we can create triggers on the user object (not sure if this is the case)

 

Aim - In this example https://www.youtube.com/watch?v=QrtVN8vZGJU you can see that “Jim Smith” is going through the  de-activation process . What i want to do, is when you press save, an apex trigger  is triggered and automatically re-assigns “Jim Smith” Leads into this appropriate manager

 

Looking around, It shouldn't be an issue to grab the users's id, and the manager id and change ownership of those leads to the new user, but i may be mistaken and i need some help.

 

The Main issues that potentally could stop this from working is 

 

1.  If there isn't a manager listed you could not assign.

2.  If the manager is also inactive you will not be able to assign the leads (you can only assign records to active users).

3.  If any of the leads have not been edited by the current user and there is validation on the lead that hasn't been completed then the lead will not get reassigned.

  • October 08, 2013
  • Like
  • 0

Hey All

just a quick question

Aim – User  is leaving the organisation, so i need to deactivate the user, before de-activating i want to assign all his records example leads & opportunities to his manager .

I want to achieve all this via code instead of using the data loader.

Is this viable ? 

  • September 20, 2013
  • Like
  • 0

 

Hi guys 

 

I need some help I have created the following apex trigger below, However the trigger currently looks at exact matches on the company name


Is there any way that i could incorporate some kind of wildcard, so the search isn’t exact ?

 

From reading the forums, it looks like i need to go along the lines of "

 

String myValue = '%' + s + '%'
List<Lead> = new List<Lead>([Select Id, companyName from leads where customField like :myvalue]);
 
Can anyone point me in the correct direction ?
 
 

Trigger DuplicateLeadPreventer on Lead

                               (before insert, before update) {

//Get map of record types we care about from Custom Setting

 Map<String, Manage_Lead_Dupes_C__c> leadrtmap = Manage_Lead_Dupes_C__c.getAll();

//Since only certain leads will match, put them in a separate list

 List<Lead> LeadstoProcess = new List<Lead> ();

 

 //Company to Lead Map

 Map<String, Lead> leadMap = new Map<String, Lead>();

     for (Lead lead : Trigger.new) {

  

     //Only process for Leads in our RecordTypeMap

         if (leadrtmap.keyset().contains(lead.RecordTypeId) ) {

                    

        // Make sure we don't treat an Company name that

       // isn't changing during an update as a duplicate.

  

              if (

                 (lead.company != null) &&

                 (Trigger.isInsert ||

                 (lead.company != Trigger.oldMap.get(lead.Id).company))

                 )

                 {

                                      

                    // Make sure another new lead isn't also a duplicate

          

                        if (leadMap.containsKey(lead.company)) {

                            lead.company.addError('Another new lead has the '

                                            + 'same company name.');

                        } else {

                            leadMap.put(lead.company , lead);

                            LeadstoProcess.add(lead);

                        }

                }

    } //end RT If Check

    } //End Loop

              

    /*

     Using a single database query, find all the leads in

     the database that have the same company address as any

     of the leads being inserted or updated.

  

   */

  

    Set<String> ExistingCompanies = new Set<String> ();

 

            for (Lead l: [Select Id, Company from Lead WHERE Company IN :leadMap.keyset()

                             AND RecordTypeId IN :leadrtmap.keyset()]) {

                          ExistingCompanies.add(l.Company);

                }

 

    //Now loop through leads to process, since we should only loop if matches

    for (Lead l : LeadstoProcess) {

        if (ExistingCompanies.contains(l.company) ) {

             l.company.addError('A lead with this company '

                               + 'name already exists.');

        }

    }

}

  • April 16, 2013
  • Like
  • 0

Hey Guys

I need some help

 

I have built the following apex trigger ( See below) however i need to apply the company search on a certain records types.

The Record types in question are  “FDMS Lead Generation  &  FDMS Sales Lead”, where do i add this into the code?

My apex trigger is


Trigger DuplicateLeadPreventer on Lead

                               (before insert, before update) {

 

    Map<String, Lead> leadMap = new Map<String, Lead>();

    for (Lead lead : System.Trigger.new) {

                               

        // Make sure we don't treat an Company name that 

       // isn't changing during an update as a duplicate. 

   

  if ((lead.company != null) &&

                (System.Trigger.isInsert ||

                (lead.company !=

                    System.Trigger.oldMap.get(lead.Id).company))) {

                               

            // Make sure another new lead isn't also a duplicate 

   

            if (leadMap.containsKey(lead.company)) {

                lead.company.addError('Another new lead has the '

                                    + 'same company name.');

            } else {

                leadMap.put(lead.company , lead);

            }

       }

    }

               

    // Using a single database query, find all the leads in 

   

    // the database that have the same company address as any 

   

    // of the leads being inserted or updated. 

   

    for (Lead lead : [SELECT company FROM Lead

                      WHERE company IN :leadMap.KeySet()]) {

        Lead newLead = leadMap.get(lead.company);

        newLead.company.addError('A lead with this company '

                               + 'name already exists.');

    }

}
  

  • April 11, 2013
  • Like
  • 0

HI

Guys i am new to apex class so my apologises if i am using the incorrect terminology

 

Aim : Preventing Duplicate Records from Saving


after hours of research i have found an apex code which i think could meet my criteria if the code is adapted.

 

Concept-

Already existing lead in database
Company Name : Test LTD
postcode : SS34EN

 

Trying to add new lead into database
Company name : Test Limited
postcode : SS34EN

apex class would look at the company name and postcode and apply some fuzzy logic, and if it sees that the new lead is already the same as the existing lead  then don’t allow the new lead to be saved onto the database.
I want this to be applied to leads being manually entered and also on a bulk insert

The apex code i have found is , from the code below, does my idea seem viable ?

 

public class leadDupePreventerTests{

        static testMethod void testLeadDupPreventer() {

              

      // First make sure there are no leads already in the system

      // that have the email addresses used for testing

      Set<String> testEmailAddress = new Set<String>();

      testEmailAddress.add('test1@duptest.com');

      testEmailAddress.add('test2@duptest.com');

      testEmailAddress.add('test3@duptest.com');

      testEmailAddress.add('test4@duptest.com');

      testEmailAddress.add('test5@duptest.com');

      System.assert([SELECT count() FROM Lead

                     WHERE Email IN :testEmailAddress] == 0);

              

      // Seed the database with some leads, and make sure they can

      // be bulk inserted successfully.

      Lead lead1 = new Lead(LastName='Test1', Company='Test1 Inc.',

                            Email='test1@duptest.com');

      Lead lead2 = new Lead(LastName='Test2', Company='Test2 Inc.',

                            Email='test4@duptest.com');

      Lead lead3 = new Lead(LastName='Test3', Company='Test3 Inc.',

                            Email='test5@duptest.com');

      Lead[] leads = new Lead[] {lead1, lead2, lead3};

      insert leads;

              

      // Now make sure that some of these leads can be changed and

      // then bulk updated successfully. Note that lead1 is not

      // being changed, but is still being passed to the update

      // call. This should be OK.

      lead2.Email = 'test2@duptest.com';

      lead3.Email = 'test3@duptest.com';

      update leads;

              

      // Make sure that single row lead duplication prevention works

      // on insert.

      Lead dup1 = new Lead(LastName='Test1Dup',

                           Company='Test1Dup Inc.',

                           Email='test1@duptest.com');

      try {

         insert dup1;

         System.assert(false);

      } catch (DmlException e) {

         System.assert(e.getNumDml() == 1);

         System.assert(e.getDmlIndex(0) == 0);

         System.assert(e.getDmlFields(0).size() == 1);

         System.assert(e.getDmlFields(0)[0] == 'Email');

         System.assert(e.getDmlMessage(0).indexOf(

            'A lead with this email address already exists.') > -1);

      }

              

      // Make sure that single row lead duplication prevention works

      // on update.

      dup1 = new Lead(Id = lead1.Id, LastName='Test1Dup',

                      Company='Test1Dup Inc.',

                      Email='test2@duptest.com');

      try {

         update dup1;

         System.assert(false);

      } catch (DmlException e) {

         System.assert(e.getNumDml() == 1);

         System.assert(e.getDmlIndex(0) == 0);

         System.assert(e.getDmlFields(0).size() == 1);

         System.assert(e.getDmlFields(0)[0] == 'Email');

         System.assert(e.getDmlMessage(0).indexOf(

            'A lead with this email address already exists.') > -1);

            }

       

      // Make sure that bulk lead duplication prevention works on

      // insert. Note that the first item being inserted is fine,

      // but the second and third items are duplicates. Note also

      // that since at least one record insert fails, the entire

      // transaction will be rolled back.

      dup1 = new Lead(LastName='Test1Dup', Company='Test1Dup Inc.',

                      Email='test4@duptest.com');

      Lead dup2 = new Lead(LastName='Test2Dup',

                           Company='Test2Dup Inc.',

                           Email='test2@duptest.com');

      Lead dup3 = new Lead(LastName='Test3Dup',

                           Company='Test3Dup Inc.',

                           Email='test3@duptest.com');

      Lead[] dups = new Lead[] {dup1, dup2, dup3};

      try {

         insert dups;

         System.assert(false);

      } catch (DmlException e) {

         System.assert(e.getNumDml() == 2);

         System.assert(e.getDmlIndex(0) == 1);

         System.assert(e.getDmlFields(0).size() == 1);

         System.assert(e.getDmlFields(0)[0] == 'Email');

         System.assert(e.getDmlMessage(0).indexOf(

            'A lead with this email address already exists.') > -1);

         System.assert(e.getDmlIndex(1) == 2);

         System.assert(e.getDmlFields(1).size() == 1);

         System.assert(e.getDmlFields(1)[0] == 'Email');

         System.assert(e.getDmlMessage(1).indexOf(

            'A lead with this email address already exists.') > -1);

      }

       

      // Make sure that bulk lead duplication prevention works on

      // update. Note that the first item being updated is fine,

      // because the email address is new, and the second item is

      // also fine, but in this case it's because the email

      // address doesn't change. The third case is flagged as an

      // error because it is a duplicate of the email address of the

      // first lead's value in the database, even though that value

      // is changing in this same update call. It would be an

      // interesting exercise to rewrite the trigger to allow this

      // case. Note also that since at least one record update

      // fails, the entire transaction will be rolled back.

      dup1 = new Lead(Id=lead1.Id, Email='test4@duptest.com');

      dup2 = new Lead(Id=lead2.Id, Email='test2@duptest.com');

      dup3 = new Lead(Id=lead3.Id, Email='test1@duptest.com');

      dups = new Lead[] {dup1, dup2, dup3};

      try {

         update dups;

         System.assert(false);

      } catch (DmlException e) {

         System.debug(e.getNumDml());

         System.debug(e.getDmlMessage(0));

         System.assert(e.getNumDml() == 1);

         System.assert(e.getDmlIndex(0) == 2);

         System.assert(e.getDmlFields(0).size() == 1);

         System.assert(e.getDmlFields(0)[0] == 'Email');

         System.assert(e.getDmlMessage(0).indexOf(

            'A lead with this email address already exists.') > -1);

            }

              

      // Make sure that duplicates in the submission are caught when

      // inserting leads. Note that this test also catches an

      // attempt to insert a lead where there is an existing

      // duplicate.

      dup1 = new Lead(LastName='Test1Dup', Company='Test1Dup Inc.',

                      Email='test4@duptest.com');

      dup2 = new Lead(LastName='Test2Dup', Company='Test2Dup Inc.',

                      Email='test4@duptest.com');

      dup3 = new Lead(LastName='Test3Dup', Company='Test3Dup Inc.',

                      Email='test3@duptest.com');

      dups = new Lead[] {dup1, dup2, dup3};

      try {

         insert dups;

         System.assert(false);

      } catch (DmlException e) {

         System.assert(e.getNumDml() == 2);

         System.assert(e.getDmlIndex(0) == 1);

         System.assert(e.getDmlFields(0).size() == 1);

         System.assert(e.getDmlFields(0)[0] == 'Email');

         System.assert(e.getDmlMessage(0).indexOf(

            'Another new lead has the same email address.') > -1);

         System.assert(e.getDmlIndex(1) == 2);

         System.assert(e.getDmlFields(1).size() == 1);

         System.assert(e.getDmlFields(1)[0] == 'Email');

         System.assert(e.getDmlMessage(1).indexOf(

            'A lead with this email address already exists.') > -1);

      }

              

      // Make sure that duplicates in the submission are caught when

      // updating leads. Note that this test also catches an attempt

      // to update a lead where there is an existing duplicate.

      dup1 = new Lead(Id=lead1.Id, Email='test4@duptest.com');

      dup2 = new Lead(Id=lead2.Id, Email='test4@duptest.com');

      dup3 = new Lead(Id=lead3.Id, Email='test2@duptest.com');

      dups = new Lead[] {dup1, dup2, dup3};

      try {

         update dups;

         System.assert(false);

      } catch (DmlException e) {

         System.assert(e.getNumDml() == 2);

         System.assert(e.getDmlIndex(0) == 1);

         System.assert(e.getDmlFields(0).size() == 1);

         System.assert(e.getDmlFields(0)[0] == 'Email');

         System.assert(e.getDmlMessage(0).indexOf(

            'Another new lead has the same email address.') > -1);

         System.assert(e.getDmlIndex(1) == 2);

         System.assert(e.getDmlFields(1).size() == 1);

         System.assert(e.getDmlFields(1)[0] == 'Email');

         System.assert(e.getDmlMessage(1).indexOf(

            'A lead with this email address already exists.') > -1);

      }

   }

}

 




 

 

  • April 11, 2013
  • Like
  • 0
HI Guy

I have a problem and i am hoping you will be able to advise me of the best solution
I have three fields “FDGL Lease Term, FDGL Monthly Terminal Payment, FDGL Equipment”. From these fields i am trying to populate a field called “FDGL Commission”
i have created a formula which “is below” Which works perfectly fine, however there are 300 different combinations of the formula, and i know that i have a maximum character length of 5000 per formula field, and the formula below is 170 characters long in length
 
How can i get all the different combinations into a formula field ? someone has suggested using APEX , but i never experimented with this before.
Has anyone got any ideas, or sample coding , which will can point me in the correct direction
 
VALUE(IF(AND(ISPICKVAL( FDGL_Lease_Term__c ,"24"),ISPICKVAL( FDGL_Monthly_Terminal_Payment__c , "21.95"), ISPICKVAL( FDGL_Equipment__c, "930BCC Contactless")),"300", ""))
  • January 31, 2013
  • Like
  • 0