• prakher jain
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
I want to delete my question 
https://developer.salesforce.com/forums/ForumsMain?id=9062I000000XquPQAS how to delete it
I am working on rest API and display the result in a table based on check I get that value from the table and want to store it as a record
my apex class:
public class superdetailget {
    @AuraEnabled
    public static Map < String,Object > superdetails(String supername){
        Http h = new Http();
        
        // Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
        HttpRequest req = new HttpRequest();
        req.setEndpoint('https://superheroapi.com/api.php/3411824965556407/search/'+supername);
        req.setMethod('GET'); 
        // Send the request, and return a response
        HttpResponse res = h.send(req);
        System.debug('response:--> ' + res.getBody());
        
        
        // Deserialize the JSON string into collections of primitive data types.
        Map < String,Object > resultsMap = (Map < String, Object > ) JSON.deserializeUntyped(res.getBody().replace('"full-name"','"fullname"').replace('"place-of-birth"','"pob"'));
        system.debug('resultsMap-->' + resultsMap);
        Object results= resultsmap.get('results');
        System.debug(results);
        return resultsMap;
    }
    @AuraEnabled
    public static void setsuperdata(Object[] datains){
        system.debug('data'+datains);
        Integer i;
        for(Object obj :datains)
        {
        }
    }
    
    }
my handler:
({
    getsuperdetail : function(component) {
        var USDval=component.get("v.heroname");
        component.set("v.strength",USDval);
        var action = component.get("c.superdetails");
        // set the url parameter for getCalloutResponseContents method (to use as endPoint) 
        action.setParams({
            "supername": USDval,
        });
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (component.isValid() && state === "SUCCESS") {
                // set the response(return Map<String,object>) to response attribute.      
                
                // get the all rates from map by using key              
                var getAllRates = response.getReturnValue()['results'];
                var len=getAllRates.length;
                //getAllRates = getAllRates.
                console.log("aaaaa",getAllRates);
                component.set('v.herolist',getAllRates);
               
            }
        });
        
        $A.enqueueAction(action);
    },
    setsuperhero : function(component){
        var getAllCheckboxes=[];
        var insertlist=[];
        var check = component.find("checkbox");
        //getAllCheckboxes.push(check.get("v.text"));
        console.log(check);
        for (var i = 0; i < check.length; i++) {
            if(check[i].get("v.value")==true)
            {
                console.log(check[i].get("v.text"));
                getAllCheckboxes.push(check[i].get("v.text"));
            }
            
        }
        console.log(getAllCheckboxes);
        var herolists=component.get('v.herolist');
         console.log("bbbbbbb",herolists);
        for (var i = 0; i < getAllCheckboxes.length; i++) 
        {
            for(var j=0;j<herolists.length;j++)
            {
               if(herolists[j].id==getAllCheckboxes[i])
               {
                   var abc={id:herolists[j].id,name:herolists[j].name,fname:herolists[j].biography.fullname,uni:herolists[j].biography.publisher,place:herolists[j].biography.pob,power:herolists[j].powerstats.power};
                   console.log(typeof abc);
                   insertlist.push(abc);
               }
            }
        }
        console.log("insert"+insertlist);
        //var action = component.get("c.setsuperdata");
        // set the url parameter for getCalloutResponseContents method (to use as endPoint) 
        //action.setParams({
        //    "datains": insertlist,
       // });
       // $A.enqueueAction(action);
    }
})

Controller:
({
    superdetail : function(component, event, helper) {
        helper.getsuperdetail(component);
    },
    insertdetail : function(component, event, helper){
        helper.setsuperhero(component);
    }
})

lightning component:
<aura:component controller='superdetailget'>
    <aura:attribute name="heroname" type="Integer" />
    <aura:attribute name="strength" type="Integer" />
    <aura:attribute name="herolist" type="Object[]" />
    <lightning:input aura:id="lvForm" label="Name of superhero"
                     name="supername"
                     type="Text"
                     value="{!v.heroname}"
                     />
    <lightning:button variant="Success" label="Get Superhero Detail" onclick="{! c.superdetail}" />
    <table >
        <tr>
            <th>Checkbox</th>
            <th>Name</th> 
            <th>Full name</th>
            <th>Universe</th>
            <th>Place of birth</th>
            <th>Power</th>
        </tr>   
        <aura:iteration items="{!v.herolist}" var="hero">
            <tr>
                <td>
                    <ui:inputCheckbox aura:id="checkbox" value="" name="checker" text="{!hero.id}"/>
                </td>
                <td>{!hero.name}</td>
                <td>{!hero.biography.fullname}</td>
                <td>{!hero.biography.publisher}</td>
                <td>{!hero.biography.pob}</td>
                <td>{!hero.powerstats.power}</td>
            </tr>
        </aura:iteration>
    </table>
        <lightning:button variant="Success" label="Insert data" onclick="{! c.insertdetail}" />
