• Jenna Hildebrand
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 16
    Replies
Hello,

I need to write an apex class that sums the Employees field on all accounts within a hierarchy and updates a custom field called "Total Hierarchy Employees" with the result on each account. For example:
  • Test Account 1 – 10 employees
    • Test Account 2 – 15 employees
    • Test Account 3 – 12 employees
The "Total Hierarchy Employees" field should read "37" on Test Account 1, 2, and 3.

I've gotten my apex class started, but I'm having trouble avoiding nesting loops and such. Any help is greatly appreciated.

Thank you!
Hi,

I've created a flow that updates an opportunity text field with the names of the products associated with that opportunity (separated by semicolons). This field should be updated whenever a new product is added or deleted, so I need to be able to invoke this flow with a trigger rather than just process builder. I've looked at a lot of different resources, but I can't seem to find something that explains how the apex class and trigger work together to call the flow and pass variables from the trigger/class to the flow. Would seriously appreciate any guidance or code snippet anyone could offer!

Thanks!
Hello,

I don't have any experience with VisualForce, but I was directed here by Salesforce Support to maybe get an idea of how to start with this request: I'd like to alter our campaign hierarchy page to show active campaigns only. Any suggestions on how I can start to tackle this?

Thank you!
Hi there,

What is the best way to check a list—like an excel spreadsheet—against existing records in Salesforce? This seems like a super basic question, so I might be missing an obvious solution. I've been given a spreadsheet of 3,000+ leads that our Marketing department will take action on. However, they first want to know if any of these leads in the spreadsheet already exist in Salesforce as leads or contacts.

If the list is small, I can pull a report matching by email address or something like that. However, with thousands of leads needing to be checked, that process is less feasible. I'd really appreciate any advice you can offer!

Thanks!
Hello,

I created an apex class and trigger to handle my org's territory management. It works by searching for the zip code of a new or updated account in our custom Zip Code object. Zip Code records have a look-up field to another custom object called Territory. If the zip code is found, it populates an account field with the "owner" of that Zip Code's Territory.

This has worked swimmingly, except for when zip codes are the full format (00000-0000). Sometimes the Territory is properly assigned in these cases, and sometimes it isn't—even though we've accounted for the variance in zip code format in the below code:
// for new accounts being created...
for (Account a :account) {

    String zipCodeFull = a.BillingPostalCode;
    String zipCodeToLookup;

    if (zipCodeFull != null && zipCodeFull.length() > 5) {
        zipCodeToLookup = zipCodeFull.left(5);
    }
    else {
        zipCodeToLookup = zipCodeFull;
    }

    // if the zip code map contains the account zip code...
    if(zipVsTerritoryMap.containsKey(zipCodeToLookup)) {
        // then assign the appropriate territory id 
        a.Account_Territory__c = zipVsTerritoryMap.get(zipCodeToLookup);
    }
    else {
        a.Account_Territory__c = 'a220f0000021ihA';
    }
}
Would a better option than using the left() class be to somehow use wildcard * logic? If so, I'd greatly appreciate suggestions on how to implement this. I'm also open to any other ways to make this assignment work better for full-formated zip codes as well as five-digit ones.

Thank you!
Hi,

Could someone help me get past this error for the test class below?

System.QueryException: List has no rows for assignment to SObject
​Class.AccountTerritoryManagementTest.validateTerritoryManagement: line 13, column 1
 
@isTest
private class AccountTerritoryManagementTest {

    static testMethod void validateTerritoryManagement() {
    
    Account a = new Account(Name='Territory Testing', BillingState='LA', BillingPostalCode='12345', Account_Territory__c = null);
    System.debug('Territory = ' + a.Account_Territory__c);
    
    insert a;
    
    a = [SELECT Account_Territory__c, BillingPostalCode FROM Account WHERE Id =:a.Id];
    
    Zip_Code__c zipCode = [Select Name, Territory__c from Zip_Code__c where Name =:a.BillingPostalCode];
    
    System.debug('Territory after trigger fired: ' + a.Account_Territory__c);
        
    System.assertEquals(zipCode.Territory__c, a.Account_Territory__c);
    
    }

}
I want to deploy a new apex class to Production, but I'm having issues because its test class keeping failing. Any advice or insight would be greatly appreciated.

Thank you!
Hello,

I'm working to build a simple, custom territory management solution for my org; other territory management tools don't quite do the trick. Basically, I need to assign accounts to territories based on the zip code value in the account's billing address.

