i'm fetching data from soql need to insert account lookup value(accountId) and contact lookup value (ContactID) in case create from email services
here is my code:
String con_Email = envelope.fromAddress;
//write soql and checking sender email & existing email of contact same
List<Contact> conList = [SELECT Id, AccountID, Block_Email__c, Email, (SELECT AccountId, ContactId FROM cases) FROM contact WHERE email =: con_Email LIMIT 1];
//Checking list size is greater then 0 and not eqaul to null
if(conList.size()>0 && conList != null){
//if Block Email checkbox true then email will not get into salesforce
if(conList[0].Block_Email__c == true){
}
// if sender email & existing email of contact same create activity (task)
else if(conList[0].email == con_Email.trim()) {
//Creating case
Case cs = new Case();
cs.Subject = email.subject;
cs.Contact = conList[0].cases.ContactId;
cs.Account = conList[0].AccountID;
cs.Origin = 'E-Mail - FMB#1';
cs.Description = email.plainTextBody;
insert cs;
ORDER BY
clause to your inner query, and check if the list is empty as Kevan suggests.