You need to sign in to do that
Don't have an account?
Haseeb Ahmad 9
ERROR System.QueryException: List has no rows for assignment to SObject
I am getting this ERROR System.QueryException: List has no rows for assignment to SObject on the following lines of code:
I tried to use try and catch but then I was not able to link the case back to opportunity, probably I am missing something very small but not able to figure this one out, can someone help, thank you.
public static void insertCase(Case caseData) { insert caseData; Opportunity unitOpportunity = [select Id from Opportunity where Id =: caseData.OppToCase__c limit 1]; unitOpportunity.Case__c = caseData.Id; update unitOpportunity; }
I tried to use try and catch but then I was not able to link the case back to opportunity, probably I am missing something very small but not able to figure this one out, can someone help, thank you.
Hi Haseeb,
In case you find any other issue please mention.Your code is correct. You check it, you have created an opportunity record related to the case.
Or you can also try this:-
Open your anonymous window:-
If you find your Solution then mark this as the best answer.
Thanks and Regards
Suraj Tripathi.
And also use this code
I have tried both of your codes now I am not getting that error but it did not link the case back to opportunity.
How can I fix that? this is exactly the same behavior when I tried to use try and catch
Because I get an error "Logical operator can only be applied to Boolean"
Sorry for that. Please replace and in place of the && operator.
In case you find any other issue please mention.
If you find your Solution then mark this as the best answer.
By doing that I am getting this now:
Id =: caseData.OppToCase__c and caseData.OppToCase__c!=null limit
^
ERROR at Row:1:Column:75
Didn't understand relationship 'caseData' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
Okay you have tried this code:-
Id =: caseData.OppToCase__r and caseData.OppToCase__r!=null limit
^
ERROR at Row:1:Column:75
Didn't understand relationship 'caseData' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
Please try this code:-
And open your anonymous window:-
In case you find any other issue please mention.
If you find your Solution then mark this as the best answer.