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
JayaJayaJayaJaya 

Urgent, please help with Lookup filter dialog result

We have following requirement:

1. Case object has 3 record types say "Product1 Record Type", "Product2 Record Type" and "Product3 Record Type"
2. There is a Lookup for Product in Case object
3. While searching for a product lookup as part of creating new Case object, only those Products shud be displayed that matches product name with current case record type.
For eg. Let us say I have already created products named "Product1" , "Product2"  and "Product3" . I am creating a case object with its record type as say "Product1 Record Type" and for product lookup, it shud display only those products whose product name contains in the current case record, which in this scenario is "Product1" under Lookup filter dialog results. 
Similarly, for case with "Product2 Record Type"  shud display "Product2" under Lookup dialog results. 

How to achieve this. I tried under lookup filter without any success. Please help.
Best Answer chosen by JayaJaya
Jigar.LakhaniJigar.Lakhani

Hi,

You can auto populate the picklist value usin pass the parameter to URL. but for override the new button url you need to override the button.
If you click on new case button currently it looks like - 
https://ap1.salesforce.com/500/e?retURL=%2F500%2Fo&RecordType=01290000001ALJD&ent=Case

but if you want to pre-populate record type name (custom picklist) field then you need below url
https://ap1.salesforce.com/500/e?retURL=%2F500%2Fo&RecordType=01290000001ALJD&ent=Case&00N9000000Ck3K2=Test+Product+2+RT

00N9000000Ck3K2 - Record Type Name picklist field Id, you can get it using edit the picklist field and id will display in URL.

For add new parameter in new case url, Follow below steps.

Visualforce Page: CreateNewCase

<apex:page standardController="Case" extensions="CreateNewCase" sidebar="false" 
    action="/500/e?retUrl={!$CurrentPage.parameters.retURL}&RecordType={!$CurrentPage.parameters.RecordType}&00N9000000Ck3K2={!strRecordTypeName}&ent=Case&cancelURL={!$CurrentPage.parameters.retURL}&nooverride=1">
</apex:page>

Apex Class: ​CreateNewCase
Public With Sharing Class CreateNewCase{
    
    public String strRecordTypeName{get;set;}
    
    Public CreateNewCase(ApexPages.StandardController controller){
        String strRecordTypeId = ApexPages.currentPage().getParameters().get('RecordType');
        if (strRecordTypeId != null && strRecordTypeId.trim() != '') {
            List<RecordType> listRecordType = new List<RecordType>([SELECT Id,Name FROM RecordType WHERE Id =: strRecordTypeId LIMIT 1]);
            if (listRecordType != null && listRecordType.size() > 0) {
                strRecordTypeName = listRecordType[0].Name;
            }
        }
    }
    
}

Override New Case button:

User-added image


**Record type name and piclist values need to be same.

Thanks and Cheers,
Jigar
 

All Answers

Jigar.LakhaniJigar.Lakhani
Hello,

I have looked into your requirement and try to find a solution, but it looks like salesforce is not accessing record type details in any lookup field criteria. So I cannot find the solution.

But alternate is that you can use validation rule after select the product. Once product will selected and try to save the record at that time we can give validation error like "Invalid product" and also can provide information about which type of products need to select in the same message.

Thanks and Cheers,
Jigar
JayaJayaJayaJaya
Thanks Jigar for your response. Instead of Validation rule and as you said that salesforce is not able to access record type details in any lookup field criteria, let us say I copy the record type name into another custom field say "RTfield". In this case can you give me the solution on how to achieve this requirement please?
Jigar.LakhaniJigar.Lakhani
Hi,

Most probably, yes we can achieve it using another custom fields but it has also some difficulties like below.

The solution is set record criteria with product lookup field. Edit product look up field and you'll see like below image.
User-added image

So for setting the criterial there are two types, one is source field type(Case Record) and another is compatible type(Product Record).
We need record type name to compare with product name, so if need to select Case:Record Type Name in first option(above image - black box).

Here Record Type Name field is custom picklist field with case record type name values. for your requirement -
"Product1 Record Type", "Product2 Record Type" and "Product3 Record Type"

I know we need to auto populate the custom field of record type name to use here, but here the limitation is that we can use only picklist field but not other field like formula or text field. So if you are talking about formula field in your above comment to copy the record type name then it is not use over here.
https://help.salesforce.com/htviewhelpdoc?err=1&id=fields_lookup_filters.htm&siteLang=en_US, you can see the table for source and compatible target object types.

So currently I am manually selecting the picklist (record type name) values. Please review below snaps.

For First Record Type
User-added image

For Second Record Type
User-added image

So the bottom line is that we need to find a way which will auto populate the picklist value based on selected record type.

Thanks and Cheers,
Jigar

 
JayaJayaJayaJaya
Thanks a lot Jigar for detailed answer. Your last sentence
"So the bottom line is that we need to find a way which will auto populate the picklist value based on selected record type." What should be the way for this? I tried creating another custom field in the Case record and tried to populate it with that of its case record type in its before trigger but it is getting populated only after saving the case record which is not useful for lookup filter, please suggest any way for this?
Jigar.LakhaniJigar.Lakhani

Hi,

You can auto populate the picklist value usin pass the parameter to URL. but for override the new button url you need to override the button.
If you click on new case button currently it looks like - 
https://ap1.salesforce.com/500/e?retURL=%2F500%2Fo&RecordType=01290000001ALJD&ent=Case

but if you want to pre-populate record type name (custom picklist) field then you need below url
https://ap1.salesforce.com/500/e?retURL=%2F500%2Fo&RecordType=01290000001ALJD&ent=Case&00N9000000Ck3K2=Test+Product+2+RT

00N9000000Ck3K2 - Record Type Name picklist field Id, you can get it using edit the picklist field and id will display in URL.

For add new parameter in new case url, Follow below steps.

Visualforce Page: CreateNewCase

<apex:page standardController="Case" extensions="CreateNewCase" sidebar="false" 
    action="/500/e?retUrl={!$CurrentPage.parameters.retURL}&RecordType={!$CurrentPage.parameters.RecordType}&00N9000000Ck3K2={!strRecordTypeName}&ent=Case&cancelURL={!$CurrentPage.parameters.retURL}&nooverride=1">
</apex:page>

Apex Class: ​CreateNewCase
Public With Sharing Class CreateNewCase{
    
    public String strRecordTypeName{get;set;}
    
    Public CreateNewCase(ApexPages.StandardController controller){
        String strRecordTypeId = ApexPages.currentPage().getParameters().get('RecordType');
        if (strRecordTypeId != null && strRecordTypeId.trim() != '') {
            List<RecordType> listRecordType = new List<RecordType>([SELECT Id,Name FROM RecordType WHERE Id =: strRecordTypeId LIMIT 1]);
            if (listRecordType != null && listRecordType.size() > 0) {
                strRecordTypeName = listRecordType[0].Name;
            }
        }
    }
    
}

Override New Case button:

User-added image


**Record type name and piclist values need to be same.

Thanks and Cheers,
Jigar
 
This was selected as the best answer