• Sandesh Vishwakarma 9
  • NEWBIE
  • 50 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 12
    Replies
I have integrated an external application with saesforce , I created connected app for that. and used securty token for the integration with salesforce.

Now i need to deploy salesforce callout. What do i need to take care while deployment (specially connected app and security token) these two things.

A security token gets reset everytime password expires or changed. we can't make changes to the code everytime for this.
My apex code works first for the authentication with the external api and then sending a record it on update of the opportunity record in salesforce , here is apex class 
 
public class DepreciationSWGetIdUpdatedOppRecord_th {
    @future (callout=true)
    public static void makePostCalloutForAuthentication(String recId) {
        String jwtTokenAccessToken; 
        
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        // endpoint for establishing authentication with application to get the response of TOKEN 
        request.setEndpoint('callout:BasicAuthintegration/api/Accounts/authenticate');
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json;charset=UTF-8');
        // Set the body as a JSON object
        request.setBody('{ "email" : "{!$Credential.BasicAuthforDuoTaxintegration.username}", "password" : "{!$Credential.BasicAuthforDuoTaxintegration.password}"}');
        System.debug('request'+ request);
        HttpResponse response = http.send(request);
        System.debug('response'+ response);
        // Parse the JSON response
        if (response.getStatusCode() != 200) {
            System.debug('The status code returned was not expected: ' +
                         response.getStatusCode() + ' ' + response.getStatus());
        } else {
            // System.debug(response.getBody());
            Map<String , Object> responseResult = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
           // System.debug('responseResult' + responseResult);
            Map<String, Object> getDataValuesFromResponse = (Map<String, Object>) responseResult.get('data');
            //System.debug('results>>>>>>>'+ getDataValuesFromResponse.get('jwtToken'));
            jwtTokenAccessToken = (string)getDataValuesFromResponse.get('jwtToken');
            //System.debug('jwtTokenAccessToken>>>>>>>> '+ jwtTokenAccessToken);
        }
        makePostCalloutToSendRecordId(recId , jwtTokenAccessToken);
        
    }
    
    
    public static void makePostCalloutToSendRecordId(String recId , String accessToken) {
        System.debug('accessToken >>>'+ accessToken);
        String body = recId;
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        // setting the endpoint for and body inculdes the recordID 
        
        request.setEndpoint('callout:BasicAuthintegration/api/Salesforce/UpdateOppotunityMySql?id='+ body);
        request.setMethod('POST');
        request.setHeader('Content-Type', 'text');
        request.setHeader( 'token', 'Bearer ' + accessToken );
        // Set the body as a JSON object
        request.setBody(body);
        System.debug('request'+ request);
        HttpResponse response = http.send(request);
        System.debug('response'+ response);
        // Parse the JSON response 
        if (response.getStatusCode() != 200) {
            System.debug('The status code returned was not expected: ' +
                         response.getStatusCode() + ' ' + response.getStatus());
        } else {
            System.debug(response.getBody());
        } 
    } 
    
}
h i am getting 88% code coverage , but pass test are not passing saying , 

System.JSONException: Unexpected character ('S' (code 83)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]

here is my test class 
 
@isTest
public class DepreciationSWGetIdUpdatedOppRecord_test {
    
    // Define a mock HTTP response class for the first callout (authentication).
    public class MockHttpResponseAuthentication implements HttpCalloutMock {
        public HTTPResponse respond(HTTPRequest req) {
            // Create a fake response to simulate a successful authentication callout.
            HttpResponse res = new HttpResponse();
            res.setHeader('Content-Type', 'application/json');
            res.setBody('{"data":{"jwtToken":"fdsbjhifewonaldj"}}');
            res.setStatusCode(200);
            //System.debug('>>> response ' + HTTPResponse.getBody());
            return res;
        }
    }
    
    // Define a mock HTTP response class for the second callout.
    public class MockHttpResponseRecordId implements HttpCalloutMock {
        public HTTPResponse respond(HTTPRequest req) {
            // Create a fake response to simulate a successful callout for sending the record ID.
            HttpResponse res = new HttpResponse();
            res.setHeader('Content-Type', 'application/json;charset=UTF-8');
            res.setBody('Success');
            res.setStatusCode(200);
            return res;
        }
    }
    
    @isTest
    static void testOpportunityTrigger() {
        // Create a test Opportunity record (you can add more fields as needed).
        Opportunity opp = new Opportunity(Name = 'Test Opportunity', StageName = 'Prospecting' , CloseDate = System.today());
        
        // Insert the Opportunity record to trigger the callout.
        insert opp;
        
        
        // Check if the trigger logic works as expected.
        // Add assertions here to validate the trigger's behavior, if any.
        
        // Set up mock responses for the callout methods.
        
        Test.setMock(HttpCalloutMock.class, new MockHttpResponseAuthentication());
        Test.setMock(HttpCalloutMock.class, new MockHttpResponseRecordId());
        
        Test.startTest();
        
        // Call the future method for authentication.
        DepreciationSWGetIdUpdatedOppRecord_th.makePostCalloutForAuthentication(opp.Id);
           // Map<String , Object> responseResult = (Map<String, Object>) JSON.deserializeUntyped('{"data":{"jwtToken":"fdsbjhifewonaldj"}}');
           // Map<String, Object> getDataValuesFromResponse = (Map<String, Object>) responseResult.get('data');

        // Call the method for sending the record ID.
        DepreciationSWGetIdUpdatedOppRecord_th.makePostCalloutToSendRecordId(opp.Id, 'mockAccessToken');
        
        Test.stopTest();
        
        // Add assertions to verify the behavior of the callout methods, if any.
    }
}


 
User-added image


I am getting 92% coverage , not 100%
Here is my Mockup callout :


@isTest
global class BatchCalloutMock implements HttpCalloutMock {
    global HTTPResponse respond(HTTPRequest req) {
        HttpResponse res = new HttpResponse();
        res.setHeader('Content-Type', 'application/json');
        res.setBody('test');
        res.setStatusCode(200);
        res.setStatus('Sucess'); 
        return res;
    }
}


Here is my test class :-

@isTest
public class BatchClassOrderPOTestClass {
    static testMethod void testbarchClass(){
        Account newAccountRecord = new Account();
        newAccountRecord.Name = 'Test Account Record';
        insert newAccountRecord;
        Order newOrderRecord = new Order();
        newOrderRecord.AccountId = newAccountRecord.Id;
        newOrderRecord.EffectiveDate = System.today();
        newOrderRecord.Status = 'Draft';
        // insert newAccountRecord;
        insert newOrderRecord;
        List<ID> idd = new List<ID>();
        idd.add(newOrderRecord.id);
        List<Order> recordsToSend = [select id from Order WHERE ID =: newOrderRecord.Id];
        
        Test.setMock(HttpCalloutMock.class, new BatchCalloutMock());
       // Test.startTest();
        BatchClassOrderPO obj = new BatchClassOrderPO(idd);
        
        //cPO newcPO = new cPO(recordsToSend);
        database.executeBatch(obj,25);
       // Test.stopTest();
    }
    
}
public class BatchClassOrder implements Database.Batchable<ID>,Database.AllowsCallouts{
    private List<ID> recordsToSend;
    
