2

Can you tell me what are the other approaches for getting the Apex(Server Side Controller) in Lightning. The Only one i know is the data.getReturnedValue(). What i want is to avoid Merging the duplicate records. For Example the apex returned a list with the same element value {marvin,marvin}. The data.getReturnedValue() will return only 1 marvin. and What i want is to return all the element value eventhough there are duplicate records.

JS CLIENT SIDE CONTROLLER

({
doInit : function(component, event, helper) {
    var action = component.get("c.GetallContacts");
    action.setCallback(this, function(data){
        component.set("v.events", data.getReturnValue()); ////<------------This Line I only know to retrieve the apex serverside controller returned value
    });
    $A.enqueueAction(action);
},
})

SERVER SIDE CONTROLLER

@AuraEnabled
Public Static List<Contact> GetallContacts(String textsearch,String EventName,String FieldSearch){ //<----- Error points here
    List<Ticket__c> ids = TicketIDget(textsearch,EventName,FieldSearch);
    Set<String> newids = new Set<String>();
    for(integer i=0; i<ids.size(); i++)
    {
        newids.add(ids[i].Booker__c);
    }
    map<Id,Contact> cmap = new map<Id,Contact>([SELECT Name FROM Contact WHERE Id IN:newids]);
    list<Contact> clist = new list<Contact>();  // changed "map" to "list"
    for(Ticket__c tc : ids){
        clist.add(cmap.get(tc.Booker__c));
    }
    return clist;
}
  • What is the return type of your getAllActiveEvents function? – martin Aug 19 '15 at 6:04
  • Please Look at my Codes again. I already edit it so that you can understand the problem – Danryl Tigol Carpio Aug 19 '15 at 6:12
3

The problem is not with the lightning component controller. The problem is with the server-side controller. If you have the same contact twice, when you put the two identical ids into a set<>, it will merge the duplicates. Try this instead:

Public Static List<Contact> GetallContacts(String textsearch,String EventName,String FieldSearch){
    List<Ticket__c> ids = TicketIDget(textsearch,EventName,FieldSearch);
    Set<String> newids = new Set<String>();
    for(integer i=0; i<ids.size(); i++)
    {
        newids.add(ids[i].Booker__c);
    }
    map<Id,Contact> cmap = new map<Id,Contact>([SELECT Name FROM Contact WHERE Id IN:newids]);
    list<Contact> clist = new list<Contact>();
    for(Ticket__c tc : ids){
        clist.add(cmap.get(tc.Booker__c));
    }
    return clist;
}
2

I have no much idea of Lightning Components but I have tried for you, can you please give try to below code:

Public Static List<String> GetallContacts(String textsearch,String EventName,String FieldSearch){
    List<Ticket__c> ids = TicketIDget(textsearch,EventName,FieldSearch);
    List<String> newids = new List<String>();
    for(integer i=0; i<ids.size(); i++)
    {
        newids.add(ids[i].Booker__c);
    }

    List <Contact> listContact= [SELECT Name FROM Contact WHERE Id IN:newids];
    List <String> result = new List<String>();
    for(Contact c : listContact){
        result.add(c.Name);
    }
return result;
}

I hope above code will solve your porblem !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.