+ Start a Discussion
ArunaAruna 

Please help me Unable to get Record Type names in lighting Javascript controller and unable to see the console.log in developer tools (console)

Hi, I am trying to convert below javascript button into a lighting component.

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
// query the record 
var qr = sforce.connection.query("SELECT Id, SyncedQuoteId FROM Opportunity where Id='" + "{!Opportunity.Id}" + "'"); 
var records = qr.getArray("records"); 

var qr1 = sforce.connection.query("SELECT Id, OpportunityId FROM Quote where OpportunityId='" + "{!Opportunity.Id}" + "'"); 

// display the field from the query 
var recTypeId='{!Opportunity.RecordTypeId}'; 

var oppQuoteId=qr.records.SyncedQuoteId; 
var quoteRecord=qr1.getArray("records"); 

if((recTypeId=='{!$Setup.Opportunity_Record_Types__c.New_Record_Type_Id__c}' || 
recTypeId=='{!$Setup.Opportunity_Record_Types__c.Pilot_Record_Type_Id__c}' || 
recTypeId=='{!$Setup.Opportunity_Record_Types__c.Renew_Upsell_Record_Type_Id__c}') 
&& (oppQuoteId==null && quoteRecord!='')) { 
window.alert("There is a root quote already attached to this Opportunity. If you need assistance with this opportunity, please reach out to xxxxx "); 

else {
window.open ("http://{!$Setup.Integration_Settings__c.Quoting_Tool_URL__c}/reps/xxxxx.aspx?SFAccountId={!CASESAFEID(Opportunity.AccountId)}&SFOppId={!CASESAFEID(Opportunity.Id)}"); 
}

Lighting component

<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
    <aura:handler name="init" value="{!this}" action="{!c.oppRecordTypes}"/>
    <!--<aura:attribute name="Opportunity" type="Opportunity" />-->
    
    <aura:attribute name="recordId" type="String" />
    <aura:attribute name="syncedQuoteId" type="String" />
    <aura:attribute name="quoteId" type="String" />
    <aura:attribute name="lstOfRecordType" type="String[]" />
    <aura:attribute name="lstOfCutomObjectRecordType" type="String[]" />
   
 </aura:component>

Javascript controller
({
    oppRecordTypes : function(component, event, helper) {
        var action=component.get("c.oppRecordTypes");
       // action.setParams({"objectName" : Opportunity});
        action.setParams({"recordId" : component.get("v.recordId")});
        action.setCallback(this,function(response){
           var state = response.getState();
            if(state=="SUCCESS"){
                component.set("v.lstOfRecordType",response.getReturnValues());
                var oppRecordTypeNamesList=response.getReturnValues();                
                console.log("Record type names11="+oppRecordTypeNamesList);
                          
                var syncedQuoteId=component.get("c.getSyncedQuoteId");
                console.log("oppSyncedQuoteId111=" + syncedQuoteId);
                               
                var quoteId=component.get("c.getQuoteId");
                console.log("oppquoteId111=" + quoteId);
                
                var oppCustomRecordTypeNamesList=component.get("c.getOppCutomRecordTypes");
               console.log("oppCustomRecordTypeNamesList11="+oppCustomRecordTypeNamesList);                
            }
            else{
                console.log("cannot get record type names");
            }            
        } );
    },
        getSyncedQuoteId : function(component,event,helper){
        var action=component.get("c.getSyncedQuoteId");
        action.setParams({"oppId" : component.get("v.recordId")});
        action.setCallback(this,function(response){
            var state = response.getState();
            if(state="SUCCESS"){
                component.set("v.syncedQuoteId",response.getReturnValues());
                var oppSyncedQuoteId=response.getReturnValues();           
                console.log("oppSyncedQuoteId=" + oppSyncedQuoteId);
                            }
            else{
                console.log("cannot get syncedQuote ID");
            }
        });
    },
     getQuoteId : function(component,event,helper){
        var action=component.get("c.getQuoteId");
        action.setParams({"oppId" : component.get("v.recordId")});
        action.setCallback(this,function(response){
            var state=response.getState();
            if(state="SUCCESS"){
                componet.set("v.quoteId",response.getReturnValues());
                var oppQuoteId=response.getReturnValues();
                console.log("oppQuoteId="+oppQuoteId);
            }
            else{
                console.log("cannot get quote id")
            }
        });
    },    
    getOppCutomRecordTypes :function(component,event,helper){
        var action=component.get("c.getOppCutomRecordTypes");
        action.setCallback(this,function(response){
            var state=response.getState();
            if(state="SUCCESS"){
                component.set("v.lstOfCutomObjectRecordType",response.getReturnValues());
                var oppCustomRecordTypeNamesList=response.getReturnValues();
                   
                console.log("oppCustomRecordTypeNamesList="+oppCustomRecordTypeNamesList);
            }
            else{
                console.log("cannot get custom report type names");
            }
        });        
    }
})
APEX Class
public class AttachQuoteCntrl {
    public static List<String> recordTypeNames;
    
    @AuraEnabled     
    public static List<String> oppRecordTypes(){
         List<Schema.RecordTypeInfo> recordtypes = Schema.getGlobalDescribe().get('Opportunity').getDescribe().getRecordTypeInfos();    
         recordTypeNames=new List<String>();
         for(RecordTypeInfo rt : recordtypes){
            recordTypeNames.add(rt.getName());
        }    
        System.debug('********recordTypeNames='+recordTypeNames);
        
        return recordTypeNames;
    }
    @AuraEnabled 
    public static string getSyncedQuoteId(string oppId){
        Opportunity oppSyncedQuote= [Select id,SyncedQuoteId from opportunity where Id=:oppId limit 1];
        string syncedQuoteId=oppSyncedQuote.SyncedQuoteId;
        System.debug('********syncedQuoteId='+syncedQuoteId);
        return syncedQuoteId;
    }
    
    @AuraEnabled 
    public static string getQuoteId(string oppId){
        Quote oppQuote= [Select id,OpportunityId from Quote where OpportunityId=:oppId limit 1];
        string QuoteId=oppQuote.id;
        System.debug('********QuoteId='+QuoteId);
        return QuoteId;
    }
    
    @AuraEnabled 
    public static Opportunity_Record_Types__c getOppCutomRecordTypes(){
        return Opportunity_Record_Types__c.getInstance();
    }
}

I am unable to see the console.log in javascript console(developer tools)
can any please correct my code I am sure something is wrong with the code I am able to save the code and added quick action lighting component.
when clicking the quick action, first of all, I want to see if the records are coming are not in the console log.I am understanding why I am unable to see the logs in the developer tools console.
Please help me 



 
Best Answer chosen by Aruna
ArunaAruna
Solution:- 
public class AttachQuoteCntrl {
     public static List<string> OpportunityRecordsList;
    
    @AuraEnabled        
    public static List<string> oppRecords(String recordId){
     OpportunityRecordsList = new List<string>();
        List<Opportunity> oppList=[SELECT id,AccountId,SyncedQuoteId,Quote_ID__c, RecordType.Id,(SELECT id FROM Quotes limit 1) FROM Opportunity WHERE id =:recordId];
        for(Opportunity oppRecord : oppList){
            
            List<Quote> quoteList=oppRecord.Quotes;
            OpportunityRecordsList.add(oppRecord.RecordType.Id);
            If(quoteList[0].id==null)
                OpportunityRecordsList.add('noQuote');
            else
                OpportunityRecordsList.add(quoteList[0].id);                
            if(oppRecord.SyncedQuoteId==null)
                OpportunityRecordsList.add('noSyncedQuote');
            else
                OpportunityRecordsList.add(oppRecord.SyncedQuoteId);
            
            OpportunityRecordsList.add(oppRecord.AccountId);
            OpportunityRecordsList.add(Integration_Settings__c.getInstance().Quoting_Tool_URL__c);
            
            OpportunityRecordsList.add(Opportunity_Record_Types__c.getInstance().New_Record_Type_Id__c);
            OpportunityRecordsList.add(Opportunity_Record_Types__c.getInstance().Pilot_Record_Type_Id__c);
            OpportunityRecordsList.add(Opportunity_Record_Types__c.getInstance().Renew_Upsell_Record_Type_Id__c);
        }
        System.debug('*******OpportunityRecordsList='+OpportunityRecordsList);
        return OpportunityRecordsList;
    }
    
}
 
<aura:component controller ="AttachQuoteCntrl" implements="force:lightningQuickActionWithoutHeader,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <aura:attribute name="recordId" type="String" />
    <aura:attribute name="lstOfRecordType" type="String[]" />
    <aura:attribute name="OpportunityRecordsList" type="List" />
    
 </aura:component>
 
controller 

({
    
    doInit: function(component, event, helper) {
       
        helper.opportunityRecordList(component);
    }
    
})

Helper

({
 
    opportunityRecordList: function(component) {
        var action = component.get("c.oppRecords");
         action.setParams({"recordId" : component.get("v.recordId")});
        
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(state=="SUCCESS"){
                var oppId=component.get("v.recordId");
                
                var oppRecordList = response.getReturnValue();
                console.log("oppRecordList="+JSON.stringify(oppRecordList));
                
                component.set("v.OpportunityRecordsList", oppRecordList);
                
                console.log("Record Type Name="+oppRecordList[0]);
                console.log("QuoteId="+oppRecordList[1]);
                console.log("syncedQuoteId="+oppRecordList[2]);
                console.log("AccountId="+oppRecordList[3]);
				console.log("Quote URL="+oppRecordList[4]);
                
                console.log("newRecord Type="+oppRecordList[5]);
                console.log("Pilot record type="+oppRecordList[6]);
                console.log("RenewUpsell record type="+oppRecordList[7]);
                
                if(oppRecordList[0]==oppRecordList[5] || oppRecordList[0]==oppRecordList[6] || oppRecordList[0]==oppRecordList[7] && oppRecordList[1]!='noQuote' && oppRecordList[2]=='noSyncedQuote') {
                    console.log("in if condition");
                    window.alert("xxxxxxxxxxxxx"); 
                	//window.close();
       				$A.get("e.force:closeQuickAction").fire();
                }
                else{
                   console.log("in else condition"); 
                	window.open ("http:"+oppRecordList[4]+"/reps/xxxxxx.aspx?SFAccountId="+oppRecordList[3]+"&SFOppId="+oppId); 
                	
                   // window.close();
       				$A.get("e.force:closeQuickAction").fire();
                }    
            }
            else{
                console.log("cannot  call back apex method");
            } 
        });
		$A.enqueueAction(action)
    }
})




 

All Answers

George SlaterGeorge Slater
You are never submitting your actions, just creating them.  In Lightning, you need to do something like this:
$A.enqueueAction(action)
or the server method will never be called.

Also, be careful with code like
if(state="SUCCESS"){  ... }
That's assignment, not an equality check.  Use strict equals like this:
 
if(state === "SUCCESS"){ ... }

Hope that helps!

 
Raj VakatiRaj Vakati
If you want to see the consolel.log you need to verify in the brower console logs and not in Salesforce debug logs 
If you want to see the debug logs in developer logs user $A.log 


Change your code as below 
 
public class AttachQuoteCntrl {
    
    @AuraEnabled     
    public static List<String> oppRecordTypes(){
         List<Schema.RecordTypeInfo> recordtypes = Schema.getGlobalDescribe().get('Opportunity').getDescribe().getRecordTypeInfos();    
          List<String> recordTypeNames=new List<String>();
         for(RecordTypeInfo rt : recordtypes){
            recordTypeNames.add(rt.getName());
        }    
        System.debug('********recordTypeNames='+recordTypeNames);
        
        return recordTypeNames;
    }
    @AuraEnabled 
    public static string getSyncedQuoteId(string oppId){
        Opportunity oppSyncedQuote= [Select id,SyncedQuoteId from opportunity where Id=:oppId limit 1];
        string syncedQuoteId=oppSyncedQuote.SyncedQuoteId;
        System.debug('********syncedQuoteId='+syncedQuoteId);
        return syncedQuoteId;
    }
    
