0

Here I am passing a String array of Id's to sentMail() method, trying to fetch data from a custom lookup field in a custom object Here 'Enquiry__c' is the custom look up field in the custom object 'Price__c'

@AuraEnabled
    public static String sentMail(String[] ids) {
       Price__c selectedenq = [SELECT Id, Name FROM Price__c WHERE Id in :ids][0];
       Enquiry__c en = selectedenq.Enquirer__c; //error in this line while deploying
        return en.Name;
    }

Error Illegal assignment from Id to Enquiry__c Is there any mistake in my code?

2

The data type for selectedenq.Enquirer__c is Id which you are trying to assign to an object of type Enquiry__c. That is why your code failed to compile.

Also, you are missing to add the parent field in the query = nquirer__r.Name.

You need to query the parent field like below and then use it to return the value

@AuraEnabled
public static String sentMail(String[] ids) {
     return [SELECT Enquirer__r.Name FROM Price__c WHERE Id in :ids][0].Enquirer__r.Name;
}
2

Enquirer__c is an Id value, but you're trying to assign it to a record instance. Use __r instead:

Enquiry__c en = selectedenq.Enquirer__r;

Note that you must include the field(s) you intend to return in your query:

Price__c selectedenq = [SELECT Enquirer__r.Name FROM Price__c WHERE Id in :ids][0];
1

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.