4

The aim of this code is to set a value for the booker__c field in Ticket__c object. I am getting an error of Initial term of field expression must be a concrete SObject: List. All the Names returned to the getContactBooker() funtion will put in the Booker__c fields in Ticket__c. For Example The getContactBooker() will returned a list values of{john,martin,hannah}, These values will be put into the Booker__c field in Ticket__c so that when i call the newTicketList() it will return the {john,martin,hannah} values when i want to access the Booker__c field.

HERE IS MY CODE. IS THIS THE RIGHT WAY OF PUTTING A NEW VALUES

@AuraEnabled
Public Static List<Ticket__c> newTicketList(String textsearch,String EventName,String FieldSearch){
    List<Contact> j = getContactBooker(textsearch,EventName,FieldSearch);
    List<String> newids = new List<String>();
    for(integer i=0; i<j.size(); i++)
    {
        newids.add(j[i].Name);
    }
    List<Ticket__c> values = new List<Ticket__c>();
    for(integer i = 0; i< newids.size(); i++){
    values.Booker__c = newids[i];<--------ERROR POINTS HERE
    }
    return values;
}

1 Answer 1

4

Booker__c is the name of a field on your Ticket__c object.

The variable values is a list of tickets and not an individual ticket. What it looks like you want to do is create a new ticket for each value in the newids list and add it to the values list. You could try this:

@AuraEnabled
Public Static List<ReturnValues> newTicketList(String textsearch,String EventName,String FieldSearch){
    List<Contact> j = getContactBooker(textsearch,EventName,FieldSearch);
    List<String> newids = new List<String>();
    for(integer i=0; i<j.size(); i++) {
        newids.add(j[i].Name);
    }
    List<ReturnValues> values = new List<ReturnValues>();
    for(integer i = 0; i< newids.size(); i++){
        ReturnValues rv = new ReturnValues();
        rv.BookerName = newids[i];
        // rv.TicketHolderName = /*put name here*/
        // rv.TicketInformation = new Ticket__c(/*fieldname = fieldvalue, ...*/);
        values.add(rv);
    }
    return values;
}

public class ReturnValues{
    @AuraEnabled public String BookerName {get; set;}
    @AuraEnabled public String TicketHolderName {get; set;}
    @AuraEnabled public Ticket__c TicketInformation {get; set;}
}
32
  • yes. You get it.. But your code gives me null value Commented Aug 20, 2015 at 7:25
  • When i System.debug the values. It says Invalid ID Commented Aug 20, 2015 at 7:30
  • @DanrylTigolCarpio ah, it must be that Booker__c is a look-up to Contact and not a text field.
    – martin
    Commented Aug 20, 2015 at 7:32
  • yes .. booker is a lookup of the Contact.. its not a textfield but i get a null value Commented Aug 20, 2015 at 7:35
  • 1
    @DanrylTigolCarpio nice! glad to help.
    – martin
    Commented Aug 26, 2015 at 7:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .