• tdevman
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 27
    Replies

I have an Account before trigger and if a bulk account update happens, I don't want to exit out the entire batch but check each account record but i can't really use database method or could i???

here is a sample code stub and check out my add error method.  aList collection are records passed in from Trigger.new

 

       Map<id, Contact> cMap= new Map<id, Contact>();

        for (Contact c: cList){
            cMap.put(c.AccountId, c);
        }

        for (Account a: aList){
            if (cMap.containsKey(a.id)){
                 if( cMap.get(a.id).custom_field__c== null 
                    && cMap.get(a.id).custom_field__c==null ){
                    a.addError('missing contact info!);
                    }
            

there is before trigger that passes records to tlist in the method.  I tested all behaviors per sfdc best practices. 1 positive, 1 negative, batch insert(200 records). However when i insert 201 records. I get System.ListException: List index out of bounds: 200.  How come i get this on the 201st record? other then that, everything works fine....

 

This class is invoked by a before insert trigger on the ExpenseLineItems object. It's supposed to assign the sales_rep__c which is the contact.ownerid associated to expense.contact__c. But when I debug the following, the size is correct but the contents of the list if null. 

hey guys..I have a before insert trigger on a OrderLineItem__c object which is the detail object. The master is Order__c. When it fires it should populate the sales_rep__c with the ownerid associated to the order.contact__c field.  This works with 1 record but when i do a bulk insert with data loader I get this issue. if anyone can help i would really appreciate and mark as solution

OrderLineItemsTrigger: execution of BeforeInsert caused by: System.ListException: List index out of bounds: 1 Class.MyUtilities.SalesRepAssign: line 11, column 1 Trigger.OrderLineItemsrigger: line 11, column 1

 

If we were to create a vf dashboard from a external file system ..csv or .txt that contains a 1 million records, is there anyway to get passed the 1000 vf collection limit

the following is from the documentation. let's say the opportunty.name is an externalid (unique) and let's say i have .csv file called c:\oppcommisionpercent.csv  that has columns of  name, commissionpercent. The y axis of the dashboard should a calculate the commission amount which would be the opportunity.amount * commissionpercent  which basically multiplies the commission% with the opportunity amount.  I think this is possible passing a JSON array into the <apex:/chart> component.. .been playing around but any ideas would be great

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_charting_example.htm

 

public class OppsController {

// Get a set of Opportunities

public ApexPages.StandardSetController setCon {
get {
if(setCon == null) {
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
[SELECT name, type, amount, closedate FROM Opportunity]));
setCon.setPageSize(5);
}
return setCon;
}
set;
}

public List<Opportunity> getOpportunities() {
return (List<Opportunity>) setCon.getRecords();
}
}

<apex:page controller="OppsController">
<apex:chart data="{!Opportunities}" width="600" height="400">
<apex:axis type="Category" position="left" fields="Name" title="Opportunities"/>
<apex:axis type="Numeric" position="bottom" fields="Amount" title="Amount"/>
<apex:barSeries orientation="horizontal" axis="bottom" xField="Name" yField="Amount"/>
</apex:chart>
<apex:dataTable value="{!Opportunities}" var="opp">
<apex:column headerValue="Opportunity" value="{!opp.name}"/>
<apex:column headerValue="Amount" value="{!opp.amount}"/>
</apex:dataTable>
</apex:page>

 

I have 2 record types on the task record. One called "Custom" and another called "Standard".  The default record type for all users is Standard. I created 2 formula fields (Custom and Standard)  that are images in the documents folder. Depending which is clicked, it should auto land on that page layout. It works for the standard but how can i make it for the custom?

 

How can I make this work?

 

Stanard(this works)

HYPERLINK('/00T/e?who_id='& Id & '&retURL=' & Id, IMAGE('/servlet/servlet.FileDownload?file=01540000000xKUQ', 'Standard)) 
& ' ' &

 

Custom(fails and says missing ')'

HYPERLINK('/00T/e?who_id='& Id & '&retURL=' & Id&RecordType=01240000000UWKG, IMAGE('/servlet/servlet.FileDownload?file=01540000000xKUB', 'Custom'))
& ' ' &

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;

                        }

                    } 

I have a before trigger that calls this class which auto assigns the region and the ownerid to the account based on the recordtype, state and zip of the region object. the region object holds all the assignments. It works great but when I execute a batch load through data laoder I hit too many script statements 200001 error. any way i can fix?

 

 

public with sharing class AccountUtilities
{
public static void acctAssign(List<Account> aList)
{
List<region__c> rList = [select id, zip_start__c, zip_end__c, state__c,sales_user__c, business_unit__c, recordTypeId from region__c];
Map<Id,RecordType> rtMap = new Map<Id,RecordType>([Select id,Name from RecordType where sObjectType IN ('Account','region__c')]);
for(Account a:aList)
{
try
{
for(integer i= 0; i< rList.size(); i++)
{
String billingPostalCode= String.valueOf(a.BillingPostalCode);
if(a.billingstate== rList.get(i).state__c && a.Protected__c != true && rtMap.get(a.recordtypeid).Name == rtMap.get(rList.get(i).recordtypeid).Name && a.business_unit__c == tList.get(i).business_unit__c)
{
if(a.billingPostalCode >= rList.get(i).zip_start__c && a.billingPostalCode<=rList.get(i).zip_end__c || rList.get(i).zip_start__c ==null && rList.get(i).zip_end__c ==null )
{
a.region__c = rList.get(i).id;
a.OwnerId = rList.get(i).sales_user__c;
}
}
}
}
catch (System.Exception e)
{
// process exception
}

}
}



the below class is invoked from before insert/update trigger.  This code stub was on another  thread. Any reason why when i hit this exception it can not be caught?

 

public static void AccountOptOutContUpdate(List<Account> aNewList, List<Account> aOldList)
{
Map<Id, Account> acctsMap= new Map<Id, Account>();
List<Contact> updatedContacts = new List<Contact>();
Account parentAccount = new Account();
 try
 {
for (Integer i = 0; i < Trigger.new.size(); i++)
{
if(aOldList.get(i).Do_Not_Call__c != aNewList.get(i).Do_Not_Call__c || aOldList.get(i).Email_Opt_Out__c != aNewList.get(i).Email_Opt_Out__c
|| aOldList.get(i).Fax_Opt_Out__c != aNewList.get(i).Fax_Opt_Out__c)
{
acctsMap.put(aOldList.get(i).Id, aNewList.get(i));
}
}
for (Contact c : [SELECT id, accountId, HasOptedOutOfFax, HasOptedOutOfEmail, DoNotCall FROM contact WHERE accountId in :acctsMap.keySet()])
{
if(c.DoNotCall ==false || c.HasOptedOutOfEmail == false || c.HasOptedOutOfFax == false)
{
parentAccount = acctsMap.get(c.accountId);
c.DoNotCall = parentAccount.Do_Not_Call__c;
c.HasOptedOutOfEmail = parentAccount.Email_Opt_Out__c;
c.HasOptedOutOfFax = parentAccount.Fax_Opt_Out__c;
updatedContacts.add(c);
}
}
update updatedContacts;
// }
/* catch(System.LimitException ex)
{
parentAccount.addError('unexpected error occur, please call your system admin!');
}

*/
}

As a best practice, i know that we need to gracefully recover from exceptions and one way is to handle the transaction is by creating a record in a custom log object.  However, after readung up, i think this will not work on a before insert/update since the transaction is rolled back completely which would prevent the error to be inserted into the object unless it;s an after insert/update.

 

 Is this true? Also if it is, what is a best way to handle exceptions associated with before insert/update triggers?

  • September 10, 2012
  • Like
  • 0
  • September 08, 2012
  • Like
  • 0

The before update trigger below passes trigger records  into the parentObjectMap. I am running various test methods and when i run my bulk tests to the parent object it says too many future calls.  I think my catch block is not bulified so every time there is more than 10 records that are bad , the future class is called to many time. how could i bulkify that? Eveything else works fine. basically, if the child items are incomplete i throw an error to the parent object

 

 

try{
    for(childObject: childObjectList){
      if(childObject.custom_field__c == null)

         parentObjectMap.get(childObject.ParentObjectId).addError('Incomplete child items');

      }
}

   if(test.isRunningTest())
   {
       throw new TestException('Exception');
    }
}

 

catch(Exception ex) {
FutureErrorlog.createExRec(ex.getMessage());
}
}

 

 

global class FutureErrorlog{
@future
public static void createExRec(string exceptionMessage){
Error_Log__c exceptionRec = new Error_Log__c(
Error_Message__c = exceptionMessage);
insert exceptionRec;
}
}

 

 

I have an Account before trigger and if a bulk account update happens, I don't want to exit out the entire batch but check each account record but i can't really use database method or could i???

here is a sample code stub and check out my add error method.  aList collection are records passed in from Trigger.new

 

       Map<id, Contact> cMap= new Map<id, Contact>();

        for (Contact c: cList){
            cMap.put(c.AccountId, c);
        }

        for (Account a: aList){
            if (cMap.containsKey(a.id)){
                 if( cMap.get(a.id).custom_field__c== null 
                    && cMap.get(a.id).custom_field__c==null ){
                    a.addError('missing contact info!);
                    }
            

there is before trigger that passes records to tlist in the method.  I tested all behaviors per sfdc best practices. 1 positive, 1 negative, batch insert(200 records). However when i insert 201 records. I get System.ListException: List index out of bounds: 200.  How come i get this on the 201st record? other then that, everything works fine....

 

This class is invoked by a before insert trigger on the ExpenseLineItems object. It's supposed to assign the sales_rep__c which is the contact.ownerid associated to expense.contact__c. But when I debug the following, the size is correct but the contents of the list if null. 

If we were to create a vf dashboard from a external file system ..csv or .txt that contains a 1 million records, is there anyway to get passed the 1000 vf collection limit

I have 2 record types on the task record. One called "Custom" and another called "Standard".  The default record type for all users is Standard. I created 2 formula fields (Custom and Standard)  that are images in the documents folder. Depending which is clicked, it should auto land on that page layout. It works for the standard but how can i make it for the custom?

 

How can I make this work?

 

Stanard(this works)

HYPERLINK('/00T/e?who_id='& Id & '&retURL=' & Id, IMAGE('/servlet/servlet.FileDownload?file=01540000000xKUQ', 'Standard)) 
& ' ' &

 

Custom(fails and says missing ')'

HYPERLINK('/00T/e?who_id='& Id & '&retURL=' & Id&RecordType=01240000000UWKG, IMAGE('/servlet/servlet.FileDownload?file=01540000000xKUB', 'Custom'))
& ' ' &