1

I have a question in regards in what would be the best structure to build a solution based on Lead fields that are compared to a number of custom fields in a custom object in SFDC.

The scenario is that we have four custom fields in the Lead object:

  1. Exterior_Colour__c,
  2. Interior_Colour__c,
  3. Motor__c and
  4. Model__c.

They are all picklist data type.

Exterior Colour have three options: A, B, and C.

Interior Colour have three options: A1, B1 and C1.

Model have three options: ZP1, ZP2 and ZP3.

Motor have three options: M1, M2 and M3.

On Vehicle__c we also have the same fields with the same values.

What I want is to show on the Lead page layout a section that will select those Vehicle__c records that are at least 80% similar to the picklist values between the Lead record and the vehicles records. I need also to show the similarity percentage on the Lead page between the Lead and Vehilces >= 80%, based on the value entered on the fields mentioned above.

I have been thinking on a few solutions but I can't see a clear structure for this. Initially I though that a trigger on the Lead object would be the best approach but I'm not so sure now. Another solution, that I was thinking, is to create a visualforce page that will be refreshed everytime a user enters a Lead.

What do you guys think will be the best approach for this scenario? Thanks.

@mkorman.

Hello mkorman. Thanks for your input. Yes, it looks like the best option will be go for a component that will be set on the Lead page. There is not problems getting the Lead and obtaining a list of vehicles in connection to that Lead. So are you suggesting to compare the fields and add points to them if a match is found? Something like.

public Integer exteriorColour;
public Integer interiorColour; 
public Integer motor;
public Integer model; 
public Integer finalPoints; 
Map<Vehicle__c, Integer> theMap = new Map<Vehicle__c, Integer>(); 
for(List<Vehicle_c> v : [SELECT Id, Exterior_Colour__c, Interior_Colour__c, Motor__c, Model__c FROM Vehicle__c WHERE id =: <list of vehicle coming from lead>]){
    for(Vehicle__c veh: v){
    if(lead. Exterior_Colour__c == veh. Exterior_Colour__c){
        exteriorColour =1; 
    }
    if(lead.Interior_Colour__c == veh.Interior_Colour__c){
        interiorColour =1; 
    }……..
finalPoints = exteriorColour+ interiorColour+ motor+ model; 
    theMap.put(veh, finalPoints); 
} 

Something like that?

1
  • Something like that could work. The exact logic would be up to your requriements. I would modify the code as to encapsulate all the comparing logic in a separate class. See the edit to my response below.
    – mkorman
    Jan 5, 2016 at 11:15

1 Answer 1

0

I don't think a trigger is the best approach. It would only run when you add/edit Leads... but how to update the info when you add/edit Vehicles?

I would go for a VisualForce custom component (note that the link above does not mention that a component can have a controller).

Controller

The controller for your component could take the ID of a Lead, read the value of the 4 fields, and then query the Vehicle objects to find the matching ones. It should return a List <Vehicle__c> in a public property, together with the match score (perhaps a Map <Vehicle__c, Decimal>) as a public property.

Edit (based on your feedback): The best way to perform the comparison is to isolate it in a separate class. Something like this:

public class VehicleScorer ()
{
    public static Integer ScoreVehicle (Vehicle__c vehicle, Lead customer)
    {
        Integer score = 0;
        if (customer.Exterior_Colour__c == vehicle.Exterior_Colour__c) {
            score++; 
        }
        if (customer.Interior_Colour__c == vehicle.Interior_Colour__c) {
            score++; 
        }
        // And so on with the other 2 properties
        return score;
    }
}

This is a very simple comparer. It does not compare 'similar' colours (for instance, orange is quite similar to red), but it may work for you. That is up to your requirements.

The component controller could call this method like this:

public Map <Vehicle__c, Integer> getScores ()
{
    Map <Vehicle__c, Integer> results = new Map <Vehicle__c, Integer> ();

    for(List<Vehicle_c> v : [SELECT Id, Exterior_Colour__c, Interior_Colour__c, Motor__c, Model__c FROM Vehicle__c WHERE id =: <list of vehicle coming from lead>]) {
         results.put (v, VehicleScores.ScoreVehicle (v, lead);
    }
    return results;
}

Markup

The VF part of the component would display all the Vehicles and scores in your public property. If you want to make it fancy you could try to delay the loading of the controller and add some UI animation (a spinner) to indicate that the information is loading... components that perform DB queries can take a bit long to run.

Page layout

Finally, you would add that component to the page layout of the lead object.

These ideas need a bit of refinement, but it could give you a way to approach the solution. Let me know if you need more information.

2
  • Hello mkorman. I have added some coments on the main question, can you take a look and let me know your thoughts on them? Thanks. Jan 5, 2016 at 10:59
  • Done. Added some code example on how you could call the compare :)
    – mkorman
    Jan 5, 2016 at 11:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .