• littledevil
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies

Ok I was able to get this up to 105 in my batch test method insert for contact. When I do 200, it gets thits error. Any ideas how I can reduce the statements?

trigger ContactAutomationTrigger on Contact (before insert, before update)
{
Set<Id> aSet = new Set<Id>();
Set<Id> aRecordTypeSet = new Set<Id>();
List<Contact> cNewList= Trigger.new;
for(Contact c: cNewList)
{
aSet.add(c.AccountId);
aRecordTypeSet.add(c.RecordTypeId);
}
ContactUtilities.RegionAssign(cNewList, aSet);

   for(Contact c: cNewList)

        {

        aSet.add(c.AccountId);  

        cRTset.add(c.RecordTypeId);

            

        }

        ContactUtilities.RegionAssign(cNewList, aSet, cRTSet); 

   

}

 

 

 public static void Region Assign(List<Contact> cList, Set<Id> aSet, Set<Id> cRTSetId)

    {         

            Map<Id, RecordType> rtMap = new Map<Id, RecordType>();      

            List<String> aList =new List<String>();       

            Map<Id, Account> aMap = new Map<Id, Account>([SELECT Id, channel__c, status__c FROM Account WHERE id =: aSet]);

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

 

           for(RecordType rt : [Select Name From RecordType Where ID IN :cRTSetId])  

          {

           cRTSetName.add(rt.name);

           }

 

            rtMap = New Map<ID,RecordType>([Select ID From RecordType Where sObjectType = 'Region__c' and Name IN     

                          :cRTSetName]);

 

            List<Region__c> tList = [select id, zip_start__c, zip_end__c, state__c,Sales_Rep__c, channel__c, recordTypeId from   

                                                        Region__c whereSales_Rep__c != null AND RecordTypeID IN :rtMap.keySet()];      

                                 

            for(Contact c:cList) 

            {

             try 

              {

                for(integer i= 0; i< rList.size(); i++)

                {

                 String mailingPostalCode= String.valueOf(c.mailingPostalCode);

                    if(c.mailingstate== rList.get(i).state__c  && aMap.get(c.accountId).channel__c == rList.get(i).channel__c &&

                       aMap.get(c.accountId).status__c=='Active' )

                    {    

                        if(c.mailingPostalCode >= tList.get(i).zip_start__c && c.mailingPostalCode<=rList.get(i).zip_end__c  ||

                          rList.get(i).zip_start__c ==null  && rList.get(i).zip_end__c ==null)

                        {

                            c.Region__c = rList.get(i).id;

                            c.OwnerId = rList.get(i).Sales_Rep__c;

                        }

                    } 

Hello Apex experts!

 

I need to be able to get the link of an attachment and download the file to a diffrent server. On the record that has the attachment, I need to have a button that triggers this.

 

Is there some way to loop all the attachments in the record?

 

 

Thanks,
David

Hi, Can anyone post a sample code for executing the test method for approval Process.My actual requirement is Whenever a record is created and a particular field is updated it goes for the manager approval.So first i want to create a record and i should unlock the record from approval process and then edit it. Mainly i need the code to achieve the approval process where the record should be approved in the test method. Thanks in Advance!!
  • December 26, 2012
  • Like
  • 0

Ok I was able to get this up to 105 in my batch test method insert for contact. When I do 200, it gets thits error. Any ideas how I can reduce the statements?

trigger ContactAutomationTrigger on Contact (before insert, before update)
{
Set<Id> aSet = new Set<Id>();
Set<Id> aRecordTypeSet = new Set<Id>();
List<Contact> cNewList= Trigger.new;
for(Contact c: cNewList)
{
aSet.add(c.AccountId);
aRecordTypeSet.add(c.RecordTypeId);
}
ContactUtilities.RegionAssign(cNewList, aSet);

   for(Contact c: cNewList)

        {

        aSet.add(c.AccountId);  

        cRTset.add(c.RecordTypeId);

            

        }

        ContactUtilities.RegionAssign(cNewList, aSet, cRTSet); 

   

}

 

 

 public static void Region Assign(List<Contact> cList, Set<Id> aSet, Set<Id> cRTSetId)

    {         

            Map<Id, RecordType> rtMap = new Map<Id, RecordType>();      

            List<String> aList =new List<String>();       

            Map<Id, Account> aMap = new Map<Id, Account>([SELECT Id, channel__c, status__c FROM Account WHERE id =: aSet]);

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

 

           for(RecordType rt : [Select Name From RecordType Where ID IN :cRTSetId])  

          {

           cRTSetName.add(rt.name);

           }

 

            rtMap = New Map<ID,RecordType>([Select ID From RecordType Where sObjectType = 'Region__c' and Name IN     

                          :cRTSetName]);

 

            List<Region__c> tList = [select id, zip_start__c, zip_end__c, state__c,Sales_Rep__c, channel__c, recordTypeId from   

                                                        Region__c whereSales_Rep__c != null AND RecordTypeID IN :rtMap.keySet()];      

                                 

            for(Contact c:cList) 

            {

             try 

              {

                for(integer i= 0; i< rList.size(); i++)

                {

                 String mailingPostalCode= String.valueOf(c.mailingPostalCode);

                    if(c.mailingstate== rList.get(i).state__c  && aMap.get(c.accountId).channel__c == rList.get(i).channel__c &&

                       aMap.get(c.accountId).status__c=='Active' )

                    {    

                        if(c.mailingPostalCode >= tList.get(i).zip_start__c && c.mailingPostalCode<=rList.get(i).zip_end__c  ||

                          rList.get(i).zip_start__c ==null  && rList.get(i).zip_end__c ==null)

                        {

                            c.Region__c = rList.get(i).id;

                            c.OwnerId = rList.get(i).Sales_Rep__c;

                        }

                    }