function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mariappan PerumalMariappan Perumal 

VLOOKUP usuage

Hi Everyone,

 

I have used vlookup function in excel and i don't how to use vlookup function in salesforce.

 

In Excel , I can fetch the values in particular cells with values to be entered in separate cell.

 

Can anyone tell me the way to use vlookup in SFDC.

 

Thanks in advance

Jeff MayJeff May

Here's the link to the SFDC doc on VLOOKUP() which has descriptions and examples.  https://help.salesforce.com/htviewhelpdoc?id=customize_functions_i_z.htm&siteLang=en_US#VLOOKUP

Mariappan PerumalMariappan Perumal

Thanks jeff. 

 

My question is whether can be used to do something other than validation purpose.

ShahTheTrainerShahTheTrainer

can be used for "Work Flow Rules" also.

Mariappan PerumalMariappan Perumal

Thanks shah.

 

I can accept that one . Can we acheive the task of trigger (I mean everytime before insert ) the record should fetch the record from some other object and insert that in another field. 

 

Instead of checking that with via VLOOKUP .

dblurton1.3891667462759148E12dblurton1.3891667462759148E12
Hi Mariappan,

I had a similar question and figured out how to do it. Here is my code: 

trigger AnyName on ObjectA (before insert, before update) {
    for (ObjectA responseInLoop : trigger.new) {
        if (responseInLoop.fieldA1 != NULL) {
        List<ObjectB> values = [SELECT fieldB2 FROM ObjectB WHERE fieldB1 = :responseInLoop.fieldA1];
            if (values.size() > 0) {
                responseInLoop.fieldA2 = scores[0].fieldB2;}
            Else {responseInLoop.Q1_Percentile__c = NULL;}}
        Else {responseInLoop.Q1_Percentile__c = NULL;}
    }
}

For clarity, I've used A and B to refer to the two objects, and 1 and 2 to the fields on each object (thus the field to return on Object B is easily identified as fieldB2). 

The code checks to see if A1 is empty, if not, return values of B2 where B1 = A1, and then sets A2 = to B2. If A1 is empty or does not return any B records, nothing happens. Hope this helps anyone with similar needs!

Dan
ScrapsWillScrapsWill
Great solution Dan, that worked for me perfectly with a couple of minor adjustments!!