    public BatchClassOrder(List<ID> recordsToSend){
        this.recordsToSend = recordsToSend;
    }
    public Iterable<ID> start(Database.BatchableContext BC){
        return recordsToSend;
    }
    public void execute(Database.BatchableContext BC, List<ID> records){
        String errormsg;
        String body;
        String responsee;
        string status;
        String Method = 'POST';
        for(ID rec : records) {
            List<Order> recc = [select id , name from Order where id = :rec];
            BatchClassOrder.cPO_main newObjj = new BatchClassOrder.cPO_main(recc);
            body = JSON.serialize(newObjj);
            body= '[' + body+ ']';
            System.debug('body' + body);
            String endpoint; 
            System.debug('body' + body);
            try {                 
                HttpRequest req = new HttpRequest();
                HttpResponse res = new HttpResponse();
                Http http = new Http();
               
                endpoint = 'https://xxxxx-xxx.xxx.xx.xx/xxx/xx';
               
                req.setHeader('client_id','xxxxxxxxxxxxxxxxx');
                req.setHeader('client_secret','xxxxxxxxxxxxxxxxx');
                req.setHeader('Content-Type', 'application/json');
                req.setEndpoint(endpoint);
                req.setMethod('POST');
                req.setBody(body);               
                if (!Test.isRunningTest()) {     
                    res = http.send(req);
                    responsee = res.getBody();
                    System.debug('getStatusCode' + res.getStatusCode());
                    if(res.getStatusCode() == 200){
                        status = 'Success';
                    }
                    else{
                       status = 'Error';
                    }
                   
                    System.debug('Str:' + res.getStatusCode());
                }            
            }
            catch (Exception e) {        
                System.debug('Error:' + e.getMessage() + 'LN:' + e.getLineNumber() ); 
                errormsg = e.getMessage();
            }
           
        }
        String className = 'BatchClassOrder';
        String API_Name  = 'APINAME';
        String Description = 'Description';
        String Error_code_c =  errormsg;
        String Request_Type_c = 'Outbound';
        String Request_c = body ;
        String Response_c = responsee;
        String Status_c = status;
        datetime Start_time_c;
        datetime End_time_c;
        Decimal duration;
        datetime Createddate;
        LoggingDetails loggingdetailsObj = new LoggingDetails();   //It is new class that has a method that saves this information into a object
        loggingdetailsObj.mainMethod(className,API_Name,Description,Error_code_c,Request_Type_c,Request_c,Response_c,Status_c,Start_time_c,End_time_c,duration,Createddate);
       
    }
    public void finish(Database.BatchableContext BC){
    }


// Constructor that sets the values into a request body JSON
  public class cPO_main {
                              public String name;
public cPo_main(List<order> recList){
               for(Order o : recList){
name = o.Name;
}
}
}
   
 
Scenario : Anytime an account is created or updated a BATCH class should be called where a HTTP POST callout will initiate and it will send the all field values of that account record to that external webApplication.

Here is what I've tried
Trigger :

trigger AccountTrigger on Account (after insert, after update) {
    // Create a list to hold the accounts that have been inserted or updated
    List<Account> accounts = new List<Account>();
    
    // Check if the trigger was fired due to an insert
    if (Trigger.isInsert) {
        // Add all of the newly inserted accounts to the list
        accounts.addAll(Trigger.new);
    }
    
    // Check if the trigger was fired due to an update
    if (Trigger.isUpdate) {
        // Add all of the updated accounts to the list
        accounts.addAll(Trigger.new);
    }
    
    // Check if there are any accounts in the list
    if (!accounts.isEmpty()) {
        // Call the batch class, passing the list of accounts as a parameter
        BatchClass.sendAccountsToExternalWebsite(accounts);
    }
}


--------------------------------------------------------------------------------------------
Please someone help me out in writing batch apex class for this.
Thank you
Apex Trigger :-


trigger TruckSupplyActual on Truck_Supply_Actual__c (after insert, after update) {
    if(Trigger.isAfter && Trigger.isInsert) 
    {
        TriggerHandler.insertRecord(Trigger.new);
    }
    if(Trigger.isBefore || Trigger.isAfter && Trigger.isUpdate )
    {
        TriggerHandler.updateRecord(Trigger.newMap, Trigger.oldMap);
    }
}

--------------------------------------------------------------------------------------------------------------


Apex Handler Class :-


public class TriggerHandler {
    public static void insertRecord(list<Truck_Supply_Actual__c> recordList ){
        list<Truck_Supply_Booking__c> truckSupplyBookinggList = new list<Truck_Supply_Booking__c>();
        for(Truck_Supply_Actual__c a : recordList){
            if(a.Amount__c != null){
                Decimal i = a.Amount__c;
                for(Integer j=1;j<=i;j++){
                    Truck_Supply_Booking__c truckSupplyBookingList = new Truck_Supply_Booking__c();
                    truckSupplyBookingList.Truck_Supply_Actual__c = a.ID;
                    truckSupplyBookingList.Date__c = system.today();
                    truckSupplyBookingList.Status__c = 'Available';
                    truckSupplyBookingList.truck__c = a.Truck__c;
                    truckSupplyBookinggList.add(truckSupplyBookingList);
                    
                }
            }
              insert truckSupplyBookinggList;
        }    
    }
    
