• George Slater
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
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 



 
  • January 23, 2019
  • Like
  • 0