3

This is kind of an odd scenario and I was wondering if anyone had seen anything like this before.

We have a custom object called Financial_Account__c which stores information about our customers' current accounts at our firm. There are two text fields on this object called Product_Category_Code__c and Product_Code__c. The combination of these two codes corresponds to a unique name for the account. For example, if Product_Category_Code__c == '001' and Product_Code__c == '00001', then the name of the product would be AFI Installment.

I want to be able to stamp the name on the Financial_Account__c record, but there are some issues:

1) There are over 3000 products.

2) An updated product list is produced weekly.

I originally thought to do this using a formula field, but there are over 3000 products and a formula field cannot contain that many rules. Plus, I do not want to update the definition of the formula field every week. So it seems that a formula field is not a viable option.

I created a class called ProductMapping that looks something like this:

public class ProductMapping{

private Map<String, String> m;
public ProductMapping(){
m = new Map<String, String>();
m.put('00100001','AFI INSTALLMENT');
m.put('00100002','IST&G INSTALLMENT');
...
}
public String Product(String Cat, String Prod){
return m.get(cat+prod);
}
} 

As well as a trigger called ProductNames that looks like this:

trigger ProductNames on Financial_Account__c (before update, before insert){

ProductMapping pm = new ProductMapping();
for (Financial_Account__c a : Trigger.new) {
String Cat = a.Product_Category_Code__c;
String Prod = a.Product_Code__c;
String Product = pm.Product(Cat, Prod);
a.Product_Name__c = Product;
}
}

But since the product names are updated weekly, I don't want to modify the code every week.

I am curious if there is a way to store a lookup/parameter file (probably CSV) in salesforce that would be able to be referenced in code that could look up the product name.

The only way I can think of doing this would to be upload the file into documents, then query for it in the code, use a BufferedReader to read each line and look for the product name based on product and category codes.

Is this a viable approach? Or is there a better way to implement a solution?

Thank you for your time and help. -Mitch

2
  • 2
    Have you thought about creating a custom object that stores the product names that is modeled after your ProductMapping class. You would then have the ability to use something like the Salesforce Dataloader to schedule or manually load these products. From there you could then reference the name through the relationship. – TC Sutton May 20 '15 at 15:18
  • I agree with @TCSutton. It seems that creating Custom Objects Product_Category__c and Product__c would be the easiest solution. Then on Account, create a formula field Unique_Id__c = Product_Category__r.Name + "-" + Product__r.Name – Scott Pelak May 20 '15 at 16:45
0

You can use list custom setting for this. It provides you a way to get the code combination quicker and does not cost any SOQL limit.

  1. Create a custom setting call Cat_Code__c with only 1 field combide_code__c
  2. Insert data into setting. Ex: Name = '00100001' , combide_code__c = 'AFI INSTALLMENT'
  3. In the code you just need to call Cat_Code__c.getInstance('00100001').combide_code__c;

Hope this help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.