    public static void updateRecord(Map<id,Truck_Supply_Actual__c> newValues , Map <id,Truck_Supply_Actual__c> oldValues){
        list<Truck_Supply_Booking__c> truckSupplyBookinggList = new list<Truck_Supply_Booking__c>(); 
        for(Truck_Supply_Actual__c a : newValues.values())
        { 
            if(oldValues.get(a.Id).Additional_Amount__c != newValues.get(a.Id).Additional_Amount__c)
            {    
                Truck_Supply_Actual__c record = [Select Id, Additional_Amount__c From Truck_Supply_Actual__c WHERE id =: a.Id]; 
                record.Additional_1_Created__c = true;
                update record;
                Decimal i = newValues.get(a.Id).Additional_Amount__c;
                for(Integer j=1;j<=i;j++){
                    Truck_Supply_Booking__c truckSupplyBookingList = new Truck_Supply_Booking__c();
                    truckSupplyBookingList.Truck_Supply_Actual__c = a.Id;
                    truckSupplyBookingList.Date__c = a.Date__c;
                    truckSupplyBookingList.Status__c = 'Available';
                    truckSupplyBookingList.truck__c = a.Truck__c;
                    truckSupplyBookinggList.add(truckSupplyBookingList);
                }
            }
            
            // -------------------------------- 2 -----------------------------------
            
             if(oldValues.get(a.Id).Additional_Amount_2__c != newValues.get(a.Id).Additional_Amount_2__c)
            {    
                Truck_Supply_Actual__c recordd = [Select Id, Additional_Amount_2__c From Truck_Supply_Actual__c WHERE id =: a.Id]; 
                recordd.Additional_2_Created__c = true;
                update recordd;
                Decimal i = newValues.get(a.Id).Additional_Amount_2__c;
                for(Integer j=1;j<=i;j++){
                    Truck_Supply_Booking__c truckSupplyBookingList = new Truck_Supply_Booking__c();
                    truckSupplyBookingList.Truck_Supply_Actual__c = a.Id;
                    truckSupplyBookingList.Date__c = a.Date__c;
                    truckSupplyBookingList.Status__c = 'Available';
                    truckSupplyBookingList.truck__c = a.Truck__c;
                    truckSupplyBookinggList.add(truckSupplyBookingList);
                }
            }
            
            //------------------------------------- 3 ----------------------------
            
                         if(oldValues.get(a.Id).Additional_Amount_3__c != newValues.get(a.Id).Additional_Amount_3__c)
            {    
                Truck_Supply_Actual__c recordd = [Select Id, Additional_Amount_3__c From Truck_Supply_Actual__c WHERE id =: a.Id]; 
                recordd.Additional_3_Created__c = true;
                update recordd;
                Decimal i = newValues.get(a.Id).Additional_Amount_3__c;
                for(Integer j=1;j<=i;j++){
                    Truck_Supply_Booking__c truckSupplyBookingList = new Truck_Supply_Booking__c();
                    truckSupplyBookingList.Truck_Supply_Actual__c = a.Id;
                    truckSupplyBookingList.Date__c = a.Date__c;
                    truckSupplyBookingList.Status__c = 'Available';
                    truckSupplyBookingList.truck__c = a.Truck__c;
                    truckSupplyBookinggList.add(truckSupplyBookingList);
                }
            }
            
        }
        insert truckSupplyBookinggList;
    }
}
public class OpportunityToBeSent {
    @future (callout=true)
    public static void makePostCallout(String recId) {
        String token; 
        //        System.debug('recorddIdd' + recorddIdd);
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        
        request.setEndpoint('https://XXXXXXXXXXXXXXXXXXXX/authenticate');
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json;charset=UTF-8');
        // Set the body as a JSON object
        request.setBody('{"email": "XXXXX@XXXX.com","password": "XXXXXX"}');
        System.debug('request'+ request);
        HttpResponse response = http.send(request);
        System.debug('response'+ response);
        // Parse the JSON response
        if (response.getStatusCode() != 200) {
            System.debug('The status code returned was not expected: ' +
                         response.getStatusCode() + ' ' + response.getStatus());
        } else {
            System.debug(response.getBody());
            Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
            Map<String, Object> m2 = (Map<String, Object>) results.get('data');
            System.debug('results'+ m2.get('jwtToken'));
            token = (string)m2.get('jwtToken');
            System.debug('token '+ token);
        }
        makePostCalloutt(recId , token);
        
    }
    
    
    public static void makePostCalloutt(String recId , String tokenn) {
        System.debug('Token >>>'+ tokenn);
      
        String body = recId;
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        
        request.setEndpoint('https://XXXXXXXXXXXXXXXX?id='+ body);
        request.setMethod('POST');
        request.setHeader('Content-Type', 'text');
        request.setHeader( 'token', 'Bearer ' + tokenn );
        // Set the body as a JSON object
        request.setBody(body);
        System.debug('request'+ request);
        HttpResponse response = http.send(request);
        System.debug('response'+ response);
        // Parse the JSON response
        if (response.getStatusCode() != 200) {
            System.debug('The status code returned was not expected: ' +
                         response.getStatusCode() + ' ' + response.getStatus());
        } else {
            System.debug(response.getBody());
        }
        
    }    
}
TASK : I want to send the recordId of the updated Opportunity record whenever it is updated. I want to send it to external web service , my code is working and fulfilling my requirement but have a look at it once. 

I first got the updated Opportunity recirdId from trigger then I called my first callout where I got the 'Token' , and then I called the secod method where I send the recordId.


Please examine this code. Thanks in advance 

public class OpportunityToBeSent {
    @future (callout=true)
    public static void makePostCallout(String recId) {
        String token; 
        //        System.debug('recorddIdd' + recorddIdd);
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        
        request.setEndpoint('https://XXXXXXXXXXXXXXXXXXXX/authenticate');
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json;charset=UTF-8');
        // Set the body as a JSON object
        request.setBody('{"email": "XXXXX@XXXX.com","password": "XXXXXX"}');
        System.debug('request'+ request);
        HttpResponse response = http.send(request);
        System.debug('response'+ response);
        // Parse the JSON response
        if (response.getStatusCode() != 200) {
            System.debug('The status code returned was not expected: ' +
                         response.getStatusCode() + ' ' + response.getStatus());
        } else {
            System.debug(response.getBody());
            Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
            Map<String, Object> m2 = (Map<String, Object>) results.get('data');
            System.debug('results'+ m2.get('jwtToken'));
            token = (string)m2.get('jwtToken');
            System.debug('token '+ token);
        }
        makePostCalloutt(recId , token);
        
    }
    
    
    public static void makePostCalloutt(String recId , String tokenn) {
        System.debug('Token >>>'+ tokenn);
      
        String body = recId;
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        
        request.setEndpoint('https://XXXXXXXXXXXXXXXX?id='+ body);
        request.setMethod('POST');
        request.setHeader('Content-Type', 'text');
        request.setHeader( 'token', 'Bearer ' + tokenn );
        // Set the body as a JSON object
        request.setBody(body);
        System.debug('request'+ request);
        HttpResponse response = http.send(request);
        System.debug('response'+ response);
        // Parse the JSON response
        if (response.getStatusCode() != 200) {
            System.debug('The status code returned was not expected: ' +
                         response.getStatusCode() + ' ' + response.getStatus());
        } else {
            System.debug(response.getBody());
        }
        
    }    
}
I have created a trigger to get the ID of the recently updated Opportunity record , Now How can I send this ID via REST API to external web application of .Net

Thanks in advance
I want to send the ID of the opportunity record just got updated to the external web service. How can I do it please help me . Thanks
I want to send the Opportunity record ID to an external web server whenever the opportunity record is updated so that they can perform opertions on their database to update the same record there as well.

I have written a trigger to get the recordID of thr updated record. Now I want to send it to the external web server please help me out. Thank you


trigger GetUpdatedOpportunityID on Opportunity (before update) {
        Set<Id> allInsertedIds = trigger.newMap.keySet();
        system.debug('allInsertedIds--------------------------------' + allInsertedIds);

}
 
public class OpportunityFetchField {
    
    @AuraEnabled
    public static list<Opportunity> insertOpportunity(list<Opportunity> oplist, ID ContactId, map<string, string> newObj){
        Contact rec = [SELECT ID ,Name from Contact where ID =: ContactId];
        system.debug('rec '+rec);
        system.debug('oplist '+oplist);
        system.debug('newObj '+newObj);
        for(Opportunity op :oplist){
            op.ContactId = rec.Id;
            op.StageName='Needs Analysis';
        }
        // op.Name= rec.Name;
        //op.CloseDate = Date.today();
        ///***************/
        Integer numberOfRelatedRecords = 0;
        //  Integer SessionNumber = 0;
        List<engageFI_Retail__c> eFIR = [SELECT ID , Name from engageFI_Retail__c where Contact_Name__c =: ContactId];
        System.debug('engageFI_Retail__c---->'+ eFIR);
        System.debug('Size------>'+ eFIR.size());

        
        if(eFIR.size()==5){
            /*----------------------------------------*/
            engageFI_Retail__c eFIRR =  [SELECT id , Name ,Contact_Name__c from engageFI_Retail__c where Contact_Name__c =: ContactId order by createdDate ASC limit 1];
            System.debug('eFIRR--------------'+eFIRR);
            delete eFIRR;
            /*-----------------------------------------*/
            engageFI_Retail__c er = new engageFI_Retail__c();
            
            if(newObj.containskey('BANK_CONVENIENCE__c')){
                er.BANK_CONVENIENCE__c = newObj.get('BANK_CONVENIENCE__c');
            }
            if(newObj.containskey('BANK_COST_EFFECTIVENESS__c')){
                er.BANK_COST_EFFECTIVENESS__c = newObj.get('BANK_COST_EFFECTIVENESS__c');
            }
            if(newObj.containskey('BANK_YIELD__c')){
                er.BANK_YIELD__c = newObj.get('BANK_YIELD__c');
            }
            if(newObj.containskey('BORROW_ACCESS_TO_LIQUIDITY__c')){
                er.BORROW_ACCESS_TO_LIQUIDITY__c = newObj.get('BORROW_ACCESS_TO_LIQUIDITY__c');
            }
            if(newObj.containskey('BORROW_CREDIT_CARDS__c')){
                er.BORROW_CREDIT_CARDS__c = newObj.get('BORROW_CREDIT_CARDS__c');
            }
            if(newObj.containskey('BORROW_DEBT_RESTRUCTURE__c')){
                er.BORROW_DEBT_RESTRUCTURE__c = newObj.get('BORROW_DEBT_RESTRUCTURE__c');
            }
            if(newObj.containskey('PLAN_EMERGENCY_FUND__c')){
                er.PLAN_EMERGENCY_FUND__c = newObj.get('PLAN_EMERGENCY_FUND__c');
            }
            if(newObj.containskey('PLAN_MAJOR_PURCHASES__c')){
                er.PLAN_MAJOR_PURCHASES__c = newObj.get('PLAN_MAJOR_PURCHASES__c');
            }
            if(newObj.containskey('PLAN_RETIREMENT__c')){
                er.PLAN_RETIREMENT__c = newObj.get('PLAN_RETIREMENT__c');
            }
            if(newObj.containskey('PROTECT_ACCOUNT_PROTECTION__c')){
                er.PROTECT_ACCOUNT_PROTECTION__c = newObj.get('PROTECT_ACCOUNT_PROTECTION__c');
            }
            if(newObj.containskey('PROTECT_ESTATE_PLANNING__c')){
                er.PROTECT_ESTATE_PLANNING__c = newObj.get('PROTECT_ESTATE_PLANNING__c');
            }
            if(newObj.containskey('PROTECT_INSURANCE_COVERAGES__c')){
                er.PROTECT_INSURANCE_COVERAGES__c = newObj.get('PROTECT_INSURANCE_COVERAGES__c');
            }  
            er.Scores__c = newObj.get('score');
            er.Contact_Name__c = rec.id;
            String datee = system.now().format('yyyy-MM-dd HH:mm');
            er.Name = rec.Name + ' - ' + datee ;
            insert er;
            
        }
        else if(eFIR.size()<5){
            engageFI_Retail__c er = new engageFI_Retail__c();
            
            if(newObj.containskey('BANK_CONVENIENCE__c')){
                er.BANK_CONVENIENCE__c = newObj.get('BANK_CONVENIENCE__c');
            }
            if(newObj.containskey('BANK_COST_EFFECTIVENESS__c')){
                er.BANK_COST_EFFECTIVENESS__c = newObj.get('BANK_COST_EFFECTIVENESS__c');
            }
            if(newObj.containskey('BANK_YIELD__c')){
                er.BANK_YIELD__c = newObj.get('BANK_YIELD__c');
            }
            if(newObj.containskey('BORROW_ACCESS_TO_LIQUIDITY__c')){
                er.BORROW_ACCESS_TO_LIQUIDITY__c = newObj.get('BORROW_ACCESS_TO_LIQUIDITY__c');
            }
            if(newObj.containskey('BORROW_CREDIT_CARDS__c')){
                er.BORROW_CREDIT_CARDS__c = newObj.get('BORROW_CREDIT_CARDS__c');
            }
            if(newObj.containskey('BORROW_DEBT_RESTRUCTURE__c')){
                er.BORROW_DEBT_RESTRUCTURE__c = newObj.get('BORROW_DEBT_RESTRUCTURE__c');
            }
            if(newObj.containskey('PLAN_EMERGENCY_FUND__c')){
                er.PLAN_EMERGENCY_FUND__c = newObj.get('PLAN_EMERGENCY_FUND__c');
            }
            if(newObj.containskey('PLAN_MAJOR_PURCHASES__c')){
                er.PLAN_MAJOR_PURCHASES__c = newObj.get('PLAN_MAJOR_PURCHASES__c');
            }
            if(newObj.containskey('PLAN_RETIREMENT__c')){
                er.PLAN_RETIREMENT__c = newObj.get('PLAN_RETIREMENT__c');
            }
            if(newObj.containskey('PROTECT_ACCOUNT_PROTECTION__c')){
                er.PROTECT_ACCOUNT_PROTECTION__c = newObj.get('PROTECT_ACCOUNT_PROTECTION__c');
            }
            if(newObj.containskey('PROTECT_ESTATE_PLANNING__c')){
                er.PROTECT_ESTATE_PLANNING__c = newObj.get('PROTECT_ESTATE_PLANNING__c');
            }
            if(newObj.containskey('PROTECT_INSURANCE_COVERAGES__c')){
                er.PROTECT_INSURANCE_COVERAGES__c = newObj.get('PROTECT_INSURANCE_COVERAGES__c');
            }  
            er.Scores__c = newObj.get('score');
            er.Contact_Name__c = rec.id;
            String datee = system.now().format('yyyy-MM-dd HH:mm');
            er.Name = rec.Name + ' - ' + datee ;
            insert er;
        }
        /****************/
        System.debug('ContactId' + ContactId);
        insert oplist;
        system.debug('oplist '+oplist);
        return oplist;
    }
    
    @AuraEnabled
    public static map<Id,engageFI_Retail__c > fetchEngageFIRetailRecentRecord(ID ContactIdd){
        System.debug('ContactIdd------'+ContactIdd);
        map<Id,engageFI_Retail__c > RecordMap = new Map<id,engageFI_Retail__c >();
        
        list<engageFI_Retail__c> eFIRRelatedRecord =  [SELECT id , Name ,BANK_CONVENIENCE__c,BANK_COST_EFFECTIVENESS__c,BANK_YIELD__c,
                                                       BORROW_ACCESS_TO_LIQUIDITY__c ,BORROW_CREDIT_CARDS__c,BORROW_DEBT_RESTRUCTURE__c,
                                                       PLAN_EMERGENCY_FUND__c,PLAN_MAJOR_PURCHASES__c,PLAN_RETIREMENT__c,
                                                       PROTECT_ACCOUNT_PROTECTION__c,PROTECT_ESTATE_PLANNING__c,PROTECT_INSURANCE_COVERAGES__c,
                                                       Scores__c,
                                                       Contact_Name__c,CreatedDate from engageFI_Retail__c where Contact_Name__c =: ContactIdd order by createdDate DESC limit 1];
        for(engageFI_Retail__c  RE : eFIRRelatedRecord ){
            RecordMap.put(Re.Id,Re);
            system.Debug('***'+RecordMap.values());
        }
        
        return RecordMap;
    }
    
}
public class OpportunityFetchField {
    
