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;
}
pchittum
  • 19,701
  • 5
  • 54
  • 97
Danryl Tigol Carpio
  • 639
  • 2
  • 13
  • 25

1 Answers1

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;}
}
martin
  • 12,614
  • 9
  • 47
  • 75
  • yes. You get it.. But your code gives me null value – Danryl Tigol Carpio Aug 20 '15 at 07:25
  • When i System.debug the values. It says Invalid ID – Danryl Tigol Carpio Aug 20 '15 at 07:30
  • @DanrylTigolCarpio ah, it must be that Booker__c is a look-up to Contact and not a text field. – martin Aug 20 '15 at 07:32
  • yes .. booker is a lookup of the Contact.. its not a textfield but i get a null value – Danryl Tigol Carpio Aug 20 '15 at 07:35
  • @DanrylTigolCarpio if you want to display the name of the booker, you have a few options. You could 1 add it as a field on Contact, 2 change the return type of the function to a wrapper class that contains all of the information that you want to send to the app, 3 if you just need the name and aren't passing back anything else, you could just change the return type to be a list<String> – martin Aug 20 '15 at 07:36
  • I created a lookup field in Ticket__c called Booker__c. My problem is When i retrieve the Ticket__c field values. The Booker__c field show ID and what i want is to show the name of the contact not an ID .. thats why i came up into this code. I am very new in salesforce i dont know what to do. haha – Danryl Tigol Carpio Aug 20 '15 at 07:38
  • @DanrylTigolCarpio do you just want the booker name, or do you have other ticket information that you want to pass back? – martin Aug 20 '15 at 07:40
  • What i need to display in the Ticket__c object is the Booker__c, Ticket__Holder__c and Ticket__ID__c, Both two field are lookup to the contact. So i decided to query the name using the ids of the booker and the ticketholder after getting the names. I am planning to make a new values for booker and ticket holder and i will return it into Ticket__c list. but im struggling – Danryl Tigol Carpio Aug 20 '15 at 07:42
  • I want the ticket informations also. – Danryl Tigol Carpio Aug 20 '15 at 07:43
  • @DanrylTigolCarpio I've edited my answer. This should help get you set up. – martin Aug 20 '15 at 07:52
  • rv.TicketInformation = new Ticket__c(Ticket_ID__c = ticket[i]); gettting me an error of Field is not writeable: Ticket__c.Ticket_ID__c – Danryl Tigol Carpio Aug 20 '15 at 08:26
  • I solve the error Thankyou Martin . You are awesome – Danryl Tigol Carpio Aug 20 '15 at 08:36
  • @DanrylTigolCarpio excellent! glad I could help. – martin Aug 20 '15 at 08:38
  • You help me twice and maybe more and more and more .... hahaha :D – Danryl Tigol Carpio Aug 20 '15 at 08:41
  • Hope you can help this problem. http://salesforce.stackexchange.com/questions/89252/how-to-swap-2-different-component-views-in-lightning?noredirect=1#comment118290_89252 – Danryl Tigol Carpio Aug 25 '15 at 05:17
  • @DanrylTigolCarpio I just posted something recently that is similar to what you are trying to do. There have been a lot of questions about lightning component navigation recently and I don't know if there is an established best way to do it. If you are still looking for ideas, you might want to check this out: http://salesforce.stackexchange.com/questions/66954/how-to-navigate-from-one-lightning-component-to-another-lightning-component/89312#89312 – martin Aug 25 '15 at 13:39
  • Hi martin .. I will look your post tommorow .. i hope it will solve my problem – Danryl Tigol Carpio Aug 25 '15 at 14:55
  • I dont see any changing of view @Martin. Got me an output of all the list element has a button Go of their side. Please test your code – Danryl Tigol Carpio Aug 26 '15 at 00:16
  • @DanrylTigolCarpio okay, what happened when you pushed go? Did it take you to the list of opportunities? I might have missed something when copying to this site. – martin Aug 26 '15 at 00:56
  • @DanrylTigolCarpio also make sure the namespace gets changed to fit your org. – martin Aug 26 '15 at 01:03
  • yes.i already changed the namespace.. can you please try the code ? i am trying to find out whats the problem for this. please do so. – Danryl Tigol Carpio Aug 26 '15 at 01:09
  • @DanrylTigolCarpio It sounds like there is an issue with the event being fired. When you click on go, is there a warning message that appears on the screen? – martin Aug 26 '15 at 01:19
  • Nothing.. did you check this code before you post ?.. i guess the issue is in the component client side controller. There is no value passed to the event – Danryl Tigol Carpio Aug 26 '15 at 01:23
  • No it has value passed into the event but the ato function in the client side controller of the app not executed. i dont know what's wrong – Danryl Tigol Carpio Aug 26 '15 at 01:33
  • MAAAAAAAAAARRRRRRRTTTTTTTTTTIIIIIIIIIN ! Why is it Sometimes this line of code wont work
    AddToggle : function(component, event, helper) {
        var listeve = component.get("v.listval");
        var myEvent = $A.get("e.c:SelectEvent");
        myEvent.setParams({"sevent":  listeve});
        myEvent.fire();
    }
    
    – Danryl Tigol Carpio Aug 26 '15 at 06:41
  • I still get the same problem.. event fired but the function of the JS wont work – Danryl Tigol Carpio Aug 26 '15 at 06:42
  • @DanrylTigolCarpio I guess some other things you could check are: 1. the type of the event should be "APPLICATION" and 2. the name of the event file should be SelectEvent.evt (the name attribute of the registered event is only relevant for COMPONENT events) – martin Aug 26 '15 at 07:21
  • I solve it :) thankyou.. I dont apply your concept martin sorry. In my code i apply Toggle classes . its more faster as i thought – Danryl Tigol Carpio Aug 26 '15 at 07:23
  • @DanrylTigolCarpio what was the problem then? Did you ever get the events to work? – martin Aug 26 '15 at 07:23
  • yeah.. i already solve the event firing to work.. thanks to you.. i understand deeply the flow – Danryl Tigol Carpio Aug 26 '15 at 07:32
  • 1
    @DanrylTigolCarpio nice! glad to help. – martin Aug 26 '15 at 07:42