• Sonakshi Sharma
  • NEWBIE
  • 10 Points
  • Member since 2020
  • Appcino

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
I want to call the apex using trigger and do the authentication. I am trying to authenticate but Recieving an Status code of 301 and Can't get the Access Token. My code is given below. Please Suggest me how to do this?


My Code:- 
Apex Code
@future(Callout=true) public static void doAuthentication(Set<Id> idSet){
        List<Account> rList = new List<Account>();
        Http http = new Http();
        for (Account r : [SELECT Rating FROM Account WHERE Id in :idSet]){
            HttpRequest req=new HttpRequest();
            String authorization_endpoint = 'https://appcenter.intuit.com/connect/oauth2';
            string un='sonakshis@appcino.com';
            String pw='Sonakshi9*';
            String scope = 'com.intuit.quickbooks.accounting';
            String final_EndPoint = authorization_endpoint+'?username='+un+'&password='+pw+'&response_type=code&scope='+scope+'&state=123445633443&redirect_URI='+redirect_URI+'&grant_type='+pw+'&client_id='+client_id+'&client_secret='+consumer_Secret;
            //String final_EndPoint = authorization_endpoint+'?username=sonakshis@appcino.com&password=Sonakshi9*&scope=scope&redirect_URI=redirect_URI&grant_type=password&client_id=client_Id&client_secret=consumer_Secret';
            System.debug('final_EndPoint in Authentication'+final_EndPoint);
            
            req.setEndpoint(final_EndPoint);
            req.setMethod ('POST');
            String username='Sonakshis@appcino.com';
            String password='Sonakshi99*';
            System.debug('req.setbody'+req.getbody());
            System.HttpResponse response1 = new System.Http().send(req);
            system.debug('response1'+response1);
            string AuthorizationToken;
            HTTPResponse res = http.send(req);
            System.debug('response===???a'+res.getBody());
            try {
                contact con = new contact();
                con.LastName='Contact Integration 1 ';
                con.AccountId=r.Id;
                Insert con;
                r.Type = 'Prospect';
                system.debug('r.type'+r.type);
                rList.add(r);
                system.debug('rList'+rList);
            } catch(System.CalloutException ce){
                // handle callout error
            }
    } 
    Database.SaveResult results = Database.update(rList[0], false);
        system.debug('rList'+rList);
        system.debug('Result==???'+results);
    // handle DML error
    }
Trigger Code:-
trigger QuickBooksT on Account (After Insert) {
    system.debug('In Trigger');
    //QuickbookConnection.doAuthorizationQuickBooks();
    set<Id> idSet = new Set<Id>{};
    for(Account acc : trigger.new){
        if(acc.Rating!= null){
            idSet.add(acc.Id);
            system.debug('idSet'+idSet);
            if(idSet.size()==100) {
                //QuickbookConnection.doAuthentication(idSet);
                QuickbookConnection.doAuthorizationQuickBooks();
                QuickbookConnection.doFetchAccessToken();
                idSet.clear();
            }
        }       
    }
    if (!idSet.isEmpty()){
       QuickbookConnection.doAuthentication(idSet);
    }
}

Thanks,
Sonakshi
 
Hello,

The below is my code for header in lightning component. When I used position fixed in this, it works fine in my desktop but not in my mobile and by using position fixed, width changes and overlaps with the next div after header div
code:-

code:-

<div class="" style="position:fixed;z-index:2">
        <div class="slds-page-header inputFormHeader slds-page-header__row slds-page-header__col-title slds-media slds-media__figure">
                       <!-- <lightning:icon iconName="standard:service_appointment_capacity_usage" alternativeText="Event" title="Event" /> -->
                        <lightning:icon iconName="standard:service_appointment" alternativeText="Service Appointment" title="Service Appointment" />
                    
                        <div class="slds-media__body header Title container lgc-bg menuButtons" style="font-size: 21px;font-weight: 100;">
                          
                                <lightning:buttonMenu label="{!v.selectedValue}" onselect="{!c.handleMenu}" alternativeText="Show menu" variant="bare">
                                    <aura:iteration items="{!v.options}" var="item">
                                        <lightning:menuItem checked="{!item.label == v.selectedValue}" value="{!item.value}" label="{!item.label}" />
                                    </aura:iteration>
                                    
                                </lightning:buttonMenu>
                        </div>
            <div class="slds-page-header__controls slds-page-header__control">
                   
                   <span class="calendarIcon" onclick=""> 
                        <lightning:icon style="position:absolute;"
                                        id="datepickerIdIcon1" iconName="standard:event" alternativeText="Approved" title="Approved" />
                    </span>
                    
                    <input readonly="readonly" style="width: 31px;
                                  border: none;
                                  box-shadow: none;background-color: transparent;"  id="datepickerId" type="text"  onfocus="DatePicker.pickDate(false, this , false);" class="slds-input calendar" />
                    
                </div>
            </div>
    </div>

Thanks,
Sonakshi