First, some object details: I have a custom object for Territories and a custom object for Zip Codes. Each Zip Code record has a lookup field for a Territory record, which basically signifies that the zip code "belongs" to the related territory. I can go to each Territory record and see a related list of the associated Zip Code records. I also have a Territory lookup field on the account record. (I was told that I may need a Zip Code lookup on the account as well to serve as a junction, but I'm not sure about that one yet...)

Now, what I want to accomplish: I need to create an apex trigger that says, "if the value in the account's billing zip code matches the name of any existing Zip Code record, then 'Territory' (on the account) equals the Territory related to that matched Zip Code record."

I was hoping to accomplish this via process builder, but Salesforce Support informed me that this won't be possible... which brings me here. Can anyone help me get started on coding an apex trigger that can accomplish what I stated above? I'd appreciate any guidance you can provide.

Thank you!
Hello,

I need to write an apex class that sums the Employees field on all accounts within a hierarchy and updates a custom field called "Total Hierarchy Employees" with the result on each account. For example:
  • Test Account 1 – 10 employees
    • Test Account 2 – 15 employees
    • Test Account 3 – 12 employees
The "Total Hierarchy Employees" field should read "37" on Test Account 1, 2, and 3.

I've gotten my apex class started, but I'm having trouble avoiding nesting loops and such. Any help is greatly appreciated.

Thank you!
Hi,

I've created a flow that updates an opportunity text field with the names of the products associated with that opportunity (separated by semicolons). This field should be updated whenever a new product is added or deleted, so I need to be able to invoke this flow with a trigger rather than just process builder. I've looked at a lot of different resources, but I can't seem to find something that explains how the apex class and trigger work together to call the flow and pass variables from the trigger/class to the flow. Would seriously appreciate any guidance or code snippet anyone could offer!

Thanks!
Hello,

I don't have any experience with VisualForce, but I was directed here by Salesforce Support to maybe get an idea of how to start with this request: I'd like to alter our campaign hierarchy page to show active campaigns only. Any suggestions on how I can start to tackle this?

Thank you!
Hi there,

What is the best way to check a list—like an excel spreadsheet—against existing records in Salesforce? This seems like a super basic question, so I might be missing an obvious solution. I've been given a spreadsheet of 3,000+ leads that our Marketing department will take action on. However, they first want to know if any of these leads in the spreadsheet already exist in Salesforce as leads or contacts.

If the list is small, I can pull a report matching by email address or something like that. However, with thousands of leads needing to be checked, that process is less feasible. I'd really appreciate any advice you can offer!

Thanks!
Hello,

I created an apex class and trigger to handle my org's territory management. It works by searching for the zip code of a new or updated account in our custom Zip Code object. Zip Code records have a look-up field to another custom object called Territory. If the zip code is found, it populates an account field with the "owner" of that Zip Code's Territory.

This has worked swimmingly, except for when zip codes are the full format (00000-0000). Sometimes the Territory is properly assigned in these cases, and sometimes it isn't—even though we've accounted for the variance in zip code format in the below code:
// for new accounts being created...
for (Account a :account) {

    String zipCodeFull = a.BillingPostalCode;
    String zipCodeToLookup;

    if (zipCodeFull != null && zipCodeFull.length() > 5) {
        zipCodeToLookup = zipCodeFull.left(5);
    }
    else {
        zipCodeToLookup = zipCodeFull;
    }

    // if the zip code map contains the account zip code...
    if(zipVsTerritoryMap.containsKey(zipCodeToLookup)) {
        // then assign the appropriate territory id 
        a.Account_Territory__c = zipVsTerritoryMap.get(zipCodeToLookup);
    }
    else {
        a.Account_Territory__c = 'a220f0000021ihA';
    }
}
Would a better option than using the left() class be to somehow use wildcard * logic? If so, I'd greatly appreciate suggestions on how to implement this. I'm also open to any other ways to make this assignment work better for full-formated zip codes as well as five-digit ones.

Thank you!
Hi,

Could someone help me get past this error for the test class below?

System.QueryException: List has no rows for assignment to SObject
​Class.AccountTerritoryManagementTest.validateTerritoryManagement: line 13, column 1
 
@isTest
private class AccountTerritoryManagementTest {

    static testMethod void validateTerritoryManagement() {
    
    Account a = new Account(Name='Territory Testing', BillingState='LA', BillingPostalCode='12345', Account_Territory__c = null);
    System.debug('Territory = ' + a.Account_Territory__c);
    
    insert a;
    
    a = [SELECT Account_Territory__c, BillingPostalCode FROM Account WHERE Id =:a.Id];
    
    Zip_Code__c zipCode = [Select Name, Territory__c from Zip_Code__c where Name =:a.BillingPostalCode];
    
    System.debug('Territory after trigger fired: ' + a.Account_Territory__c);
        
    System.assertEquals(zipCode.Territory__c, a.Account_Territory__c);
    
    }

}
I want to deploy a new apex class to Production, but I'm having issues because its test class keeping failing. Any advice or insight would be greatly appreciated.

Thank you!
Hello,

I'm working to build a simple, custom territory management solution for my org; other territory management tools don't quite do the trick. Basically, I need to assign accounts to territories based on the zip code value in the account's billing address.

First, some object details: I have a custom object for Territories and a custom object for Zip Codes. Each Zip Code record has a lookup field for a Territory record, which basically signifies that the zip code "belongs" to the related territory. I can go to each Territory record and see a related list of the associated Zip Code records. I also have a Territory lookup field on the account record. (I was told that I may need a Zip Code lookup on the account as well to serve as a junction, but I'm not sure about that one yet...)

Now, what I want to accomplish: I need to create an apex trigger that says, "if the value in the account's billing zip code matches the name of any existing Zip Code record, then 'Territory' (on the account) equals the Territory related to that matched Zip Code record."

I was hoping to accomplish this via process builder, but Salesforce Support informed me that this won't be possible... which brings me here. Can anyone help me get started on coding an apex trigger that can accomplish what I stated above? I'd appreciate any guidance you can provide.

Thank you!