Skip to main content
added 842 characters in body
Source Link
Tushar Sharma
  • 29.7k
  • 7
  • 38
  • 60

This is because you declare this inside if block. SO its scope is limited to if block and you are trying to access it outside if so declare it outside of if block

Case incomingCase = new Case();
  if(toAddresses.size()>0){
     

or you can move the insert inside if statement

if(toAddresses.size()>0){
         System.debug('Inside the to Addresses.size');
         Case incomingCase = new Case();
         incomingCase.Description = email.plainTextBody;
         incomingCase.Subject = email.subject;
         incomingCase.Status= 'New';    
         incomingCase.RecordTypeId = caseComplaintRecordType;
         incomingCase.Origin ='Support Email';       
         incomingCase.ContactId = email.fromName;  

         if(email.subject.contains('Nothing')){

         }
     Database.SaveResult[]SaveResult srList = Database.insert(incomingCase, True);

  }

In first approach you need to make sure don't try to insert empty case record so it will be better if you move insert inside if block.

This is because you declare this inside if block. SO its scope is limited to if block and you are trying to access it outside if so declare it outside of if block

Case incomingCase = new Case();
  if(toAddresses.size()>0){
     

or you can move the insert inside if statement

if(toAddresses.size()>0){
         System.debug('Inside the to Addresses.size');
         Case incomingCase = new Case();
         incomingCase.Description = email.plainTextBody;
         incomingCase.Subject = email.subject;
         incomingCase.Status= 'New';    
         incomingCase.RecordTypeId = caseComplaintRecordType;
         incomingCase.Origin ='Support Email';       
         incomingCase.ContactId = email.fromName;  

         if(email.subject.contains('Nothing')){

         }
     Database.SaveResult[] srList = Database.insert(incomingCase, True);

  }

In first approach you need to make sure don't try to insert empty case record so it will be better if you move insert inside if block.

This is because you declare this inside if block. SO its scope is limited to if block and you are trying to access it outside if so declare it outside of if block

Case incomingCase = new Case();
  if(toAddresses.size()>0){
     

or you can move the insert inside if statement

if(toAddresses.size()>0){
         System.debug('Inside the to Addresses.size');
         Case incomingCase = new Case();
         incomingCase.Description = email.plainTextBody;
         incomingCase.Subject = email.subject;
         incomingCase.Status= 'New';    
         incomingCase.RecordTypeId = caseComplaintRecordType;
         incomingCase.Origin ='Support Email';       
         incomingCase.ContactId = email.fromName;  

         if(email.subject.contains('Nothing')){

         }
     Database.SaveResult srList = Database.insert(incomingCase, True);

  }

In first approach you need to make sure don't try to insert empty case record so it will be better if you move insert inside if block.

added 842 characters in body
Source Link
Tushar Sharma
  • 29.7k
  • 7
  • 38
  • 60

This is because you declare this inside if block. SO its scope is limited to if block and you are trying to access it outside if so declare it outside of if block

Case incomingCase = new Case();
  if(toAddresses.size()>0){
     

or you can move the insert inside if statement

if(toAddresses.size()>0){
         System.debug('Inside the to Addresses.size');
         Case incomingCase = new Case();
         incomingCase.Description = email.plainTextBody;
         incomingCase.Subject = email.subject;
         incomingCase.Status= 'New';    
         incomingCase.RecordTypeId = caseComplaintRecordType;
         incomingCase.Origin ='Support Email';       
         incomingCase.ContactId = email.fromName;  

         if(email.subject.contains('Nothing')){

         }
     Database.SaveResult[] srList = Database.insert(incomingCase, True);

  }

In first approach you need to make sure don't try to insert empty case record so it will be better if you move insert inside if block.

This is because you declare this inside if block. SO its scope is limited to if block and you are trying to access it outside if so declare it outside of if block

Case incomingCase = new Case();
  if(toAddresses.size()>0){
     

This is because you declare this inside if block. SO its scope is limited to if block and you are trying to access it outside if so declare it outside of if block

Case incomingCase = new Case();
  if(toAddresses.size()>0){
     

or you can move the insert inside if statement

if(toAddresses.size()>0){
         System.debug('Inside the to Addresses.size');
         Case incomingCase = new Case();
         incomingCase.Description = email.plainTextBody;
         incomingCase.Subject = email.subject;
         incomingCase.Status= 'New';    
         incomingCase.RecordTypeId = caseComplaintRecordType;
         incomingCase.Origin ='Support Email';       
         incomingCase.ContactId = email.fromName;  

         if(email.subject.contains('Nothing')){

         }
     Database.SaveResult[] srList = Database.insert(incomingCase, True);

  }

In first approach you need to make sure don't try to insert empty case record so it will be better if you move insert inside if block.

Source Link
Tushar Sharma
  • 29.7k
  • 7
  • 38
  • 60

This is because you declare this inside if block. SO its scope is limited to if block and you are trying to access it outside if so declare it outside of if block

Case incomingCase = new Case();
  if(toAddresses.size()>0){