You need to sign in to do that
Don't have an account?
Problem with SOQL query (Error: Invalid Data...List has no rows for assignment)
I am trying to populate Contract_Header_LOOKUP__c (a lookup field) with the id from Contract_Header__c (a text field)... hence, the SOQL query.
It compiles, but when I try to get it to work, I am getting this error.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger ContractLine_ContractHeaderLookupUpdate caused an unexpected exception, contact your administrator: ContractLine_ContractHeaderLookupUpdate: execution of BeforeUpdate caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.ContractLine_ContractHeaderLookupUpdate: line 7, column 1
trigger ContractLine_ContractHeaderLookupUpdate on Contract_Line__c (before update, before insert){ for (Contract_Line__c cl: Trigger.new) { if(cl.Contract_Header_LOOKUP__c == Null) { cl.Contract_Header_LOOKUP__c = [SELECT id FROM Contract_Line__c WHERE Name =: cl.Contract_Header__c].id ; } } }
This helped me (http://boards.developerforce.com/t5/Apex-Code-Development/Can-t-get-this-trigger-to-work-any-ideas-Populate-Lookup-field/m-p/341141#M60433), but I am stuck at this point...
Any help is greatly appreciated!
I needed to change the following:
[SELECT id FROM Contract_Line__c WHERE Name =: cl.Contract_Header__c].id ;
to
[SELECT id FROM Contract_Header__c WHERE Name =: cl.Contract_Header__c].id ;
All Answers
I needed to change the following:
[SELECT id FROM Contract_Line__c WHERE Name =: cl.Contract_Header__c].id ;
to
[SELECT id FROM Contract_Header__c WHERE Name =: cl.Contract_Header__c].id ;
How do I put an if catch in this?
Thanks,
Chris
like this.
if(contractHeaders.size()>0)
{
//System.debug('Chris has values to insert = '+ ContractHeaderInsert.size());//
try{
insert contractHeaders;
}catch (System.Dmlexception e)
{
system.debug (e);
}
but I don't know what to put in the if/insert statements with this code? is it necessary?
I was also told I should not put a SOQL query in a for loop...
how do i close the loop?
Thanks,
Chris