    @AuraEnabled 
    public static string getQuoteId(string oppId){
        Quote oppQuote= [Select id,OpportunityId from Quote where OpportunityId=:oppId limit 1];
        string QuoteId=oppQuote.id;
        System.debug('********QuoteId='+QuoteId);
        return QuoteId;
    }
    
    @AuraEnabled 
    public static Opportunity_Record_Types__c getOppCutomRecordTypes(){
        return Opportunity_Record_Types__c.getInstance();
    }
}

<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
    <aura:handler name="init" value="{!this}" action="{!c.oppRecordTypes}"/>
    <!--<aura:attribute name="Opportunity" type="Opportunity" />-->
    
    <aura:attribute name="recordId" type="String" />
    <aura:attribute name="syncedQuoteId" type="String" />
    <aura:attribute name="quoteId" type="String" />
    <aura:attribute name="lstOfRecordType" type="String[]" />
    <aura:attribute name="lstOfCutomObjectRecordType" type="String[]" />
   
 </aura:component>
 
({
    oppRecordTypes : function(component, event, helper) {
        var action=component.get("c.oppRecordTypes");
       // action.setParams({"objectName" : Opportunity});
        action.setParams({"recordId" : component.get("v.recordId")});
        action.setCallback(this,function(response){
           var state = response.getState();
            if(state=="SUCCESS"){
                component.set("v.lstOfRecordType",response.getReturnValues());
                var oppRecordTypeNamesList=response.getReturnValues();                
                console.log("Record type names11="+oppRecordTypeNamesList);
                          
                var syncedQuoteId=component.get("c.getSyncedQuoteId");
                console.log("oppSyncedQuoteId111=" + syncedQuoteId);
                               
                var quoteId=component.get("c.getQuoteId");
                console.log("oppquoteId111=" + quoteId);
                
                var oppCustomRecordTypeNamesList=component.get("c.getOppCutomRecordTypes");
               console.log("oppCustomRecordTypeNamesList11="+oppCustomRecordTypeNamesList);                
            }
            else{
                console.log("cannot get record type names");
            }            
        });
		$A.enqueueAction(action)
    },
        getSyncedQuoteId : function(component,event,helper){
        var action=component.get("c.getSyncedQuoteId");
        action.setParams({"oppId" : component.get("v.recordId")});
        action.setCallback(this,function(response){
            var state = response.getState();
            if(state="SUCCESS"){
                component.set("v.syncedQuoteId",response.getReturnValues());
                var oppSyncedQuoteId=response.getReturnValues();           
                console.log("oppSyncedQuoteId=" + oppSyncedQuoteId);
                            }
            else{
                console.log("cannot get syncedQuote ID");
            }
        });
		$A.enqueueAction(action)
    },
     getQuoteId : function(component,event,helper){
        var action=component.get("c.getQuoteId");
        action.setParams({"oppId" : component.get("v.recordId")});
        action.setCallback(this,function(response){
            var state=response.getState();
            if(state="SUCCESS"){
                componet.set("v.quoteId",response.getReturnValues());
                var oppQuoteId=response.getReturnValues();
                console.log("oppQuoteId="+oppQuoteId);
            }
            else{
                console.log("cannot get quote id")
            }
        });
		$A.enqueueAction(action)
    },    
    getOppCutomRecordTypes :function(component,event,helper){
        var action=component.get("c.getOppCutomRecordTypes");
        action.setCallback(this,function(response){
            var state=response.getState();
            if(state="SUCCESS"){
                component.set("v.lstOfCutomObjectRecordType",response.getReturnValues());
                var oppCustomRecordTypeNamesList=response.getReturnValues();
                   
                console.log("oppCustomRecordTypeNamesList="+oppCustomRecordTypeNamesList);
            }
            else{
                console.log("cannot get custom report type names");
            }
        });
$A.enqueueAction(action)        
    },
})


 
ArunaAruna
Solution:- 
public class AttachQuoteCntrl {
     public static List<string> OpportunityRecordsList;
    
