• Fayyad Zahid
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
Hello,

I am simply trying to access a few Case fields of a Case that has been created after an Apex trigger. However, I keep getting this error: "Invalid loop variable type expected SObject was Case". I am not sure what the problem is, as other sources online that I have looked at seem to be using the same syntax/declarations that I am using. As a sidenote, I am fairly new to Apex and am still learning as I go. Please bear with me.

Here is my code:

trigger Ticket_Trigger on Case (after insert) {

    List<Id> listId = new List<Id>();
    for(Case c : Trigger.new){
        listId.add(c.Id);
    }
    
    List<Case> caseList = [SELECT Case.Id, Case.Origin, Case.ContactId, Case.AccountId, Case.Status,
                           Case.Priority, Case.Subject, Case.LastModifiedById, Case.OwnerId,
                           Case.CreatedById, Case.CreatedDate, Case.Description 
                           FROM Case 
                           WHERE Case.id IN :setId];
    
    System.debug(caseList);
}
Hello,
I am quite new to Salesforce and Apex (however I am very familiar with Java), so any help explained in simple terms would be much appreciated.

I am trying to write an Apex Trigger that will simply get the fields (shown below) of a Case on its creation. The fields I am trying to access are:

caseRecord, caseOwner, contactName, accountName, products, priority, status, caseOrigin, customerType, date/timeOpened, ticketDesc, subject, originator, reporter, primaryVendor, secondaryVendor, vendorStatus, createdBy, lastModifiedBy

I believe some of the fields may be custom fields, so I am also wondering how I would get those fields.

I would also like to get any attachments, related cases, and comments on the case, so if someone could tell me how I can access those, that would be very helpful.

 Thanks in advance to anyone who puts in the time to help answer my question!

Fayyad

 
Hello,

I am simply trying to access a few Case fields of a Case that has been created after an Apex trigger. However, I keep getting this error: "Invalid loop variable type expected SObject was Case". I am not sure what the problem is, as other sources online that I have looked at seem to be using the same syntax/declarations that I am using. As a sidenote, I am fairly new to Apex and am still learning as I go. Please bear with me.

Here is my code:

trigger Ticket_Trigger on Case (after insert) {

    List<Id> listId = new List<Id>();
    for(Case c : Trigger.new){
        listId.add(c.Id);
    }
    
    List<Case> caseList = [SELECT Case.Id, Case.Origin, Case.ContactId, Case.AccountId, Case.Status,
                           Case.Priority, Case.Subject, Case.LastModifiedById, Case.OwnerId,
                           Case.CreatedById, Case.CreatedDate, Case.Description 
                           FROM Case 
                           WHERE Case.id IN :setId];
    
    System.debug(caseList);
}