    @AuraEnabled
    public static list<Opportunity> insertOpportunity(list<Opportunity> oplist, ID ContactId){
        Contact rec = [SELECT ID ,Name from Contact where ID =: ContactId];
        system.debug('rec '+rec);
        system.debug('oplist '+oplist);
        for(Opportunity op :oplist){
            op.ContactId = rec.Id;
            op.StageName='Needs Analysis';
        }
        System.debug('ContactId' + ContactId);
        insert oplist;
        system.debug('oplist '+oplist);
        return oplist;
    }    
}
I have 2 slds box , In one I have 3 tect values now I want to drag 2 of them into second slds box and then have to save those two values into two different fields of the opportunity object.

[It is working fine till drag and drop onto another slds box now i want to save those 2 values into Opportunity object's 2 different fields.]

Here si my code 
Aura Component:-

<aura:component implements="force:appHostable">
    <aura:attribute name="startId" type="string"/>
    <aura:attribute name="parentId" type="string"/>
    
    <div class="slds-box" id="div1" ondrop="{!c.drop}" ondragover="{!c.allowDrop}">
        <h2 draggable="true" ondragstart="{!c.drag}" id="drag1" width="88" height="31"> Hiii</h2>
        <h2 draggable="true" ondragstart="{!c.drag}" id="drag2" width="88" height="31"> Hello</h2>
        <h2 draggable="true" ondragstart="{!c.drag}" id="drag3" width="88" height="31"> Hello There</h2>
        
    </div>
    
    
    
    <div class="slds-box" id="div3" ondrop="{!c.drop}" ondragover="{!c.allowDrop}"><span id="drag3"> </span></div>
    
</aura:component>
********************************************************************************************************
JS Controller :-

({
    allowDrop: function(cmp, event, helper){
        event.preventDefault();
    },
    drag: function(cmp, ev, helper){
          var parentId = document.getElementById(ev.target.id).parentElement.id;
       cmp.set("v.startId",ev.target.id);
       cmp.set("v.parentId",parentId);
    },
    drop: function(cmp, ev, helper){
        var drag = cmp.get("v.startId");
        var div = ev.target.id;
        alert(div);
        var fragment = document.createDocumentFragment();
        alert(fragment);
        fragment.appendChild(document.getElementById(drag));
        document.getElementById(div).appendChild(fragment);
        var c = document.getElementById(div).children;
        var x = document.getElementById('drag1').parentElement.id;
        var fragment = document.createDocumentFragment();
        fragment.appendChild(document.getElementById(c[0].id));
        document.getElementById(cmp.get("v.parentId")).appendChild(fragment);
    }
})
I am creating a lightning component where i have to I have iterated over list of Radio button results with label.

Now what i want to do is to Have a drag and drop functionality on those selected results from where i only want to choose only 5 of those 12 radio results , and then save those 5 into  5 different text fields of an object.

Here is my aura component code:-

<aura:component controller="OpportunityFetchField">
    <aura:attribute name="newOpportunity" type="Opportunity"
                    default="{ 'sobjectType': 'Opportunity',
                             'Name': '',
                             'StageName' :'',
                             'CloseDate' : '',
                             'Priority_1__c' :'',
                             'Priority_2__c' : '',
                             'Priority_Date_1__c' : '',
                             'Priority_Date_1__c' : ''
                             }"/>
    <aura:attribute name="stageList" type="List"/>
    <aura:attribute name="objName" type="String" default="Opportunity"/>
    <aura:attribute name="fldName" type="String" default="StageName"/>
    <aura:attribute name="today" type="Date" default=""/>
    <aura:attribute name="listOne" type="List" default="['CONVENIENCE','COST-EFFECTIVENESS', 'YIELD']"/>
    <aura:attribute name="listTwo" type="List" default="['CREDIT CARDS','DEBT RESTRUCTURE', 'ACCESS TO LIQUIDITY']"/>
    <aura:attribute name="listThree" type="List" default="['EMERGENCY FUND','MAJOR PURCHASES ', 'RETIREMENT']"/>
    <aura:attribute name="listFour" type="List" default="['ACCOUNT PROTECTION','INSURANCE COVERAGES', 'ESTATE PLANNING']"/>
    
    <aura:attribute name="selectedList" type="List"/>    
    <aura:attribute name="buttonSelected" type="String" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    
    <div class="slds-page-header">
        <!-- COMPANY LOGO -->
    </div>
    
    <div class="tab">
        <div class="slds-col slds-size_1-of-12">
            
            <div><lightning:button variant="{!v.buttonSelected == 'A' ? 'brand':'neutral'}" label="BANK" name="A" onclick="{!c.buttonHandler}"/> </div>
            <div><lightning:button variant="{!v.buttonSelected == 'B' ? 'brand':'neutral'}" label="BORROW" name="B" onclick="{!c.buttonHandler}"/> </div>
            <div><lightning:button variant="{!v.buttonSelected == 'C' ? 'brand':'neutral'}" label="PLAN" name="C" onclick="{!c.buttonHandler}"/> </div>
            <div><lightning:button variant="{!v.buttonSelected == 'D' ? 'brand':'neutral'}" label="PROTECT" name="D" onclick="{!c.buttonHandler}"/> </div> 
            <div><lightning:button variant="{!v.buttonSelected == 'E' ? 'brand':'neutral'}" label="PRIORITIZE" name="E" onclick="{!c.buttonHandler}"/> </div>
            
        </div>
    </div>
    
    <div class="slds-col slds-size_3-of-12">
        <aura:if isTrue="{!v.buttonSelected == 'A'}">
            <table>
                <thead>
                    <tr>
                        <th></th>
                        <th>Yes</th> 
                        <th>No</th>
                        <th>Don't Know</th>
                    </tr>
                </thead>
                <tbody>
                    <aura:iteration items="{!v.listOne}" var="item">
                        <tr>
                            <td><strong>{!item}</strong></td>
                            
                            <td><input type="radio" name="{!item}" value="Yes"  onchange="{!c.radioHandler}"/></td>
                            <td><input type="radio" name="{!item}" value="No"  onchange="{!c.radioHandler}"/></td>
                            <td><input type="radio" name="{!item}" value="Don't Know"  onchange="{!c.radioHandler}"/></td>
                            
                        </tr>
                    </aura:iteration>
                    
                </tbody>
            </table>
        </aura:if>
        <aura:if isTrue="{!v.buttonSelected == 'B'}">
            <table>
                <thead>
                    <tr>
                        <th></th>
                        <th>Yes</th> 
                        <th>No</th> 
                        <th>Don't Know</th>
                    </tr>
                </thead>
                <tbody>
                    <aura:iteration items="{!v.listTwo}" var="item">
                        <tr>
                            <td><strong>{!item}</strong></td>
                            <td><input type="radio" name="{!item}" value="Yes" onchange="{!c.radioHandler}"/></td>
                            <td><input type="radio" name="{!item}" value="No" onchange="{!c.radioHandler}"/></td>
                            <td><input type="radio" name="{!item}" value="Don't Know" onchange="{!c.radioHandler}"/></td> 
                        </tr>
                    </aura:iteration>
                </tbody>
            </table>
        </aura:if>
        <aura:if isTrue="{!v.buttonSelected == 'C'}">
            <table>
                <thead>
                    <tr>
                        <th></th>
                        <th>Yes</th> 
                        <th>No</th>
                        <th>Don't Know</th>
                    </tr>
                </thead>
                <tbody>
                    <aura:iteration items="{!v.listThree}" var="item">
                        <tr>
                            <td><strong>{!item}</strong></td>
                            <td><input type="radio" name="{!item}" value="Yes" onchange="{!c.radioHandler}"/></td>
                            <td><input type="radio" name="{!item}" value="No" onchange="{!c.radioHandler}"/></td>
                            <td><input type="radio" name="{!item}" value="Don't Know" onchange="{!c.radioHandler}"/></td> 
                        </tr>
                    </aura:iteration>
                </tbody>
            </table>
        </aura:if>
        
        <aura:if isTrue="{!v.buttonSelected == 'D'}">
            <table>
                <thead>
                    <tr>
                        <th></th>
                        <th>Yes</th> 
                        <th>No</th> 
                        <th>Don't Know</th>
                    </tr>
                </thead>
                <tbody>
                    <aura:iteration items="{!v.listFour}" var="item">
                        <tr>
                            <td><strong>{!item}</strong></td>
                            <td><input type="radio" name="{!item}" value="Yes" onchange="{!c.radioHandler}"/></td>
                            <td><input type="radio" name="{!item}" value="No" onchange="{!c.radioHandler}"/></td>
                            <td><input type="radio" name="{!item}" value="Don't Know" onchange="{!c.radioHandler}"/></td>  
                        </tr>
                    </aura:iteration>
                </tbody>
            </table>
        </aura:if>
    </div>
    
    
    <!--  Here is the code of Iterated values of All Radio Buttons  -->    
    <aura:if isTrue="{!v.buttonSelected == 'E'}">  
        <div class="sourcebox">
            