    @AuraEnabled        
    public static List<string> oppRecords(String recordId){
     OpportunityRecordsList = new List<string>();
        List<Opportunity> oppList=[SELECT id,AccountId,SyncedQuoteId,Quote_ID__c, RecordType.Id,(SELECT id FROM Quotes limit 1) FROM Opportunity WHERE id =:recordId];
        for(Opportunity oppRecord : oppList){
            
            List<Quote> quoteList=oppRecord.Quotes;
            OpportunityRecordsList.add(oppRecord.RecordType.Id);
            If(quoteList[0].id==null)
                OpportunityRecordsList.add('noQuote');
            else
                OpportunityRecordsList.add(quoteList[0].id);                
            if(oppRecord.SyncedQuoteId==null)
                OpportunityRecordsList.add('noSyncedQuote');
            else
                OpportunityRecordsList.add(oppRecord.SyncedQuoteId);
            
            OpportunityRecordsList.add(oppRecord.AccountId);
            OpportunityRecordsList.add(Integration_Settings__c.getInstance().Quoting_Tool_URL__c);
            
            OpportunityRecordsList.add(Opportunity_Record_Types__c.getInstance().New_Record_Type_Id__c);
            OpportunityRecordsList.add(Opportunity_Record_Types__c.getInstance().Pilot_Record_Type_Id__c);
            OpportunityRecordsList.add(Opportunity_Record_Types__c.getInstance().Renew_Upsell_Record_Type_Id__c);
        }
        System.debug('*******OpportunityRecordsList='+OpportunityRecordsList);
        return OpportunityRecordsList;
    }
    
}
 
