0
  1. I have 2 lookups to two different objects: licence Type and Licence class Definition on Case Object.
  2. Licence Type is a lookup on Licence Class Definition Object.
  3. I want to filter Licence Class Definition Field on Case object based on Licence Type Value on Licence Class Definition Object.

Is there a way to retrieve results for Licence class field on Case based on Licence Type field on Case.

Apex Class:

  List<Case> caseList = [SELECT Id,Subject,LMT_LicenceType__c,(SELECT ID FROM LMT_Licence_Class_Definition_ForCase__r.LMT_LicenceClassDefinition__r) FROM LMT_LicenceType__c FROM Case WHERE Id = :caseId ];

Getting below errors:

Expecting ']' but was: 'FROM'
Unexpected token 'WHERE'.
Unexpected token ':'.
Extra ';', at ']'.
Variable does not exist: Id
Expression cannot be a statement.

Data Model for Case, Licence Type and Licence Class Object

  1. We have a component to capture specific fields on case object from case fields. So we have a requirement to add new Field Licence Class Definition.
  2. As discussed previously, Licence Type is a look up on Licence Class. So, even on this custom component, we want to make Licence Class field dependant on Licence Type.
  3. I tried couple of ways by creating Licence Class as a lookup to Licence Type itself and filtering Licence Class Values from that field but my query didn’t go well.
  4. Now, I want to know how to query specific licence Classes based on Licence Type value selected by User. It should be that dynamic in showing results to users.

We have that component on Case Object

Custom Component on Case Object

0

Edit 2:

I'll give this another try, but I really want to encourage you to read How to Ask and make sure to provide the information that the community needs from you in your question. This is a fairly straightforward SOQL issue, but we need to know the object model and API names to provide support.

I am going to assume that the API name for the License Type object is LMT_LicenseType__c and the API name for the License Class Definition object is LMT_LicenseClassDefinition__c. If that is not correct, you can make changes when you write your final SOQL.

If we have a Case whose Id is caseId and which has a lookup field whose API name is LMT_LicenceType__c, and we want to find all of the records in LMT_License_Class_Definition__c that have the same value in their License Type lookup field, also called LMT_LicenceType__c, we can run a simple SOQL query, using a subquery to pick up the Case's type:

List<LMT_LicenseClassDefinition__c> defs = [
    SELECT Id, ...OTHER_FIELDS
    FROM LMT_LicenseClassDefinition__c
    WHERE LMT_LicenceType__c IN (SELECT LMT_LicenceType__c FROM Case WHERE Id = :caseId)
];

If you already have the Case's license type, it's even easier: just an Apex bind, no subquery needed.

List<LMT_LicenseClassDefinition__c> defs = [
    SELECT Id, ...OTHER_FIELDS
    FROM LMT_LicenseClassDefinition__c
    WHERE LMT_LicenceType__c = :licenseTypeOfThisCase
];

Although in this case you do not need a relationship query at all, I would strongly encourage you to read the entirety of SOQL Relationship Queries. The query you include in your post isn't valid, and becoming familiar with the different types of relationship query will help in many areas.

|improve this answer|||||
  • Hi David, Licence Type Field is a direct lookup to Licence Type Object. Both of them are (Licence Type and Licence Class Definition) are queried separately on case object. Now, I want to filter results of licence class Definition based on Licence Type through code. Hope this is clear? – Prassu Dec 7 '18 at 3:04
  • Not really, @Prassu. Can you edit your question to show what you have tried so far, and make clear what the API names of the objects are and the relationships between them? – David Reed Dec 7 '18 at 3:11
  • HI @david, there is a whole lot of code which is used for different purposes. But, from your earlier comments, I got an idea. I created a new loookup relationship for Licence class Definition relating that to look Licence Type itself on case. From there, I want to traverse Licence Class(Child) from Licence Type(Parent). Can you help me with that traversal. Adding vf component code and apex class code which is used for this purpose – Prassu Dec 7 '18 at 20:29

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.