            <h3><strong>PRIORITIZE</strong></h3> <br></br><br></br>
            
            <aura:iteration items="{!v.selectedList}" var="item">
                <div  ondragstart="{!c.dragStart}" ondragover="{!c.allowDrop}" draggable="true" id="drag1">  
                    {!item.label} - {!item.value}
                </div>
                <br></br>
            </aura:iteration>
        </div>

*****************************************************************************************
JS Controller:-
  
    dragStart : function(component, event, helper){
        // console.log(event.target.id);
        // event.currentTarget.style.border = "dashed";
        event.dataTransfer.setData("text", event.target.id);
    },
    allowDrop : function(component, event, helper){
        event.preventDefault();
    },
    OnNewDrop : function(component, event, helper){
        var data = event.dataTransfer.getData("text");
        alert(data);
        // var texteSelectionne = document.createTextNode(data);
        // event.target.appendChild(texteSelectionne);
        
        event.target.appendChild(document.getElementById(data));
        event.dataTransfer.clearData();
        
    }
Here is the scenario where I am seeking help from our community,

I have 10 radio group buttons now then what i need to do is on a click of a perticular button lets say 'SHOW RESULT' all the results should be shown of above all 10 radio groups WITH THEIR LABELS (eg. = Do you use credit card - Yes) that way. then on all those 10 results i want to create a drag and drop where i can only choose 5 of them. Then i need to save all these 5 into our lead object fileds.

Please help me out.
Thanks in advance

[I have done till creating radio groups and storing them into a list and theniterated over the list]
 
My apex code works first for the authentication with the external api and then sending a record it on update of the opportunity record in salesforce , here is apex class 
 
public class DepreciationSWGetIdUpdatedOppRecord_th {
    @future (callout=true)
    public static void makePostCalloutForAuthentication(String recId) {
        String jwtTokenAccessToken; 
        
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        // endpoint for establishing authentication with application to get the response of TOKEN 
        request.setEndpoint('callout:BasicAuthintegration/api/Accounts/authenticate');
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json;charset=UTF-8');
        // Set the body as a JSON object
        request.setBody('{ "email" : "{!$Credential.BasicAuthforDuoTaxintegration.username}", "password" : "{!$Credential.BasicAuthforDuoTaxintegration.password}"}');
        System.debug('request'+ request);
        HttpResponse response = http.send(request);
        System.debug('response'+ response);
        // Parse the JSON response
        if (response.getStatusCode() != 200) {
            System.debug('The status code returned was not expected: ' +
                         response.getStatusCode() + ' ' + response.getStatus());
        } else {
            // System.debug(response.getBody());
            Map<String , Object> responseResult = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
           // System.debug('responseResult' + responseResult);
            Map<String, Object> getDataValuesFromResponse = (Map<String, Object>) responseResult.get('data');
            //System.debug('results>>>>>>>'+ getDataValuesFromResponse.get('jwtToken'));
            jwtTokenAccessToken = (string)getDataValuesFromResponse.get('jwtToken');
            //System.debug('jwtTokenAccessToken>>>>>>>> '+ jwtTokenAccessToken);
        }
        makePostCalloutToSendRecordId(recId , jwtTokenAccessToken);
        
    }
    
    
    public static void makePostCalloutToSendRecordId(String recId , String accessToken) {
        System.debug('accessToken >>>'+ accessToken);
        String body = recId;
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        // setting the endpoint for and body inculdes the recordID 
        
        request.setEndpoint('callout:BasicAuthintegration/api/Salesforce/UpdateOppotunityMySql?id='+ body);
        request.setMethod('POST');
        request.setHeader('Content-Type', 'text');
        request.setHeader( 'token', 'Bearer ' + accessToken );
        // Set the body as a JSON object
        request.setBody(body);
        System.debug('request'+ request);
        HttpResponse response = http.send(request);
        System.debug('response'+ response);
        // Parse the JSON response 
        if (response.getStatusCode() != 200) {
            System.debug('The status code returned was not expected: ' +
                         response.getStatusCode() + ' ' + response.getStatus());
        } else {
            System.debug(response.getBody());
        } 
    } 
    
}
h i am getting 88% code coverage , but pass test are not passing saying , 

System.JSONException: Unexpected character ('S' (code 83)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]

here is my test class 
 
@isTest
public class DepreciationSWGetIdUpdatedOppRecord_test {
    
    // Define a mock HTTP response class for the first callout (authentication).
    public class MockHttpResponseAuthentication implements HttpCalloutMock {
        public HTTPResponse respond(HTTPRequest req) {
            // Create a fake response to simulate a successful authentication callout.
            HttpResponse res = new HttpResponse();
            res.setHeader('Content-Type', 'application/json');
            res.setBody('{"data":{"jwtToken":"fdsbjhifewonaldj"}}');
            res.setStatusCode(200);
            //System.debug('>>> response ' + HTTPResponse.getBody());
            return res;
        }
    }
    
    // Define a mock HTTP response class for the second callout.
    public class MockHttpResponseRecordId implements HttpCalloutMock {
        public HTTPResponse respond(HTTPRequest req) {
            // Create a fake response to simulate a successful callout for sending the record ID.
            HttpResponse res = new HttpResponse();
            res.setHeader('Content-Type', 'application/json;charset=UTF-8');
            res.setBody('Success');
            res.setStatusCode(200);
            return res;
        }
    }
    
    @isTest
    static void testOpportunityTrigger() {
        // Create a test Opportunity record (you can add more fields as needed).
        Opportunity opp = new Opportunity(Name = 'Test Opportunity', StageName = 'Prospecting' , CloseDate = System.today());
        
        // Insert the Opportunity record to trigger the callout.
        insert opp;
        
        
        // Check if the trigger logic works as expected.
        // Add assertions here to validate the trigger's behavior, if any.
        
        // Set up mock responses for the callout methods.
        
        Test.setMock(HttpCalloutMock.class, new MockHttpResponseAuthentication());
        Test.setMock(HttpCalloutMock.class, new MockHttpResponseRecordId());
        
        Test.startTest();
        
        // Call the future method for authentication.
        DepreciationSWGetIdUpdatedOppRecord_th.makePostCalloutForAuthentication(opp.Id);
           // Map<String , Object> responseResult = (Map<String, Object>) JSON.deserializeUntyped('{"data":{"jwtToken":"fdsbjhifewonaldj"}}');
           // Map<String, Object> getDataValuesFromResponse = (Map<String, Object>) responseResult.get('data');

        // Call the method for sending the record ID.
        DepreciationSWGetIdUpdatedOppRecord_th.makePostCalloutToSendRecordId(opp.Id, 'mockAccessToken');
        
        Test.stopTest();
        
        // Add assertions to verify the behavior of the callout methods, if any.
    }
}


 
Apex Trigger :-


trigger TruckSupplyActual on Truck_Supply_Actual__c (after insert, after update) {
    if(Trigger.isAfter && Trigger.isInsert) 
    {
        TriggerHandler.insertRecord(Trigger.new);
    }
    if(Trigger.isBefore || Trigger.isAfter && Trigger.isUpdate )
    {
        TriggerHandler.updateRecord(Trigger.newMap, Trigger.oldMap);
    }
}

--------------------------------------------------------------------------------------------------------------


Apex Handler Class :-


public class TriggerHandler {
    public static void insertRecord(list<Truck_Supply_Actual__c> recordList ){
        list<Truck_Supply_Booking__c> truckSupplyBookinggList = new list<Truck_Supply_Booking__c>();
        for(Truck_Supply_Actual__c a : recordList){
            if(a.Amount__c != null){
                Decimal i = a.Amount__c;
                for(Integer j=1;j<=i;j++){
                    Truck_Supply_Booking__c truckSupplyBookingList = new Truck_Supply_Booking__c();
                    truckSupplyBookingList.Truck_Supply_Actual__c = a.ID;
                    truckSupplyBookingList.Date__c = system.today();
                    truckSupplyBookingList.Status__c = 'Available';
                    truckSupplyBookingList.truck__c = a.Truck__c;
                    truckSupplyBookinggList.add(truckSupplyBookingList);
                    
                }
            }
              insert truckSupplyBookinggList;
        }    
    }
    