<aura:component controller ="AttachQuoteCntrl" implements="force:lightningQuickActionWithoutHeader,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <aura:attribute name="recordId" type="String" />
    <aura:attribute name="lstOfRecordType" type="String[]" />
    <aura:attribute name="OpportunityRecordsList" type="List" />
    
 </aura:component>
 
controller 

({
    
    doInit: function(component, event, helper) {
       
        helper.opportunityRecordList(component);
    }
    
})

Helper

({
 
    opportunityRecordList: function(component) {
        var action = component.get("c.oppRecords");
         action.setParams({"recordId" : component.get("v.recordId")});
        
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(state=="SUCCESS"){
                var oppId=component.get("v.recordId");
                
                var oppRecordList = response.getReturnValue();
                console.log("oppRecordList="+JSON.stringify(oppRecordList));
                
                component.set("v.OpportunityRecordsList", oppRecordList);
                
                console.log("Record Type Name="+oppRecordList[0]);
                console.log("QuoteId="+oppRecordList[1]);
                console.log("syncedQuoteId="+oppRecordList[2]);
                console.log("AccountId="+oppRecordList[3]);
				console.log("Quote URL="+oppRecordList[4]);
                
                console.log("newRecord Type="+oppRecordList[5]);
                console.log("Pilot record type="+oppRecordList[6]);
                console.log("RenewUpsell record type="+oppRecordList[7]);
                
                if(oppRecordList[0]==oppRecordList[5] || oppRecordList[0]==oppRecordList[6] || oppRecordList[0]==oppRecordList[7] && oppRecordList[1]!='noQuote' && oppRecordList[2]=='noSyncedQuote') {
                    console.log("in if condition");
                    window.alert("xxxxxxxxxxxxx"); 
                	//window.close();
       				$A.get("e.force:closeQuickAction").fire();
                }
                else{
                   console.log("in else condition"); 
                	window.open ("http:"+oppRecordList[4]+"/reps/xxxxxx.aspx?SFAccountId="+oppRecordList[3]+"&SFOppId="+oppId); 
                	
                   // window.close();
       				$A.get("e.force:closeQuickAction").fire();
                }    
            }
            else{
                console.log("cannot  call back apex method");
            } 
        });
		$A.enqueueAction(action)
    }
})




 
This was selected as the best answer