</aura:component>

​​​​​​​
I am working on rest API and display the result in a table based on check I get that value from the table and want to store it as a record
my apex class:
public class superdetailget {
    @AuraEnabled
    public static Map < String,Object > superdetails(String supername){
        Http h = new Http();
        
        // Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
        HttpRequest req = new HttpRequest();
        req.setEndpoint('https://superheroapi.com/api.php/3411824965556407/search/'+supername);
        req.setMethod('GET'); 
        // Send the request, and return a response
        HttpResponse res = h.send(req);
        System.debug('response:--> ' + res.getBody());
        
        
        // Deserialize the JSON string into collections of primitive data types.
        Map < String,Object > resultsMap = (Map < String, Object > ) JSON.deserializeUntyped(res.getBody().replace('"full-name"','"fullname"').replace('"place-of-birth"','"pob"'));
        system.debug('resultsMap-->' + resultsMap);
        Object results= resultsmap.get('results');
        System.debug(results);
        return resultsMap;
    }
    @AuraEnabled
    public static void setsuperdata(Object[] datains){
        system.debug('data'+datains);
        Integer i;
        for(Object obj :datains)
        {
        }
    }
    
    }
my handler:
({
    getsuperdetail : function(component) {
        var USDval=component.get("v.heroname");
        component.set("v.strength",USDval);
        var action = component.get("c.superdetails");
        // set the url parameter for getCalloutResponseContents method (to use as endPoint) 
        action.setParams({
            "supername": USDval,
        });
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (component.isValid() && state === "SUCCESS") {
                // set the response(return Map<String,object>) to response attribute.      
                
                // get the all rates from map by using key              
                var getAllRates = response.getReturnValue()['results'];
                var len=getAllRates.length;
                //getAllRates = getAllRates.
                console.log("aaaaa",getAllRates);
                component.set('v.herolist',getAllRates);
               
            }
        });
        
        $A.enqueueAction(action);
    },
    setsuperhero : function(component){
        var getAllCheckboxes=[];
        var insertlist=[];
        var check = component.find("checkbox");
        //getAllCheckboxes.push(check.get("v.text"));
        console.log(check);
        for (var i = 0; i < check.length; i++) {
            if(check[i].get("v.value")==true)
            {
                console.log(check[i].get("v.text"));
                getAllCheckboxes.push(check[i].get("v.text"));
            }
            
        }
        console.log(getAllCheckboxes);
        var herolists=component.get('v.herolist');
         console.log("bbbbbbb",herolists);
        for (var i = 0; i < getAllCheckboxes.length; i++) 
        {
            for(var j=0;j<herolists.length;j++)
            {
               if(herolists[j].id==getAllCheckboxes[i])
               {
                   var abc={id:herolists[j].id,name:herolists[j].name,fname:herolists[j].biography.fullname,uni:herolists[j].biography.publisher,place:herolists[j].biography.pob,power:herolists[j].powerstats.power};
                   console.log(typeof abc);
                   insertlist.push(abc);
               }
            }
        }
        console.log("insert"+insertlist);
        //var action = component.get("c.setsuperdata");
        // set the url parameter for getCalloutResponseContents method (to use as endPoint) 
        //action.setParams({
        //    "datains": insertlist,
       // });
       // $A.enqueueAction(action);
    }
})

Controller:
({
    superdetail : function(component, event, helper) {
        helper.getsuperdetail(component);
    },
    insertdetail : function(component, event, helper){
        helper.setsuperhero(component);
    }
})

lightning component:
<aura:component controller='superdetailget'>
    <aura:attribute name="heroname" type="Integer" />
    <aura:attribute name="strength" type="Integer" />
    <aura:attribute name="herolist" type="Object[]" />
    <lightning:input aura:id="lvForm" label="Name of superhero"
                     name="supername"
                     type="Text"
                     value="{!v.heroname}"
                     />
    <lightning:button variant="Success" label="Get Superhero Detail" onclick="{! c.superdetail}" />
    <table >
        <tr>
            <th>Checkbox</th>
            <th>Name</th> 
            <th>Full name</th>
            <th>Universe</th>
            <th>Place of birth</th>
            <th>Power</th>
        </tr>   
        <aura:iteration items="{!v.herolist}" var="hero">
            <tr>
                <td>
                    <ui:inputCheckbox aura:id="checkbox" value="" name="checker" text="{!hero.id}"/>
                </td>
                <td>{!hero.name}</td>
                <td>{!hero.biography.fullname}</td>
                <td>{!hero.biography.publisher}</td>
                <td>{!hero.biography.pob}</td>
                <td>{!hero.powerstats.power}</td>
            </tr>
        </aura:iteration>
    </table>
        <lightning:button variant="Success" label="Insert data" onclick="{! c.insertdetail}" />
</aura:component>

​​​​​​​