    public static void updateRecord(Map<id,Truck_Supply_Actual__c> newValues , Map <id,Truck_Supply_Actual__c> oldValues){
        list<Truck_Supply_Booking__c> truckSupplyBookinggList = new list<Truck_Supply_Booking__c>(); 
        for(Truck_Supply_Actual__c a : newValues.values())
        { 
            if(oldValues.get(a.Id).Additional_Amount__c != newValues.get(a.Id).Additional_Amount__c)
            {    
                Truck_Supply_Actual__c record = [Select Id, Additional_Amount__c From Truck_Supply_Actual__c WHERE id =: a.Id]; 
                record.Additional_1_Created__c = true;
                update record;
                Decimal i = newValues.get(a.Id).Additional_Amount__c;
                for(Integer j=1;j<=i;j++){
                    Truck_Supply_Booking__c truckSupplyBookingList = new Truck_Supply_Booking__c();
                    truckSupplyBookingList.Truck_Supply_Actual__c = a.Id;
                    truckSupplyBookingList.Date__c = a.Date__c;
                    truckSupplyBookingList.Status__c = 'Available';
                    truckSupplyBookingList.truck__c = a.Truck__c;
                    truckSupplyBookinggList.add(truckSupplyBookingList);
                }
            }
            
            // -------------------------------- 2 -----------------------------------
            
             if(oldValues.get(a.Id).Additional_Amount_2__c != newValues.get(a.Id).Additional_Amount_2__c)
            {    
                Truck_Supply_Actual__c recordd = [Select Id, Additional_Amount_2__c From Truck_Supply_Actual__c WHERE id =: a.Id]; 
                recordd.Additional_2_Created__c = true;
                update recordd;
                Decimal i = newValues.get(a.Id).Additional_Amount_2__c;
                for(Integer j=1;j<=i;j++){
                    Truck_Supply_Booking__c truckSupplyBookingList = new Truck_Supply_Booking__c();
                    truckSupplyBookingList.Truck_Supply_Actual__c = a.Id;
                    truckSupplyBookingList.Date__c = a.Date__c;
                    truckSupplyBookingList.Status__c = 'Available';
                    truckSupplyBookingList.truck__c = a.Truck__c;
                    truckSupplyBookinggList.add(truckSupplyBookingList);
                }
            }
            
            //------------------------------------- 3 ----------------------------
            
                         if(oldValues.get(a.Id).Additional_Amount_3__c != newValues.get(a.Id).Additional_Amount_3__c)
            {    
                Truck_Supply_Actual__c recordd = [Select Id, Additional_Amount_3__c From Truck_Supply_Actual__c WHERE id =: a.Id]; 
                recordd.Additional_3_Created__c = true;
                update recordd;
                Decimal i = newValues.get(a.Id).Additional_Amount_3__c;
                for(Integer j=1;j<=i;j++){
                    Truck_Supply_Booking__c truckSupplyBookingList = new Truck_Supply_Booking__c();
                    truckSupplyBookingList.Truck_Supply_Actual__c = a.Id;
                    truckSupplyBookingList.Date__c = a.Date__c;
                    truckSupplyBookingList.Status__c = 'Available';
                    truckSupplyBookingList.truck__c = a.Truck__c;
                    truckSupplyBookinggList.add(truckSupplyBookingList);
                }
            }
            
        }
        insert truckSupplyBookinggList;
    }
}
TASK : I want to send the recordId of the updated Opportunity record whenever it is updated. I want to send it to external web service , my code is working and fulfilling my requirement but have a look at it once. 

I first got the updated Opportunity recirdId from trigger then I called my first callout where I got the 'Token' , and then I called the secod method where I send the recordId.


Please examine this code. Thanks in advance 

public class OpportunityToBeSent {
    @future (callout=true)
    public static void makePostCallout(String recId) {
        String token; 
        //        System.debug('recorddIdd' + recorddIdd);
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        
        request.setEndpoint('https://XXXXXXXXXXXXXXXXXXXX/authenticate');
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json;charset=UTF-8');
        // Set the body as a JSON object
        request.setBody('{"email": "XXXXX@XXXX.com","password": "XXXXXX"}');
        System.debug('request'+ request);
        HttpResponse response = http.send(request);
        System.debug('response'+ response);
        // Parse the JSON response
        if (response.getStatusCode() != 200) {
            System.debug('The status code returned was not expected: ' +
                         response.getStatusCode() + ' ' + response.getStatus());
        } else {
            System.debug(response.getBody());
            Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
            Map<String, Object> m2 = (Map<String, Object>) results.get('data');
            System.debug('results'+ m2.get('jwtToken'));
            token = (string)m2.get('jwtToken');
            System.debug('token '+ token);
        }
        makePostCalloutt(recId , token);
        
    }
    
    
    public static void makePostCalloutt(String recId , String tokenn) {
        System.debug('Token >>>'+ tokenn);
      
        String body = recId;
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        
        request.setEndpoint('https://XXXXXXXXXXXXXXXX?id='+ body);
        request.setMethod('POST');
        request.setHeader('Content-Type', 'text');
        request.setHeader( 'token', 'Bearer ' + tokenn );
        // Set the body as a JSON object
        request.setBody(body);
        System.debug('request'+ request);
        HttpResponse response = http.send(request);
        System.debug('response'+ response);
        // Parse the JSON response
        if (response.getStatusCode() != 200) {
            System.debug('The status code returned was not expected: ' +
                         response.getStatusCode() + ' ' + response.getStatus());
        } else {
            System.debug(response.getBody());
        }
        
    }    
}
I want to send the ID of the opportunity record just got updated to the external web service. How can I do it please help me . Thanks
public class OpportunityFetchField {
    
