• pjaenicke
  • NEWBIE
  • 25 Points
  • Member since 2009

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

Greetings,

 

Just was pondering the best method to suppress all alerts during a mass update operation, (when desired to suppress, that is).

 

Perhaps via a hidden field that you update during such a mass update, and every alert workflow would key off of?  (Would need to be cleared though too then, post update).

 

Anyone have a successful strategy / best practice recommendation?

 

Thanks,

Pete

 

 

Greetings,

 

Been pulling out my hair on this one - have a fully functional class/trigger set that performs the following:

 

Have a "Reports To" and "Reporting VP" lookup fields on the User record.  For every Account record I want to have three AccountTeamMembers created, or updated when the Account Owner changes, or if their report to structure should change:

 

"Sales Rep" (Oppy Owner)

"Sales Manager" (Oppy Owner's Report To) and

"Sales Director" (Oppy Owner's Reporting VP)

 

Again, the trigger and class are working - I'm struggling with the Test Class.  There are three entry points:

1.  Account creation - (create the three AccountTeamMembers)

2.  Account owner change - (replace the three AccountTeamMembers)

3.  User Manager / VP change - (replace the Manager / Director AccountTeamMembers)

 

Here's the error message / Stack Trace:

 

Message:

System.DmlException: Update failed. First exception on row 0 with id 005Q0000000LTK4IAO; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): User, original object: Account: []

 

Stack Trace:

Class.TestAccountTeamMemberUpdates.testAccountModelATMAssignmentMethods: line 140, column 13 External entry point

 

I will post my test class in the next message.  Thanks for any guidance / assistance!

 

Pete

Greetings !

 

Wondering how to solve what I think is just a timing issue..

 

I have an "After Update" trigger that inserts records into a child object.

 

Seems to work fine when run and inspected by human eyes, however, in my test class, I think I'm running into an issue where my "after update" hasn't quite finished yet. 

 

How can I ensure the trigger has finished processing before my "assertEquals" checks in my test class?

 

Thanks,

Pete

 

Greetings listers,

 

I'm encountering the infamous "AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object" message....  line 70, column 13, here's my code snippet where I'm running into the problem:

 

        AccountTeamMember atm;
        AccountTeamMember[] atmsToInsert = new AccountTeamMember[0];
        User u;
        index=0;
        for(Account a : accts) {
            if (a.OwnerId == Null) system.assertequals(1,2);
//            system.assertequals(3,4);
            atm.UserId = a.OwnerId;                          //this is line 70, where the error is occurring.

 

What am I missing?  Thanks for any assistance.  (a.OwnerId successfully holds the account owner Id).

 

Pete

As a safeguard to inadvertant changes to a user account used by various integration jobs, was wondering if it would be possible to detect and stop the "Change Password" capability on that account.

 

I thought since the "Change Password" seems to update the "Last Modified" Datestamp, I could do this easily with a validation rule, but this doesn't work.

 

Thoughts?

 

Thanks,

Pete

Greetings,

 

Is it possible to assign a control-key to a custom button? 

 

(Use-case:  User has a long form - rather than scroll up or down to find the [Save] button, I can give them a [Ctrl-S] (or equivalent) to invoke the [Save] process).

 

Thanks,

Pete

Listers,

 

We have a "Manager" field on our user table that's just a lookup to the user table, (it holds a reference to that user's manager).  On another table, I also have a lookup to the user table, called "Associate".  If I wanted to also retreive the last name of that Associate's manager, I can do so with a formula field:

 

Associate__r.Manager__r.LastName

 

Here's my question:

Why doesn't this also work with the Owner field?  i.e.,

Ownerid__r.Manager__r.LastName

 

Thanks,

Pete

Greetings Listers,

 

Within an Apex class, I'm looping through and building a string thusly :

 

  mystring += eachrecord.Quantity__c + '         ' + eachrecord.Item__c + '\n';

 

After setting the target field to this value, when displaying this value in a report (or an alert), the whitespace between the Quantity and Item values is compressed to a single space.  How can I prevent this?

 

Thanks,

Pete

Greetings,

 

I'm pulling my hair out trying to find out why my test method is failing.

 

I've "borrowed liberally" from Colin Loretz's page on creating rollup fields between any object, (x-ref http://colinloretz.com/tag/salesforce-apex-code/).

 

The trigger I've created aggregates values from "child" records, placing the total value on the parent.  Works great.

 

The test method however, fails on the assertequals clause :

 

...

    // Test ParentObj__c "p" created, which automatically spawns the

    // creation of a default first ChildObj__c with a Percent__c equal to 100.

...

    List<ChildObj__c> ChildObjList = new List<ChildObj__c>();
    ChildObj__c c1 = new ChildObj__c(ParentObj__c=p.id,Percent__c=10);
    ChildObj__c c2 = new ChildObj__c(ParentObj__c=p.id,Percent__c=25);
    ChildObj__c c3 = new ChildObj__c(ParentObj__c=p.id,Percent__c=50);

    ChildObjList.add(c1);
    ChildObjList.add(c2);
    ChildObjList.add(c3);

    //Insertion test 100 + 10 + 25 + 50 = 185
    {
        insert ChildObjList;
        p = [select id, Total_Percent__c from ParentObj__c where id=:p.Id];
        System.assertEquals(185,Parent.Total_Percent__c);

        // "System.AssertException: Assertion Failed: Expected: 185, Actual: 555" ?!?!?!

    }

...

 

If I set my "expected" value to 555, then continue with update and deletion tests, things seem to normalize.  I noticed that the "Actual Result" is always three times the expected, (because I'm inserting three records).  If I only do two inserts, then the delta is off by two times the expected, (and I can avoid the issue entirely if I do a single record test, but I'd really like to understand why this is happening).

 

Thanks for any insight,

Pete

 

Greetings,

 

Wondering if the following is possible via Apex coding -

 

I have some functioning Apex code that fires on a button-click.  At the conclusion of that code, I'd like to pass/relinquish control to the save process, (via "update obj" or other construct).  I say relinquish, because I'd like any validation rules / workflow rules to execute normally - (outside of Apex, as if the user themselves clicked "Save").  Whether the record actually is 'Saved' or generated errors is unimportant to this procedure.

 

Is this possible?  Thanks for any information / assistance.

 

Pete  

Feels like I'm really close... 

 

I'm still struggling with trying to populate a lookup field to another table based on the value in a text field.

 

I have...

 a map of accounts with their associated scrubbed zip-code ("accountmap")

 a set of unique scrubbed zip-codes ("accountzips")

 a map of zip codes ("zipcodes")

 

The code compiles, but fails on execution:

        a.ZipId__c = zipcodes.get(accountmap.get(a.id)).id; 

 

Error:  "Apex trigger PopZipId caused an unexpected exception, contact your administrator: PopZipId: execution of BeforeUpdate caused by: System.StringException: Invalid id: 10041"

 

Full trigger is shown below.  Thanks for any/all guidance.  I'm pulling my hair out.

 

//  Set<string> accountzips = new Set<string>();

trigger PopZipId on Account (before insert, before update) {

    String billzip;
    integer dashpos;

    Map<id, string> accountmap = new Map<id, string>();
    Set<string> accountzips = new Set<string>();

    for (Account a : Trigger.new) {
        // only include accounts being inserted or where the BillingPostalCode is changing
        if (
                System.Trigger.isInsert
            || (System.Trigger.isUpdate && a.BillingPostalCode != System.Trigger.oldMap.get(a.Id).BillingPostalCode)
           )
        {
            // remove leading zeros, remove zip+4
            if (a.BillingPostalCode != Null) {
                dashpos = (a.BillingPostalCode + '-').indexof('-');
                billzip = (a.BillingPostalCode.substring(0,Dashpos)).replaceAll('^0+(?!$)','');
                //if we accidentally nulled out the zip code, use the '0' zip code:
                if (billzip == Null) {
                    billzip = '0';
                }
            } else {
                billzip = '0';
            }
        accountmap.put(a.id, billzip);
        accountzips.add(billzip);
        }
    } 
   
    Map<id, zip__c> zipcodes = new Map<id, zip__c>([Select id, name from zip__c where name in :accountzips]);

    for (Account a : Trigger.new) {
        //a.ZipId__c = 'a0kT0000000K7dI';     
        a.ZipId__c = zipcodes.get(accountmap.get(a.id)).id; 
    }
}

 

Pete

Greetings,

 

I have two fields on the account - a text "Zip Code" field, and a lookup field to a custom ZIP__c table.  I'd like to write a trigger to populate the value of the corresponding ZIP__c.id based on the text value entered.

 

The trigger should:

1.  Fire before insert and before update

2.  If before update, (to prevent unnecessary cpu cycles) only fire if the Billing_Zip_Code has changed.

3.  Remove the "Zip+4" and leading zeros, if they exist.

4.  Populate the id from the "Zip__c" table into the ZipID__c field on the Account, (or else use the "0" zip code id)

 

I was able to write this trigger as a "one-off" - works fine.  I'm struggling with "bulkifying" the trigger, (okay, I'm failing miserably).  I'm trying to group the accounts by zip code and do a bulk update.  Here's what I've come up with so far:

 

trigger setZipId on Account (before insert, before update) {

    // Get the Undefined Zip Id out of the way.. (important for bulkifying)
    Zip__c BadZipCode = [
        SELECT Id
          FROM Zip__c
         WHERE Name = '0' Limit 1
    ];
    String BillZip;
    integer Dashpos;

    Map<String, Account> accountMap = new Map<String, Account>();
    for (Account acct : System.Trigger.new) {
        if (System.Trigger.isInsert ||
            acct.BillingPostalCode != System.Trigger.oldMap.get(acct.Id).BillingPostalCode) {
            if (acct.BillingPostalCode != Null) {
                Dashpos = (Acct.BillingPostalCode + '-').indexof('-');
                BillZip = (Acct.BillingPostalCode.substring(0,Dashpos)).replaceAll('^0+(?!$)','');
            } else {
                BillZip = '0';
            }
            accountMap.put(BillZip, acct);
        }
    }
    for (Account acct : [
         SELECT BillingPostalCode
           FROM Account
          WHERE BillingPostalCode IN :accountMap.KeySet()
          ]) {
        Account newAcct = accountMap.get(acct.BillingPostalCode);
        if (newAcct.BillingPostalCode != Null) {
            List<Zip__c> ZipArray = [
                SELECT Id
                  FROM Zip__c
                 WHERE Name = :newAcct.BillingPostalCode limit 1
            ];
           
            if (ZipArray.size() > 0) {
                for (Zip__c ZipCode: ZipArray) {
                    newAcct.ZipId__c = ZipCode.id;
                 }
            } else {
                newAcct.ZipId__c = BadZipCode.Id;
            }
        }
    }
}

 

 

Thanks for any / all assistance,

Pete

Hi all,

 

Getting my feet wet with triggers - trying to "bulkify" an otherwise working trigger using best practices.

 

I'm using a zip code field on the Account table to query a custom table, and populate a lookup field.  In the event the zip code is blank, invalid, or not found in the query, I'd like to populate a "default" record in the lookup.

 

My choices are 

  1.  hard-code the record id of the "default" record in a variable (and hope that it never changes).

  2.  query the "default" record exactly one time - up-front in the trigger, before the "for (Account Acct:Trigger.new) {"

  3.  query the "default" record zero to 'n' times - only when needed.

 

I'm leaning towards #2.  Though I'm still getting "too many SOQL queries" in my testing, with batch sizes > 10 :

 

trigger setWidgetOwner on Account (before insert, before update) {

    // Get the Default Widget

    Widget__c DefaultWidget = [
        Select Id from Widget__c
         where Name = 'Default' Limit 1  // 2nd q:  does "Limit 1" help processing at all, if I know there's only one?
    ];

// Begin the bulk processing...        
    for (Account Acct:Trigger.new) {
    ... 

 

Thanks,

Pete

Greetings all..

 

Looking for some assistance, I'm very new to SFDC.

 

I created a custom two-field object that holds 4-digit SIC codes and Industry Title.

 

I'd like to populate a custom field on the Account object called "SIC Description" with the "SIC.Industry Title" value, depending on the value in the (standard) "Account.SIC Code" field.

 

(Would this be best served by an Apex trigger?)  Any and all assistance is appreciated! 

 

Thanks,

Pete

Greetings,

 

Been pulling out my hair on this one - have a fully functional class/trigger set that performs the following:

 

Have a "Reports To" and "Reporting VP" lookup fields on the User record.  For every Account record I want to have three AccountTeamMembers created, or updated when the Account Owner changes, or if their report to structure should change:

 

"Sales Rep" (Oppy Owner)

"Sales Manager" (Oppy Owner's Report To) and

"Sales Director" (Oppy Owner's Reporting VP)

 

Again, the trigger and class are working - I'm struggling with the Test Class.  There are three entry points:

1.  Account creation - (create the three AccountTeamMembers)

2.  Account owner change - (replace the three AccountTeamMembers)

3.  User Manager / VP change - (replace the Manager / Director AccountTeamMembers)

 

Here's the error message / Stack Trace:

 

Message:

System.DmlException: Update failed. First exception on row 0 with id 005Q0000000LTK4IAO; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): User, original object: Account: []

 

Stack Trace:

Class.TestAccountTeamMemberUpdates.testAccountModelATMAssignmentMethods: line 140, column 13 External entry point

 

I will post my test class in the next message.  Thanks for any guidance / assistance!

 

Pete

Greetings listers,

 

I'm encountering the infamous "AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object" message....  line 70, column 13, here's my code snippet where I'm running into the problem:

 

        AccountTeamMember atm;
        AccountTeamMember[] atmsToInsert = new AccountTeamMember[0];
        User u;
        index=0;
        for(Account a : accts) {
            if (a.OwnerId == Null) system.assertequals(1,2);
//            system.assertequals(3,4);
            atm.UserId = a.OwnerId;                          //this is line 70, where the error is occurring.

 

What am I missing?  Thanks for any assistance.  (a.OwnerId successfully holds the account owner Id).

 

Pete

Listers,

 

We have a "Manager" field on our user table that's just a lookup to the user table, (it holds a reference to that user's manager).  On another table, I also have a lookup to the user table, called "Associate".  If I wanted to also retreive the last name of that Associate's manager, I can do so with a formula field:

 

Associate__r.Manager__r.LastName

 

Here's my question:

Why doesn't this also work with the Owner field?  i.e.,

Ownerid__r.Manager__r.LastName

 

Thanks,

Pete

Greetings Listers,

 

Within an Apex class, I'm looping through and building a string thusly :

 

  mystring += eachrecord.Quantity__c + '         ' + eachrecord.Item__c + '\n';

 

After setting the target field to this value, when displaying this value in a report (or an alert), the whitespace between the Quantity and Item values is compressed to a single space.  How can I prevent this?

 

Thanks,

Pete

Greetings,

 

I'm pulling my hair out trying to find out why my test method is failing.

 

I've "borrowed liberally" from Colin Loretz's page on creating rollup fields between any object, (x-ref http://colinloretz.com/tag/salesforce-apex-code/).

 

The trigger I've created aggregates values from "child" records, placing the total value on the parent.  Works great.

 

The test method however, fails on the assertequals clause :

 

...

    // Test ParentObj__c "p" created, which automatically spawns the

    // creation of a default first ChildObj__c with a Percent__c equal to 100.

...

    List<ChildObj__c> ChildObjList = new List<ChildObj__c>();
    ChildObj__c c1 = new ChildObj__c(ParentObj__c=p.id,Percent__c=10);
    ChildObj__c c2 = new ChildObj__c(ParentObj__c=p.id,Percent__c=25);
    ChildObj__c c3 = new ChildObj__c(ParentObj__c=p.id,Percent__c=50);

    ChildObjList.add(c1);
    ChildObjList.add(c2);
    ChildObjList.add(c3);

    //Insertion test 100 + 10 + 25 + 50 = 185
    {
        insert ChildObjList;
        p = [select id, Total_Percent__c from ParentObj__c where id=:p.Id];
        System.assertEquals(185,Parent.Total_Percent__c);

        // "System.AssertException: Assertion Failed: Expected: 185, Actual: 555" ?!?!?!

    }

...

 

If I set my "expected" value to 555, then continue with update and deletion tests, things seem to normalize.  I noticed that the "Actual Result" is always three times the expected, (because I'm inserting three records).  If I only do two inserts, then the delta is off by two times the expected, (and I can avoid the issue entirely if I do a single record test, but I'd really like to understand why this is happening).

 

Thanks for any insight,

Pete

 

Greetings,

 

Wondering if the following is possible via Apex coding -

 

I have some functioning Apex code that fires on a button-click.  At the conclusion of that code, I'd like to pass/relinquish control to the save process, (via "update obj" or other construct).  I say relinquish, because I'd like any validation rules / workflow rules to execute normally - (outside of Apex, as if the user themselves clicked "Save").  Whether the record actually is 'Saved' or generated errors is unimportant to this procedure.

 

Is this possible?  Thanks for any information / assistance.

 

Pete  

Feels like I'm really close... 

 

I'm still struggling with trying to populate a lookup field to another table based on the value in a text field.

 

I have...

 a map of accounts with their associated scrubbed zip-code ("accountmap")

 a set of unique scrubbed zip-codes ("accountzips")

 a map of zip codes ("zipcodes")

 

The code compiles, but fails on execution:

        a.ZipId__c = zipcodes.get(accountmap.get(a.id)).id; 

 

Error:  "Apex trigger PopZipId caused an unexpected exception, contact your administrator: PopZipId: execution of BeforeUpdate caused by: System.StringException: Invalid id: 10041"

 

Full trigger is shown below.  Thanks for any/all guidance.  I'm pulling my hair out.

 

//  Set<string> accountzips = new Set<string>();

trigger PopZipId on Account (before insert, before update) {

    String billzip;
    integer dashpos;

    Map<id, string> accountmap = new Map<id, string>();
    Set<string> accountzips = new Set<string>();

    for (Account a : Trigger.new) {
        // only include accounts being inserted or where the BillingPostalCode is changing
        if (
                System.Trigger.isInsert
            || (System.Trigger.isUpdate && a.BillingPostalCode != System.Trigger.oldMap.get(a.Id).BillingPostalCode)
           )
        {
            // remove leading zeros, remove zip+4
            if (a.BillingPostalCode != Null) {
                dashpos = (a.BillingPostalCode + '-').indexof('-');
                billzip = (a.BillingPostalCode.substring(0,Dashpos)).replaceAll('^0+(?!$)','');
                //if we accidentally nulled out the zip code, use the '0' zip code:
                if (billzip == Null) {
                    billzip = '0';
                }
            } else {
                billzip = '0';
            }
        accountmap.put(a.id, billzip);
        accountzips.add(billzip);
        }
    } 
   
    Map<id, zip__c> zipcodes = new Map<id, zip__c>([Select id, name from zip__c where name in :accountzips]);

    for (Account a : Trigger.new) {
        //a.ZipId__c = 'a0kT0000000K7dI';     
        a.ZipId__c = zipcodes.get(accountmap.get(a.id)).id; 
    }
}

 

Pete

Hi all,

 

Getting my feet wet with triggers - trying to "bulkify" an otherwise working trigger using best practices.

 

I'm using a zip code field on the Account table to query a custom table, and populate a lookup field.  In the event the zip code is blank, invalid, or not found in the query, I'd like to populate a "default" record in the lookup.

 

My choices are 

  1.  hard-code the record id of the "default" record in a variable (and hope that it never changes).

  2.  query the "default" record exactly one time - up-front in the trigger, before the "for (Account Acct:Trigger.new) {"

  3.  query the "default" record zero to 'n' times - only when needed.

 

I'm leaning towards #2.  Though I'm still getting "too many SOQL queries" in my testing, with batch sizes > 10 :

 

trigger setWidgetOwner on Account (before insert, before update) {

    // Get the Default Widget

    Widget__c DefaultWidget = [
        Select Id from Widget__c
         where Name = 'Default' Limit 1  // 2nd q:  does "Limit 1" help processing at all, if I know there's only one?
    ];

// Begin the bulk processing...        
    for (Account Acct:Trigger.new) {
    ... 

 

Thanks,

Pete

Hi All.

 

I have the following requirement -

 

I want a text to be displayed on the page that should be just a label, not to be associated with any field. It is a normal page and not a Visualforce page.

My text is about 200 characters (the character limit for field label is 50 chars and that for section label is 80 chars).

 

Can anyone suggest me the solution for this?

 

Any help will be GREAT :)

 

Thanks