• arnt72
  • NEWBIE
  • 50 Points
  • Member since 2008

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 22
    Replies
Hi all,

I have a set up where Object A is a parent of Object B. There is a trigger on delete of an Object B record to delete a record of type Object C related to the Object B record being deleted (ideally, Object C would be a child of B, but we can't do this unfortunately).

So: A is a parent of B, C is related to B but not via a parent/child relationship. And a trigger on B deletes the relevant C object when B is deleted.

If we delete a record of type A, it will delete B (because of the parent/child relationship) and - what I would expect anyway - the trigger on B will delete the relevant C object.

Except that it doesn't. Should it? I opened a clean developer account, put a trigger on B that just prints a debug statement, created the relevant data, deleted A and - nothing in the log.

FWIW, A is the standard Account object, B is the standard Event object, and C is a custom object we've developed.

Thanks in advance for your help!
  • October 29, 2008
  • Like
  • 0
I am getting a NullPointerException: Attempt to de-reference a null object error on the following trigger code:
 
Code:
trigger ImportMDRDataTrigger on Lead (before update) {
 
 Lead[] leadList = [Select Id, MDR_Account__r.Enrollment__c, MDR_Account__r.MDR_School_I_D__c, MDR_Account__r.MDR_District_I_D__c from Lead WHERE MDR_Account__c != null and Id in :Trigger.new];

 Map<Id, Lead> leadMap = new Map<Id, Lead>(leadList);
 
 for (Lead l : Trigger.new) {
  if (l.MDR_Account__c == null)       
  continue;
  Lead the_lead = leadMap.get(l.Id);
     l.Enrollment__c = the_lead.MDR_Account__r.Enrollment__c;
     l.MDR_District_PID__c = the_lead.MDR_Account__r.MDR_District_I_D__c;
     l.MDR_School_PID__c = the_lead.MDR_Account__r.MDR_School_I_D__c;
  }
}

 
The trigger works if the MDR_Account__c field in the lead object is already populated and I run the update.  However, if I edit the lead and do the lookup on the MDR_Account__c field, the NullPointerException error is thrown.
 
Thanks for any help.
Hi all,

I have a set up where Object A is a parent of Object B. There is a trigger on delete of an Object B record to delete a record of type Object C related to the Object B record being deleted (ideally, Object C would be a child of B, but we can't do this unfortunately).

So: A is a parent of B, C is related to B but not via a parent/child relationship. And a trigger on B deletes the relevant C object when B is deleted.

If we delete a record of type A, it will delete B (because of the parent/child relationship) and - what I would expect anyway - the trigger on B will delete the relevant C object.

Except that it doesn't. Should it? I opened a clean developer account, put a trigger on B that just prints a debug statement, created the relevant data, deleted A and - nothing in the log.

FWIW, A is the standard Account object, B is the standard Event object, and C is a custom object we've developed.

Thanks in advance for your help!
  • October 29, 2008
  • Like
  • 0
Does anyone know the syntax to access a lookup data type in a trigger. I am trying to grab a Contact Id from a trigger that is created on a Contract insert.  Here is is the code:

trigger emailConfirm on Contract (after insert) {
Contract[] newContract = Trigger.new;
Id templateId= '00X401200012BvE';
Id targetId = newContract[0].CustomerSigned
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setSubject('contract confirm');
mail.setTemplateId(templateId);
mail.setTargetObjectId(targetId);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}

This does not work. I can grab any fields that are not of data type lookup though. For example newContract[0].ContractNumber works just fine.

I also tried the following with no success:

newContract[0].CustomerSigned.Id
newContract[0].CustomerSigned[0].Id


Any help is greatly appreciated.

PB
  • October 16, 2008
  • Like
  • 0
Hi all:
   I do not know where am I going wrong but I keep getting errors rarely but do get errors on this trigger i wrote 3 times already...
Code:
trigger tsk on Task (before insert,before update) {
    for(Task cs : trigger.new){ 
    Account[] acc = [select Id,
                    AccountNumber,
                    Territory__c from 
                    Account where 
                    Id = :cs.WhatId];
     Opportunity[] opp = [Select a.Id, 
                      a.AccountId 
                      From Opportunity a where
                      Id=:cs.WhatId]; 
     Case[] ca = [Select c.Id,c.AccountId
               from Case c where
               Id=:cs.WhatId];                                                       
    if (acc.isEmpty()){
        if(opp.isEmpty())
        {            
           Account actx = [Select Id,
                        AccountNumber,
                        Territory__c from 
                        Account where 
                        Id =:ca[0].AccountId];
           cs.Dealer_ID__c = actx.AccountNumber;
           cs.Territory__c = actx.Territory__c;  
         }
          if(ca.isEmpty())
          {          
            Account act = [Select Id,
                        AccountNumber,
                        Territory__c from 
                        Account where 
                        Id = :opp[0].AccountId];                                                         
             cs.Dealer_ID__c = act.AccountNumber;
             cs.Territory__c = act.Territory__c;
         } 
    }
    else if(cs.WhatId != null)
    {
    cs.Dealer_ID__c = acc[0].AccountNumber;
    cs.Territory__c = acc[0].Territory__c;
    }
    }
}

 Please let me know where am I going wrong...So far this is the new error:
Developer script exception from tsk : tsk: execution of BeforeInsert caused by: System.ListException: List index out of bounds: 0 Trigger.tsk: line 22, column 34
Thanks


Need to build a workflow rule to trigger when opportunities owned by certain users (all a part of the same role) meet a certain criteria (close date is within 3 days of today).

I have all figured out execpt for how to tell the system to look for these users.

Any/all help appreciated.
Hi we are a developer team using force.com unlimited edition,right now we got a problem working with eclipse and code sharing .we are using sandbox every developer was using a admin account for development flexibility and ,we got problem because availability of permission to all the person in the team creating issues ,code changes hipping with out knowledge of other person and if a new developer joined some environment issues coming when using eclipse.
 
for resolve this type of issues ,any code shareing tool is supported bye force.com platform and any good documetaion or blog thats would great we are geting trouble working with eclipse.
  • October 13, 2008
  • Like
  • 0
I have two custom objects (SFDC_Employee__c Promotion__c). I need to update field Unit__c (text) in object SFDC_Employee__c when sombody add or change field Unit__c (Picklist) in object Promotions__c.

I made trigger in object Promotions__c with this code:

Code:
trigger Unit_update on Promotions__c (after insert, after update) {

sObject s = [SELECT Unit__c FROM SFDC_Employee__c LIMIT 1];

s.Unit__c = 'sdfsfsdf';

update s;

}


But this trigger doesn't work. Can you please explane what is the better way to fix my problem.
Hello!  I'm trying to bulk trigger the following query:

for(Case TLnew : Trigger.new) {

High = TLnew.Value__c + 10;
Low = TLnew.Value__c -10 ;

Integer i = [SELECT count() FROM Case x WHERE x.Party1__c = :TLnew.Party1__c  AND x.Party2__c = :TLnew.Party2__c AND x.Value__c <= :High AND x.Value__c >= :Low AND ID != :TLnew.ID ];

TLnew.Similar__c = i;

}

Basically I want to return the number of cases that are similar to the triggering case and update that trigger's Similar__c with that number.  This includes cases with the same party values and within a +/- 10 range of a number.

The following works fine above, but obviously the SOQL is written into the loop.  I can't figure out how to bulk the trigger; I tried storing all the trigger objects in a map, but I can't determine how to iterate over it with the above query conditions.  I could store all the trigger variables in a set, but then I lose the 'AND' conditional link between objects.

Is there a solution to the above?
  • October 12, 2008
  • Like
  • 0
I have an apex class that is set up mass update contact records. It spools through and updates some custom indexes that we use.

Currently it uses a a for loop to spool through and update contact 1k at a time. I am getting a governor warning :

Number of query rows: 9300 out of 10000
Number of DML rows: 9291 out of 10000

Is there a work around to updating more then 10k records via a class? I have it attached to a campaign button to update contacts from a current campaign and it is likely that we will have more then 10k.

  • October 12, 2008
  • Like
  • 0
Hi,
We have enabled Territory Management in our Org. We are experiencing a strange Data accessibility.We had given View access in our Territory structure for all Accounts. Two specific Users, are having Read/write access to the Opportunies which are shared in Read only mode.
The reason displayed in the Sharing section of Opportunity Record was "Opportunity Territory Manager". 
But these two Users are not the Managers of any one in the Role hierarchy. And in Territories, the data sharing is View only. How to overcome this,so that they can only view or where might be the fault. Any pointers would help.
 
 
UG
  • October 11, 2008
  • Like
  • 0
Hi

I am trying to validate that the BillingCountry field matches our specifications. I thought the best way to do this would be to create a validation rule that did a vlookup on a custom object which had a list of the correct countries. The problem is I can't figure out how to create the custom object properly. Thanks in advance for the help. 
I am getting a NullPointerException: Attempt to de-reference a null object error on the following trigger code:
 
Code:
trigger ImportMDRDataTrigger on Lead (before update) {
 
 Lead[] leadList = [Select Id, MDR_Account__r.Enrollment__c, MDR_Account__r.MDR_School_I_D__c, MDR_Account__r.MDR_District_I_D__c from Lead WHERE MDR_Account__c != null and Id in :Trigger.new];

 Map<Id, Lead> leadMap = new Map<Id, Lead>(leadList);
 
 for (Lead l : Trigger.new) {
  if (l.MDR_Account__c == null)       
  continue;
  Lead the_lead = leadMap.get(l.Id);
     l.Enrollment__c = the_lead.MDR_Account__r.Enrollment__c;
     l.MDR_District_PID__c = the_lead.MDR_Account__r.MDR_District_I_D__c;
     l.MDR_School_PID__c = the_lead.MDR_Account__r.MDR_School_I_D__c;
  }
}

 
The trigger works if the MDR_Account__c field in the lead object is already populated and I run the update.  However, if I edit the lead and do the lookup on the MDR_Account__c field, the NullPointerException error is thrown.
 
Thanks for any help.
hi All,

I will like to create a new lookup field in the task Object. I know that for creating new custom fields I have to go to Activities custom fields in the menu bar. However, I don't have the option to create a lookup field.

My problem is that I would like to add to the task views a new field (Account Number) from the Lead/Contact related to the task. I don't know a priori if the task will be related to a Lead or Contact.

Any Ideas?

Many Thanks!
  • October 10, 2008
  • Like
  • 0
I'm creating a trigger on a lead to auto-populate several fields when the lead is updated based on a lookup field to a custom object.
 
I've tried both a before update and after update trigger.
 
Here is the trigger code:
 
Code:
trigger ImportMDRDataTrigger on Lead (after update) {
 
 Lead[] leadList = [Select Id, MDR_Account__r.Enrollment__c, MDR_Account__r.MDR_School_I_D__c, MDR_Account__r.MDR_District_I_D__c from Lead WHERE MDR_Account__c != null and Id in :Trigger.new];
 
 List<Lead> leadsToUpdate = new List<Lead>();
 
 for (Lead l : leadList) {
     l.Enrollment__c = l.MDR_Account__r.Enrollment__c;
     l.MDR_District_PID__c = l.MDR_Account__r.MDR_District_I_D__c;
     l.MDR_School_PID__c = l.MDR_Account__r.MDR_School_I_D__c;
     leadsToUpdate.add(l);
  }
  update (leadsToUpdate);

}

 
Here is the error I get when using a before update trigger:
 
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger ImportMDRDataTrigger caused an unexpected exception, contact your administrator: ImportMDRDataTrigger: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 00Q7000000NibUREAZ; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 00Q7000000NibUR) is currently being updated in trigger ImportMDRDataTrigger: [Id]: Trigger.ImportMDRDataTrigger: line 13, column 5
 
Here is the error I get when using an after update trigger:
 
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger ImportMDRDataTrigger caused an unexpected exception, contact your administrator: ImportMDRDataTrigger: maximum trigger depth exceeded Lead trigger event AfterUpdate for 00Q7000000NibUR Lead trigger event AfterUpdate for 00Q7000000NibUR Lead trigger event AfterUpdate for 00Q7000000NibUR Lead trigger event AfterUpdate for 00Q7000000NibUR Lead trigger event AfterUpdate for 00Q7000000NibUR Lead trigger event AfterUpdate for 00Q7000000NibUR Lead trigger event AfterUpdate for 00Q7000000NibUR Lead trigger event AfterUpdate for 00Q7000000NibUR Lead trigger event AfterUpdate for 00Q7000000NibUR Lead trigger event AfterUpdate for 00Q7000000NibUR Lead trigger event AfterUpdate for 00Q7000000NibUR Lead trigger event AfterUpdate for 00Q7000000NibUR Lead trigger event AfterUpdate for 00Q7000000NibUR Lead trigger event AfterUpdate for 00Q7000000NibUR Lead trigger event AfterUpdate for 00Q7000000NibUR Lead trigger event AfterUpdate for 00Q7000000NibUR
 
Any help is appreciated.
Thank you.
Hi,

I need to update the Owner Id of a Contact each time it is inserted/updated. The Owner Id for Contacts is assigne to each Contact based in some criterias.  That is why I was thinking to use workflow rules, however I couldn't find any lookup fields in the list when I chose to update a field in the workflow action options. I really need to update Owner Id for each contact based in custom fields values... Is there any other way to do it if this one is not possible???

Any help?

many thanks!
  • October 09, 2008
  • Like
  • 0
I just started using the sforce connector to build queris for a customized opportunity report in excel. All queries were working fine until excel crashed on me. When I go back into excel to re-run the queries, I'm get an error that states:
 
Error Generated by request::
from OpportunityLineItem where Service Date >2008-08-01TO0:00:00.00Z
 
ERROR at Row:1:Column:43
value of filter criterion for field 'service date' must be of type date and should not be enclosed with quotes????
Exception code: 5077
 
Then I would get the error: No data returned for this query.
 
I've changed the date format and I still get this error. I dont know what is causing this. Has anyone had this same issue? Can anyone help me please? :smileysad:
This might be a dumb question, but for some reason I can't get the system log to return any information.  I've got the window open set to Apex Code/Debug, and I know my triggers are executing because I've got field updates.  But the system log remains silent, despite multiple System.debug calls.  This worked just fine last week, no idea why it's not now.  I made a couple minor edits to a trigger but that's it.  I did purposely create an error and that came back in the UI fine, futher verifying that the trigger is firing and is calling my apex class.  Field updates with my "debug" messages work and place the messages into the field, so it's definitely stepping through all the code.

I'm running Firefox 2.0.0.11 and Eclipse 3.3.1.1 with the latest Force.com IDE, on MacOSX 10.4.11.  I just cleared out the cache, reloaded and still nothing.  There's probably a really easy answer here, but what is it?

Mark