    @AuraEnabled
    public static list<Opportunity> insertOpportunity(list<Opportunity> oplist, ID ContactId, map<string, string> newObj){
        Contact rec = [SELECT ID ,Name from Contact where ID =: ContactId];
        system.debug('rec '+rec);
        system.debug('oplist '+oplist);
        system.debug('newObj '+newObj);
        for(Opportunity op :oplist){
            op.ContactId = rec.Id;
            op.StageName='Needs Analysis';
        }
        // op.Name= rec.Name;
        //op.CloseDate = Date.today();
        ///***************/
        Integer numberOfRelatedRecords = 0;
        //  Integer SessionNumber = 0;
        List<engageFI_Retail__c> eFIR = [SELECT ID , Name from engageFI_Retail__c where Contact_Name__c =: ContactId];
        System.debug('engageFI_Retail__c---->'+ eFIR);
        System.debug('Size------>'+ eFIR.size());

        
        if(eFIR.size()==5){
            /*----------------------------------------*/
            engageFI_Retail__c eFIRR =  [SELECT id , Name ,Contact_Name__c from engageFI_Retail__c where Contact_Name__c =: ContactId order by createdDate ASC limit 1];
            System.debug('eFIRR--------------'+eFIRR);
            delete eFIRR;
            /*-----------------------------------------*/
            engageFI_Retail__c er = new engageFI_Retail__c();
            
            if(newObj.containskey('BANK_CONVENIENCE__c')){
                er.BANK_CONVENIENCE__c = newObj.get('BANK_CONVENIENCE__c');
            }
            if(newObj.containskey('BANK_COST_EFFECTIVENESS__c')){
                er.BANK_COST_EFFECTIVENESS__c = newObj.get('BANK_COST_EFFECTIVENESS__c');
            }
            if(newObj.containskey('BANK_YIELD__c')){
                er.BANK_YIELD__c = newObj.get('BANK_YIELD__c');
            }
            if(newObj.containskey('BORROW_ACCESS_TO_LIQUIDITY__c')){
                er.BORROW_ACCESS_TO_LIQUIDITY__c = newObj.get('BORROW_ACCESS_TO_LIQUIDITY__c');
            }
            if(newObj.containskey('BORROW_CREDIT_CARDS__c')){
                er.BORROW_CREDIT_CARDS__c = newObj.get('BORROW_CREDIT_CARDS__c');
            }
            if(newObj.containskey('BORROW_DEBT_RESTRUCTURE__c')){
                er.BORROW_DEBT_RESTRUCTURE__c = newObj.get('BORROW_DEBT_RESTRUCTURE__c');
            }
            if(newObj.containskey('PLAN_EMERGENCY_FUND__c')){
                er.PLAN_EMERGENCY_FUND__c = newObj.get('PLAN_EMERGENCY_FUND__c');
            }
            if(newObj.containskey('PLAN_MAJOR_PURCHASES__c')){
                er.PLAN_MAJOR_PURCHASES__c = newObj.get('PLAN_MAJOR_PURCHASES__c');
            }
            if(newObj.containskey('PLAN_RETIREMENT__c')){
                er.PLAN_RETIREMENT__c = newObj.get('PLAN_RETIREMENT__c');
            }
            if(newObj.containskey('PROTECT_ACCOUNT_PROTECTION__c')){
                er.PROTECT_ACCOUNT_PROTECTION__c = newObj.get('PROTECT_ACCOUNT_PROTECTION__c');
            }
            if(newObj.containskey('PROTECT_ESTATE_PLANNING__c')){
                er.PROTECT_ESTATE_PLANNING__c = newObj.get('PROTECT_ESTATE_PLANNING__c');
            }
            if(newObj.containskey('PROTECT_INSURANCE_COVERAGES__c')){
                er.PROTECT_INSURANCE_COVERAGES__c = newObj.get('PROTECT_INSURANCE_COVERAGES__c');
            }  
            er.Scores__c = newObj.get('score');
            er.Contact_Name__c = rec.id;
            String datee = system.now().format('yyyy-MM-dd HH:mm');
            er.Name = rec.Name + ' - ' + datee ;
            insert er;
            
        }
        else if(eFIR.size()<5){
            engageFI_Retail__c er = new engageFI_Retail__c();
            
            if(newObj.containskey('BANK_CONVENIENCE__c')){
                er.BANK_CONVENIENCE__c = newObj.get('BANK_CONVENIENCE__c');
            }
            if(newObj.containskey('BANK_COST_EFFECTIVENESS__c')){
                er.BANK_COST_EFFECTIVENESS__c = newObj.get('BANK_COST_EFFECTIVENESS__c');
            }
            if(newObj.containskey('BANK_YIELD__c')){
                er.BANK_YIELD__c = newObj.get('BANK_YIELD__c');
            }
            if(newObj.containskey('BORROW_ACCESS_TO_LIQUIDITY__c')){
                er.BORROW_ACCESS_TO_LIQUIDITY__c = newObj.get('BORROW_ACCESS_TO_LIQUIDITY__c');
            }
            if(newObj.containskey('BORROW_CREDIT_CARDS__c')){
                er.BORROW_CREDIT_CARDS__c = newObj.get('BORROW_CREDIT_CARDS__c');
            }
            if(newObj.containskey('BORROW_DEBT_RESTRUCTURE__c')){
                er.BORROW_DEBT_RESTRUCTURE__c = newObj.get('BORROW_DEBT_RESTRUCTURE__c');
            }
            if(newObj.containskey('PLAN_EMERGENCY_FUND__c')){
                er.PLAN_EMERGENCY_FUND__c = newObj.get('PLAN_EMERGENCY_FUND__c');
            }
            if(newObj.containskey('PLAN_MAJOR_PURCHASES__c')){
                er.PLAN_MAJOR_PURCHASES__c = newObj.get('PLAN_MAJOR_PURCHASES__c');
            }
            if(newObj.containskey('PLAN_RETIREMENT__c')){
                er.PLAN_RETIREMENT__c = newObj.get('PLAN_RETIREMENT__c');
            }
            if(newObj.containskey('PROTECT_ACCOUNT_PROTECTION__c')){
                er.PROTECT_ACCOUNT_PROTECTION__c = newObj.get('PROTECT_ACCOUNT_PROTECTION__c');
            }
            if(newObj.containskey('PROTECT_ESTATE_PLANNING__c')){
                er.PROTECT_ESTATE_PLANNING__c = newObj.get('PROTECT_ESTATE_PLANNING__c');
            }
            if(newObj.containskey('PROTECT_INSURANCE_COVERAGES__c')){
                er.PROTECT_INSURANCE_COVERAGES__c = newObj.get('PROTECT_INSURANCE_COVERAGES__c');
            }  
            er.Scores__c = newObj.get('score');
            er.Contact_Name__c = rec.id;
            String datee = system.now().format('yyyy-MM-dd HH:mm');
            er.Name = rec.Name + ' - ' + datee ;
            insert er;
        }
        /****************/
        System.debug('ContactId' + ContactId);
        insert oplist;
        system.debug('oplist '+oplist);
        return oplist;
    }
    
    @AuraEnabled
    public static map<Id,engageFI_Retail__c > fetchEngageFIRetailRecentRecord(ID ContactIdd){
        System.debug('ContactIdd------'+ContactIdd);
        map<Id,engageFI_Retail__c > RecordMap = new Map<id,engageFI_Retail__c >();
        
        list<engageFI_Retail__c> eFIRRelatedRecord =  [SELECT id , Name ,BANK_CONVENIENCE__c,BANK_COST_EFFECTIVENESS__c,BANK_YIELD__c,
                                                       BORROW_ACCESS_TO_LIQUIDITY__c ,BORROW_CREDIT_CARDS__c,BORROW_DEBT_RESTRUCTURE__c,
                                                       PLAN_EMERGENCY_FUND__c,PLAN_MAJOR_PURCHASES__c,PLAN_RETIREMENT__c,
                                                       PROTECT_ACCOUNT_PROTECTION__c,PROTECT_ESTATE_PLANNING__c,PROTECT_INSURANCE_COVERAGES__c,
                                                       Scores__c,
                                                       Contact_Name__c,CreatedDate from engageFI_Retail__c where Contact_Name__c =: ContactIdd order by createdDate DESC limit 1];
        for(engageFI_Retail__c  RE : eFIRRelatedRecord ){
            RecordMap.put(Re.Id,Re);
            system.Debug('***'+RecordMap.values());
        }
        
        return RecordMap;
    }
    
}
Here is the scenario where I am seeking help from our community,

I have 10 radio group buttons now then what i need to do is on a click of a perticular button lets say 'SHOW RESULT' all the results should be shown of above all 10 radio groups WITH THEIR LABELS (eg. = Do you use credit card - Yes) that way. then on all those 10 results i want to create a drag and drop where i can only choose 5 of them. Then i need to save all these 5 into our lead object fileds.

Please help me out.
Thanks in advance

[I have done till creating radio groups and storing them into a list and theniterated over the list]