• kezia dola
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 8
    Replies
Hello Everyone,

I am facing an issue after conversion of lead. After converting the lead, when I click on opportunity it redirects to account record page instead of opportunity. I want it to redirects to opportunity after clicking the opportunity on lead conversion page.

Any Idea how to solve this?

Thanks
Kezia
Hi,
 
I configured CPQ for partner community. They can create a new CPQ quote. When they try to edit lines, it is showing the below message. 
Add products button is not available.

User-added image




Any suggestions can help.

Thank you
Kezia
Hi,
I have two objects i.e; Invoice and Account. Invoice is a custom object, in invoice object, I have a master detail field called "customer name__c". I want to populate the customer name field with account name while creating a new record in invoice object. I have tried with process builder and flows to populate the account name but I can't update it.

So, Any suggestion how to update it through trigger?

Thanks,
Kezia
Hi All,
I have created a visual force page to create a pdf in order object. Earlier it was worked fine but now I am facing this error:
"common.apex.runtime.impl.executionexception: sobject row was retrieved via soql without querying the requested field: order.ordernumber"

Here is my controller:
public class OrderPdf {
    public  Order ord{set;get;} 
    public OrderItem ordIt{set;get;}
    public Organization  org{set;get;}
    public  string rec;
    public OrderPdf(apexpages.StandardController sc){ 
        rec=apexpages.currentPage().getparameters().get('id');
  ord = [SELECT ID,AccountId,Customer_PO_Date__c,Customer_PO_Number__c,Delivery_Terms__c,Incoterms_2010_named_place__c,Payment_Terms__c,Port_of_Arrival__c,CurrencyIsoCode,Name,OrderNumber,EffectiveDate,Ship_Via__c,Supplier_Number__c,Account.CIN__c,Account.Email__c,Account.Phone,BillToContact.Email,BillToContact.Phone,TotalAmount,BillToContact.FirstName,BillToContact.LastName,account.name,account.billingcountry,account.billingcity,account.billingstate,account.billingPostalCode,account.billingStreet,account.shippingcountry,account.shippingcity,account.shippingstate,account.shippingPostalCode,
             account.shippingStreet,(select Product2Id,Product2.Name,OrderItemNumber,Product2.Description,Total_Price_Incl_GST__c,Quantity,Delivery_Date__c,HSN_Code__c,CAS_No__c,UOM__c,Description,UnitPrice,TotalPrice from orderItems) from order where id =: rec];  
    }
       public  pagereference SaveFile(){
         PageReference pdf = Page.OrderPDFAttachement;
           pdf.getParameters().put('id',rec);
           pdf.setRedirect(true);
          blob body =Test.isRunningTest() ? Blob.valueOf('UNIT.TEST'):pdf.getContentAsPDF();
          string filename = ' My File Name ';  
          ContentVersion conVer = new ContentVersion();
          conVer.ContentLocation = 'S'; // S specify this document is in SF, use E for external files
          conVer.PathOnClient = 'Attachment.pdf'; // The files name, extension is very important here which will help the file in preview.
          conVer.Title = String.valueOf('SOMU '+ string.valueof(system.today().format())+'.pdf'); // Display name of the files
          conVer.VersionData = body; // converting your binary string to Blog
          insert conVer;
          Id conDoc = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:conVer.Id].ContentDocumentId;
           ContentDocumentLink cDe = new ContentDocumentLink();
           cDe.ContentDocumentId = conDoc;
           cDe.LinkedEntityId =rec; // you can use objectId,GroupId etc
//cDe.ShareType = 'I'; // Inferred permission, checkout description of ContentDocumentLink object for more details
//cDe.Visibility = 'System Administrator';
           insert cDe;
           pagereference p=new pagereference('/'+rec);
           return p;
    }
    public  pagereference SendFile(){
          PageReference pdf = Page.OrderPdf;
          pdf.getParameters().put('id',rec);
         //  Blob b =pdf.getContentAsPDF();
          Blob b =Test.isRunningTest() ? Blob.valueOf('UNIT.TEST'):pdf.getContentAsPDF();
        ContentVersion conVer = new ContentVersion();
conVer.ContentLocation = 'S'; // S specify this document is in SF, use E for external files
conVer.PathOnClient = 'Attachment.pdf'; // The files name, extension is very important here which will help the file in preview.
conVer.Title = String.valueOf('SOMU '+ string.valueof(system.today().format())+'.pdf'); // Display name of the files
conVer.VersionData = b; // converting your binary string to Blog
insert conVer;
           Id conDoc = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:conVer.Id].ContentDocumentId;
 //Create ContentDocumentLink
ContentDocumentLink cDe = new ContentDocumentLink();
cDe.ContentDocumentId = conDoc;
cDe.LinkedEntityId =rec; // you can use objectId,GroupId etc
//cDe.ShareType = 'I'; // Inferred permission, checkout description of ContentDocumentLink object for more details
//cDe.Visibility = 'System Administrator';
insert cDe;
        pagereference p=new pagereference('/'+rec); 
        return p;
           }    
}
---------------------------------------------------------------------------------------------
Visualforce page:
<apex:page extensions="OrderPdf" renderas="pdf" standardController="order" applyHtmlTag="false" applyBodyTag="false" showHeader="false">   
     <head>
        <style type="text/css">
            @page{
             size:21cm 29.7cm; 
              @bottom-right{
                content:"Page " counter(page) " of " counter(pages);
            }
            }
            
        </style> 
    <img src="https://somugroup--dev1.sandbox.file.force.com/servlet/servlet.FileDownload?file=0151s000000E4iq" style="background-color:#D3D3D3; width: 90px; height: 50px" align="left" /> <br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    </head>
    <tr>
         <td colspan= "2" align="left">        <br/> <span style="font-size: 14px;"><b>Contact: {!ord.BillToContact.FirstName}{!ord.BillToContact.LastName}</b></span></td> 
       <td style="font-size: 15px;text-align: right" width="5%">&nbsp; <b>Order:{!ord.OrderNumber} </b><br/></td>  
  
            </tr> 
      <table style="width:100%" border="0" cellspacing="0">          
        <tbody>
        <tr>
     <td colspan= "2" align="left">        <br/> <span style="font-size: 14px;"><b>{!ord.account.name}</b></span></td> 
            
            </tr>
            <tr><td >
       <span style="font-size: 15px;">{!ord.account.billingStreet}<br/>{!ord.account.billingcity}<br/>{!ord.account.billingstate}<br/>{!ord.account.billingPostalCode}<br/>{!ord.account.billingcountry}<br/>CIN#: {!ord.Account.CIN__c}<br/>Email: {!ord.Account.Email__c}<br/>Phone: {!ord.Account.Phone}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><br/>
       </td>
       
       <table style="width:10%" border="1" cellspacing="0" align="right">
           <tr>
           <td style="font-size: 15px;text-align: center"  width="5%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <b>Type</b><br/></td>
           <td style="font-size: 15px;text-align: center"  width="5%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <b>Order</b><br/></td>
          <td style="font-size: 15px;text-align: center"  width="5%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <b>Order Date</b><br/></td>
          <td style="font-size: 15px;text-align: center"  width="5%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <b>Revision Date</b><br/></td>
           <td style="font-size: 15px;text-align: center"  width="5%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <b>Buyer</b><br/></td>

           </tr>
            <apex:repeat value="{!Order}" var="ort">
            <tr>
                
                <td style="font-size: 12px;" align="left" >Standard Purchase Order </td>
                <td style="font-size: 12px;" align="left"> {!ort.OrderNumber}</td>
                <td style="font-size: 12px;" align="left">
                <apex:outputText value="{0,date,dd'-'MM'-'yyyy}">
                  <apex:param value="{!ort.EffectiveDate}" /> 
                  </apex:outputText></td>
               <td style="font-size: 12px;" align="left">
                <apex:outputText value="{0,date,dd'-'MM'-'yyyy}">
                  <apex:param value="{!ort.PoDate}" /> 
                  </apex:outputText></td>
           <td style="font-size: 12px;" align="left" >SP </td>

             </tr>
              
              </apex:repeat>
       </table>
           
            </tr>
            
 <br/>
            <td >
             <span style="font-size: 15px;text-align: right">      <b>Somu Group Of Companies </b></span><br/>   
            <span style="font-size: 15px;text-align: right">      <b>No.20,Somu Centre,29th Main,BTM Layout, </b></span><br/>
            <span style="font-size: 15px;text-align: right">      <b>2nd Stage </b></span><br/>
            <span style="font-size: 15px;text-align: right">        Bangalore 560076</span><br/>
            <span style="font-size: 15px;text-align: right">        Karnataka   </span><br/>
            <span style="font-size: 15px;text-align: right">         India </span><br/><br/>
            </td>
                    <tr>
     <td colspan= "3" align="left">        </td> 
            
            </tr> 
            <tr><td >
<span style="font-size: 15px;"><b>Deliver To : </b> <br/>
                <span style="font-size: 15px;">{!ord.account.shippingStreet}<br/>{!ord.account.shippingcity}<br/>{!ord.account.shippingstate}<br/>{!ord.account.shippingPostalCode}<br/>{!ord.account.shippingcountry}<br/>&nbsp;</span><br/>
                </span><br/>        </td><td >
    <span style="font-size: 15px;text-align: right">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   <b> Bill To : </b></span><br/>
<span style="font-size: 15px;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {!ord.account.billingStreet}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  {!ord.account.billingcity}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  {!ord.account.billingstate}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  {!ord.account.billingPostalCode}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   {!ord.account.billingcountry}<br/>&nbsp;</span><br/>                </td>
        </tr>
        </tbody>
</table>
         
      <br/> <table  style="width:100%" border="1" cellspacing="0">
   <tr>
        <td  style="background-color:#D3D3D3; font-size: 14px;" align="center" width="10%"><b>Account Number</b><br/></td>
        <td  style="background-color:#D3D3D3; font-size: 14px;" align="center" width="10%"><b>Supplier Number</b><br/></td>
        <td  style="background-color:#D3D3D3; font-size: 14px;" align="center" width="10%"><b>Payment Terms</b></td>
         <td  style="background-color:#D3D3D3; font-size: 14px;" align="center" width="10%"><b>Currency</b><br/></td>
         <td  style="background-color:#D3D3D3; font-size: 14px;" align="center" width="10%"><b>Inncoterms 2010 named place</b><br/></td>
         <td  style="background-color:#D3D3D3; font-size: 14px;" align="center" width="10%"><b>Ship via</b><br/></td>
        <td  style="background-color:#D3D3D3; font-size: 14px;" align="center" width="10%"><b>Port of Arrival</b></td>
        </tr>
          <apex:repeat value="{!Order}" var="ort">
            <tr>
               
                <td style="font-size: 12px;" align="left" >{!ort.account.name} </td>
                <td style="font-size: 12px;" align="left">{!ort.Supplier_Number__c} </td>
               <td style="font-size: 12px;" align="left">{!ort.Payment_Terms__c} </td>
               <td style="font-size: 12px;" align="left">{!ort.CurrencyIsoCode} </td>
                <td style="font-size: 12px;" align="left" >{!ort.Incoterms_2010_named_place__c} </td>
                <td style="font-size: 12px;" align="left" >{!ort.Ship_Via__c} </td>
                <td style="font-size: 12px;" align="left">{!ort.Port_of_Arrival__c} </td>
             </tr>
              
              </apex:repeat>
          </table>
     <br/> <table style="width:100%" border="1">
     <td style="background-color:#D3D3D3; font-size: 14px;" align="left" width="10%"><b>Confirm To: {!ord.BillToContact.FirstName}{!ord.BillToContact.LastName}</b><br/> </td> 
    <td style="background-color:#D3D3D3; font-size: 14px;" align="left" width="10%"><b>Email: {!ord.BillToContact.Email}</b><br/> </td>
   <td style="background-color:#D3D3D3; font-size: 14px;" align="left" width="10%"><b>Phone: {!ord.BillToContact.Phone}</b><br/> </td>
     </table>
     
     <br/> <table  style="width:100%" border="1" cellspacing="0">
   <tr>
        
         <td  style="background-color:#D3D3D3; font-size: 14px;" align="center" width="10%"><b>Product</b><br/></td>
         <td  style="background-color:#D3D3D3; font-size: 14px;" align="center" width="10%"><b>Delivery Date</b></td>
         <td  style="background-color:#D3D3D3; font-size: 14px;" align="center" width="10%"><b>Qunatity</b><br/></td>
         <td  style="background-color:#D3D3D3; font-size: 14px;" align="center" width="10%"><b>UOM</b><br/></td>
         <td  style="background-color:#D3D3D3; font-size: 14px;" align="center" width="10%"><b>CAS No</b><br/></td>
         <td  style="background-color:#D3D3D3; font-size: 14px;" align="center" width="10%"><b>HSN Code</b></td>
         <td  style="background-color:#D3D3D3; font-size: 14px;" align="center" width="10%"><b>Unit Price</b></td>
         <td  style="background-color:#D3D3D3; font-size: 14px;" align="center" width="10%"><b>Amount</b></td>
         <td  style="background-color:#D3D3D3; font-size: 14px;" align="center" width="30%"><b>Product Description</b><br/></td>

</tr>
          <apex:repeat value="{!ord.orderItems}" var="o">
            <tr>
                
                <td style="font-size: 12px;" align="left" >{!o.Product2.Name} </td>
               <td style="font-size: 12px;" align="left">
                <apex:outputText value="{0,date,dd'-'MM'-'yyyy}">
                  <apex:param value="{!o.Delivery_Date__c}" /> 
                  </apex:outputText></td>
                 <td style="font-size: 12px;" align="left"><apex:outputText value="{0, number, ###,###}">
                          <apex:param value="{!o.Quantity}" />
                          </apex:outputText><br/></td>
                <td style="font-size: 12px;" align="left" >{!o.UOM__c} </td>
                <td style="font-size: 12px;" align="left" >{!o.CAS_No__c} </td>
                <td style="font-size: 12px;" align="left">{!o.HSN_Code__c} </td>
               <td style="font-size: 12px;" align="left">{!o.UnitPrice} </td>
               <td style="font-size: 12px;" align="left">{!o.Total_Price_Incl_GST__c} </td>
                <td style="font-size: 12px;" align="left">{!o.Product2.Description} </td>
</tr>
              </apex:repeat>
              <tr>
   <td style="font-size: 14px;" colspan="7" align="Right">
            <b>Grand Total</b>
            </td>
            <td style="font-size: 12px;" align="left">{!ord.TotalAmount}
            </td>
     <td style="font-size: 12px;" align="left">
            </td><td style="font-size: 12px;" align="left">
            </td>
      </tr>
          </table>
          <table style="width:100%" border="0" cellspacing="0" >
          </table>  
</apex:page>
Any idea how to avoid this? Even that field was in query.

Thanks,
Kezia
Hi All,

I have two objects called Quote Line Items and Order Products. Using trigger I want to update the order products when quote line items are edited.

Any Idea how to do?

Thanks,
Kezia
Hi All,

I have a field called order__c in quote and quote line item objects. Using trigger, I want to update order__c field in quote line item, when order__c field in quote is updated. 

Any Idea how to do this?

Thank you,
Kezia
Hi,

I am getting 401 unauthorized error while running my API. I have checked the endpoint url and all credentials from server side, all are correct. Still getting this error. 
Error: [Status=Unauthorized, StatusCode=401]
"code":401,"message":"An error occurred. Header not set."
-------
This is my code:

public class QcAPI {
    @future(callout=true)
    public static void callServer(String id){
        Opportunity opp =[Select Id,Account.FirstName,Account.ShippingAddress,Account.BillingAddress, Account.LastName,Email__c,DUP_Mobile__c,account.BillingStreet,account.BillingCity,account.BillingState,account.BillingCountry,account.BillingPostalCode,
                          account.ShippingStreet,account.ShippingCity,account.ShippingState,account.ShippingCountry,account.ShippingPostalCode from Opportunity where id=: id limit 1];
        
        OpportunityDataWrap oppdata = new OpportunityDataWrap();
        String rno = opp.Account.LastName+'-'+opp.Id;
        oppdata.refno = rno;
        oppdata.syncOnly = true;
        oppdata.deliveryMode = 'API';
        
        if(opp.Account.ShippingAddress !=null){
            ShippingAddressWrap cc = new ShippingAddressWrap();
            cc.firstname = opp.Account.LastName;
            cc.lastname = '';
            cc.email = opp.Email__c;
            cc.telephone = '+91'+opp.DUP_Mobile__c;
            cc.country = 'IN';
            cc.line1 = opp.Account.ShippingStreet;
            cc.line2 = '-';
            cc.city = opp.Account.ShippingCity;
            cc.postcode = opp.Account.ShippingPostalCode;
            cc.region = opp.Account.ShippingState;
            cc.billToThis = true;
            oppdata.address = cc;
        }
        
        if(opp.Account.BillingAddress !=null){
            BillingAddressWrap cb = new BillingAddressWrap();
            cb.firstname = opp.Account.lastname;
            cb.lastname = '';
            cb.email = opp.Email__c;
            cb.telephone = '+91'+opp.DUP_Mobile__c;
            cb.country = 'IN';
            cb.line1 = opp.Account.ShippingStreet;
            cb.line2 = '-';
            cb.city = opp.Account.ShippingCity;
            cb.postcode = opp.Account.ShippingPostalCode;
            cb.region = opp.Account.ShippingState; 
            oppdata.billing = cb;
        }
        List<paymentwrap> pw = new List<paymentwrap>();
        paymentwrap pwr = new paymentwrap();
        pwr.code = 'xyz';
        pwr.amount = 0;
        pw.add(pwr);
        oppdata.payments = pw;
        
        List<productsWrap> prodwrap = new List<productsWrap>();
        productsWrap pdwr = new productsWrap();
        pdwr.sku = 'xyzABCDE000';  
        pdwr.price = 0;
        pdwr.qty = 1;
        pdwr.currency_x =356;
        pdwr.giftMessage ='';
        pdwr.theme ='';
        prodwrap.add(pdwr);
        oppdata.products = prodwrap;
        system.debug('OppData:'+oppdata);
        String jsbody = JSON.serialize(oppdata);
        String jsonBody = jsbody.replace('currency_x', 'currency');
        system.debug('JSON BODY : '+jsonBody);
        map<string,Object> result = (map<string,Object>)JSON.deserializeUntyped(jsonBody);
        system.debug('result '+result);
        string endresult = JSON.serialize(result);
        system.debug('endresult '+endresult);

        String customLabelValue = Label.QCAPI+'/orders';
        //signature calling
        
        XYZ__c    Qc = XYZ__c.getvalues('XYZ details');
        string secretKeyValue = Qc.Consumer_secret__c;
        string reqMethod = 'POST';
        string url = EncodingUtil.URLEncode(Label.QCAPI+'/10000028/resend','UTF-8');
        system.JSONParser requestData = JSON.createParser(jsonBody);
        string endpoint = reqMethod + '&' + url;
        system.debug('end point url '+endpoint);
        string signature;
        Blob hmacData = Crypto.generateMac('HmacSHA512', Blob.valueOf(endpoint), Blob.valueOf(secretKeyValue));
        signature = encodingUtil.convertToHex(hmacData);
        system.debug('signature '+signature);
        
        string BearerToken = QCoauth.BearerToken();
        HttpRequest request = new HttpRequest();
        request.setEndpoint(customLabelValue);
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json');
        request.setHeader('Authorization',BearerToken);
        request.setHeader('Accept','*/*');
        request.setBody(jsonBody);
        Http http = new Http();
        HttpResponse response = http.send(request);
        system.debug('get response :'+response.getBody());
        system.debug('get response :'+response);
        List<ResponseData> rd = (List<ResponseData>)JSON.deserialize(response.getBody(),List<ResponseData>.class);
        System.debug('Response Data :'+rd);
        
    }
    
    public class ShippingAddressWrap{
        public String firstname{get;set;}
        public String lastname{get;set;} 
        public String email{get;set;} 
        public String telephone{get;set;} 
        public String line1{get;set;} 
        public String line2{get;set;} 
        public String city{get;set;} 
        public String region{get;set;} 
        public String country{get;set;} 
        public String postcode{get;set;} 
        public boolean billToThis{get;set;} 
    }
    
    public class BillingAddressWrap{
        public String firstname{get;set;}
        public String lastname{get;set;} 
        public String email{get;set;} 
        public String telephone{get;set;} 
        public String line1{get;set;} 
        public String line2{get;set;} 
        public String city{get;set;} 
        public String region{get;set;} 
        public String country{get;set;} 
        public String postcode{get;set;} 
    }
    public class paymentwrap{
        public string code{get;set;}
        public double amount{get;set;}
    }
    public class productsWrap{
        public string sku{get;set;}
        public double price{get;set;}
        public integer qty{get;set;}
        public integer currency_x{get;set;}
        public string giftMessage{get;set;}
        public string theme{get;set;}
    }
    public class OpportunityDataWrap{    
        Public ShippingAddressWrap address{get;set;}
        Public BillingAddressWrap billing{get;set;}
        Public List<paymentwrap> payments{get;set;}
        public string refno{get;set;}
        public List<productsWrap> products{get;set;}
        public boolean syncOnly{get;set;}
        public String deliveryMode{get;set;} 
    }
    public class ResponseData {
        public string status;
        public List<cardwrap> cards;
    }
    public class cardwrap{
        public string cardNumber;
        public string cardPin;
    }
}
-----------
This is my Oauth code:

public class qcOauth {
    public static string AuthCode(){
        string Authcode;
        qc__c    Qc = qc__c.getvalues('qc details');
        authWrapreq Aw = new authWrapreq();
        Aw.clientId = Qc.Consumer_Key__c;
        Aw.username = Qc.UserName__c;
        Aw.password = Qc.Password__c;
        
        string endpoint = Qc.url__c+'verify';
        HttpRequest request = new HttpRequest();
        request.setEndpoint(endpoint);
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json');
        String jsonBody = JSON.serialize(Aw);
      //  system.debug('JSON BODY : '+jsonBody);
        request.setBody(jsonBody);
        Http http = new Http();
        HttpResponse response = http.send(request);
     //   system.debug('response body: '+response.getBody());
        if(response.getStatusCode() == 200){
            authRes res = (authRes)json.deserialize(response.getBody(), authRes.class);
            authcode = res.authorizationCode;
        }
     //   system.debug(authcode);
        return authcode;
    }
    
    public static string BearerToken(){
        string BearerToken;
        qc__c    Qc = qc__c.getvalues('qc details');
        BearerWrapReq Bw = new BearerWrapReq();
        Bw.clientId = Qc.Consumer_Key__c;
        Bw.clientSecret = Qc.Consumer_secret__c;
        Bw.authorizationCode = Authcode();
        
        string endpoint = Qc.url__c+'token';
        HttpRequest request = new HttpRequest();
        request.setEndpoint(endpoint);
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json');
        String jsonBody = JSON.serialize(Bw);
    //    system.debug('JSON BODY : '+jsonBody);
        request.setBody(jsonBody);
        Http http = new Http();
        HttpResponse response = http.send(request);
     //   system.debug('response body: '+response.getBody());
        if(response.getStatusCode() == 200){
            BearRes res = (BearRes)json.deserialize(response.getBody(), BearRes.class);
            BearerToken = res.token;
        }
     //   system.debug(BearerToken);
        return BearerToken;
    }

    public class authWrapreq{
        public string clientId;
        public string username;
        public string password;
    }
    public class authRes{
        public string authorizationCode;
    }
    public class BearerWrapReq{
        public string clientId;
        public string clientSecret;
        public string authorizationCode;
    }
    public class BearRes{
        public string token;
    }
}


Any idea to resolve this issue?

Thanks,
Kezia
Hi,

I am generating a bearer token in API. Now, I want to add a condition to regenerate a new bearer token for every 6 days. 
This is my code:
-------------------
public class qcOauth {
    public static string AuthCode(){
        string Authcode;
        qc__c    Qc = qc__c.getvalues('qc details');
        authWrapreq Aw = new authWrapreq();
        Aw.clientId = Qc.Consumer_Key__c;
        Aw.username = Qc.UserName__c;
        Aw.password = Qc.Password__c;
        
        string endpoint = Qc.url__c+'verify';
        HttpRequest request = new HttpRequest();
        request.setEndpoint(endpoint);
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json');
        String jsonBody = JSON.serialize(Aw);
      //  system.debug('JSON BODY : '+jsonBody);
        request.setBody(jsonBody);
        Http http = new Http();
        HttpResponse response = http.send(request);
     //   system.debug('response body: '+response.getBody());
        if(response.getStatusCode() == 200){
            authRes res = (authRes)json.deserialize(response.getBody(), authRes.class);
            authcode = res.authorizationCode;
        }
     //   system.debug(authcode);
        return authcode;
    }
    
    public static string BearerToken(){
        string BearerToken;
        qc__c    Qc = qc__c.getvalues('qc details');
        BearerWrapReq Bw = new BearerWrapReq();
        Bw.clientId = Qc.Consumer_Key__c;
        Bw.clientSecret = Qc.Consumer_secret__c;
        Bw.authorizationCode = Authcode();
        
        string endpoint = Qc.url__c+'token';
        HttpRequest request = new HttpRequest();
        request.setEndpoint(endpoint);
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json');
        String jsonBody = JSON.serialize(Bw);
    //    system.debug('JSON BODY : '+jsonBody);
        request.setBody(jsonBody);
        Http http = new Http();
        HttpResponse response = http.send(request);
     //   system.debug('response body: '+response.getBody());
        if(response.getStatusCode() == 200){
            BearRes res = (BearRes)json.deserialize(response.getBody(), BearRes.class);
            BearerToken = res.token;
        }
     //   system.debug(BearerToken);
        return BearerToken;
    }

    public class authWrapreq{
        public string clientId;
        public string username;
        public string password;
    }
    public class authRes{
        public string authorizationCode;
    }
    public class BearerWrapReq{
        public string clientId;
        public string clientSecret;
        public string authorizationCode;
    }
    public class BearRes{
        public string token;
    }
}

Any Idea how to do this?

Thanks,
Kezia
 
Error: Malformed JSON: Expected '{' at the beginning of object.

I am getting this error while running this API. This is my code:

public class QcAPI {
    @future(callout=true)
    public static void callServer(String id){
        Opportunity opp =[Select Id,Account.FirstName,Account.ShippingAddress,Account.BillingAddress, Account.LastName,Email__c,DUP_Mobile__c,account.BillingStreet,account.BillingCity,account.BillingState,account.BillingCountry,account.BillingPostalCode,
                          account.ShippingStreet,account.ShippingCity,account.ShippingState,account.ShippingCountry,account.ShippingPostalCode from Opportunity where id=: id limit 1];
        
        OpportunityDataWrap oppdata = new OpportunityDataWrap();
        String rno = opp.Account.LastName+'-'+opp.Id;
        oppdata.refno = rno;
        oppdata.syncOnly = true;
        oppdata.deliveryMode = 'API';
        
        if(opp.Account.ShippingAddress !=null){
            ShippingAddressWrap cc = new ShippingAddressWrap();
            cc.firstname = opp.Account.LastName;
            cc.lastname = '';
            cc.email = opp.Email__c;
            cc.telephone = '+91'+opp.DUP_Mobile__c;
            cc.country = 'IN';
            cc.line1 = opp.Account.ShippingStreet;
            cc.line2 = '-';
            cc.city = opp.Account.ShippingCity;
            cc.postcode = opp.Account.ShippingPostalCode;
            cc.region = opp.Account.ShippingState;
            cc.billToThis = true;
            oppdata.address = cc;
        }
        
        if(opp.Account.BillingAddress !=null){
            BillingAddressWrap cb = new BillingAddressWrap();
            cb.firstname = opp.Account.lastname;
            cb.lastname = '';
            cb.email = opp.Email__c;
            cb.telephone = '+91'+opp.DUP_Mobile__c;
            cb.country = 'IN';
            cb.line1 = opp.Account.ShippingStreet;
            cb.line2 = '-';
            cb.city = opp.Account.ShippingCity;
            cb.postcode = opp.Account.ShippingPostalCode;
            cb.region = opp.Account.ShippingState; 
            oppdata.billing = cb;
        }
        List<paymentwrap> pw = new List<paymentwrap>();
        paymentwrap pwr = new paymentwrap();
        pwr.code = 'xyz';
        pwr.amount = 0;
        pw.add(pwr);
        oppdata.payments = pw;
        
        List<productsWrap> prodwrap = new List<productsWrap>();
        productsWrap pdwr = new productsWrap();
        pdwr.sku = 'xyzABCDE000';  
        pdwr.price = 0;
        pdwr.qty = 1;
        pdwr.currency_x =356;
        pdwr.giftMessage ='';
        pdwr.theme ='';
        prodwrap.add(pdwr);
        oppdata.products = prodwrap;
        system.debug('OppData:'+oppdata);
        String jsbody = JSON.serialize(oppdata);
        String jsonBody = jsbody.replace('currency_x', 'currency');
        system.debug('JSON BODY : '+jsonBody);
        map<string,Object> result = (map<string,Object>)JSON.deserializeUntyped(jsonBody);
        system.debug('result '+result);
        string endresult = JSON.serialize(result);
        system.debug('endresult '+endresult);

        String customLabelValue = Label.QCAPI+'/orders';
        //signature calling
        
        XYZ__c    Qc = XYZ__c.getvalues('XYZ details');
        string secretKeyValue = Qc.Consumer_secret__c;
        string reqMethod = 'POST';
        string url = EncodingUtil.URLEncode(Label.QCAPI+'/10000028/resend','UTF-8');
        system.JSONParser requestData = JSON.createParser(jsonBody);
        string endpoint = reqMethod + '&' + url;
        system.debug('end point url '+endpoint);
        string signature;
        Blob hmacData = Crypto.generateMac('HmacSHA512', Blob.valueOf(endpoint), Blob.valueOf(secretKeyValue));
        signature = encodingUtil.convertToHex(hmacData);
        system.debug('signature '+signature);
        
        string BearerToken = QCoauth.BearerToken();
        HttpRequest request = new HttpRequest();
        request.setEndpoint(customLabelValue);
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json');
        request.setHeader('Authorization',BearerToken);
        request.setHeader('Accept','*/*');
        request.setBody(jsonBody);
        Http http = new Http();
        HttpResponse response = http.send(request);
        system.debug('get response :'+response.getBody());
        system.debug('get response :'+response);
        ResponseData rd = (ResponseData)JSON.deserialize(response.getBody(), ResponseData.class);
        System.debug('Response Data :'+rd);
        
        Opportunity oppty = new Opportunity();
        oppty.Id = opp.id;
        oppty.ABC__c = rd.cards[0].cardNumber;
 //       oppty.Pin__c = rd.cards[0].cardPin;
        update oppty;

    }
    
    public class ShippingAddressWrap{
        public String firstname{get;set;}
        public String lastname{get;set;} 
        public String email{get;set;} 
        public String telephone{get;set;} 
        public String line1{get;set;} 
        public String line2{get;set;} 
        public String city{get;set;} 
        public String region{get;set;} 
        public String country{get;set;} 
        public String postcode{get;set;} 
        public boolean billToThis{get;set;} 
    }
    
    public class BillingAddressWrap{
        public String firstname{get;set;}
        public String lastname{get;set;} 
        public String email{get;set;} 
        public String telephone{get;set;} 
        public String line1{get;set;} 
        public String line2{get;set;} 
        public String city{get;set;} 
        public String region{get;set;} 
        public String country{get;set;} 
        public String postcode{get;set;} 
    }
    public class paymentwrap{
        public string code{get;set;}
        public double amount{get;set;}
    }
    public class productsWrap{
        public string sku{get;set;}
        public double price{get;set;}
        public integer qty{get;set;}
        public integer currency_x{get;set;}
        public string giftMessage{get;set;}
        public string theme{get;set;}
    }
    public class OpportunityDataWrap{    
        Public ShippingAddressWrap address{get;set;}
        Public BillingAddressWrap billing{get;set;}
        Public List<paymentwrap> payments{get;set;}
        public string refno{get;set;}
        public List<productsWrap> products{get;set;}
        public boolean syncOnly{get;set;}
        public String deliveryMode{get;set;} 
    }
    public class ResponseData {
        public string status;
        public List<cardwrap> cards;
    }
    public class cardwrap{
        public string cardNumber;
        public string cardPin;
    }
}

Any idea to resolve this issue?

Thanks,
Kezia
Hello Everyone,

I am facing an issue after conversion of lead. After converting the lead, when I click on opportunity it redirects to account record page instead of opportunity. I want it to redirects to opportunity after clicking the opportunity on lead conversion page.

Any Idea how to solve this?

Thanks
Kezia
Hi,
I have two objects i.e; Invoice and Account. Invoice is a custom object, in invoice object, I have a master detail field called "customer name__c". I want to populate the customer name field with account name while creating a new record in invoice object. I have tried with process builder and flows to populate the account name but I can't update it.

So, Any suggestion how to update it through trigger?

Thanks,
Kezia
Hi All,

I have two objects called Quote Line Items and Order Products. Using trigger I want to update the order products when quote line items are edited.

Any Idea how to do?

Thanks,
Kezia
Hi All,

I have a field called order__c in quote and quote line item objects. Using trigger, I want to update order__c field in quote line item, when order__c field in quote is updated. 

Any Idea how to do this?

Thank you,
Kezia
Hi,

I am getting 401 unauthorized error while running my API. I have checked the endpoint url and all credentials from server side, all are correct. Still getting this error. 
Error: [Status=Unauthorized, StatusCode=401]
"code":401,"message":"An error occurred. Header not set."
-------
This is my code:

public class QcAPI {
    @future(callout=true)
    public static void callServer(String id){
        Opportunity opp =[Select Id,Account.FirstName,Account.ShippingAddress,Account.BillingAddress, Account.LastName,Email__c,DUP_Mobile__c,account.BillingStreet,account.BillingCity,account.BillingState,account.BillingCountry,account.BillingPostalCode,
                          account.ShippingStreet,account.ShippingCity,account.ShippingState,account.ShippingCountry,account.ShippingPostalCode from Opportunity where id=: id limit 1];
        
        OpportunityDataWrap oppdata = new OpportunityDataWrap();
        String rno = opp.Account.LastName+'-'+opp.Id;
        oppdata.refno = rno;
        oppdata.syncOnly = true;
        oppdata.deliveryMode = 'API';
        
        if(opp.Account.ShippingAddress !=null){
            ShippingAddressWrap cc = new ShippingAddressWrap();
            cc.firstname = opp.Account.LastName;
            cc.lastname = '';
            cc.email = opp.Email__c;
            cc.telephone = '+91'+opp.DUP_Mobile__c;
            cc.country = 'IN';
            cc.line1 = opp.Account.ShippingStreet;
            cc.line2 = '-';
            cc.city = opp.Account.ShippingCity;
            cc.postcode = opp.Account.ShippingPostalCode;
            cc.region = opp.Account.ShippingState;
            cc.billToThis = true;
            oppdata.address = cc;
        }
        
        if(opp.Account.BillingAddress !=null){
            BillingAddressWrap cb = new BillingAddressWrap();
            cb.firstname = opp.Account.lastname;
            cb.lastname = '';
            cb.email = opp.Email__c;
            cb.telephone = '+91'+opp.DUP_Mobile__c;
            cb.country = 'IN';
            cb.line1 = opp.Account.ShippingStreet;
            cb.line2 = '-';
            cb.city = opp.Account.ShippingCity;
            cb.postcode = opp.Account.ShippingPostalCode;
            cb.region = opp.Account.ShippingState; 
            oppdata.billing = cb;
        }
        List<paymentwrap> pw = new List<paymentwrap>();
        paymentwrap pwr = new paymentwrap();
        pwr.code = 'xyz';
        pwr.amount = 0;
        pw.add(pwr);
        oppdata.payments = pw;
        
        List<productsWrap> prodwrap = new List<productsWrap>();
        productsWrap pdwr = new productsWrap();
        pdwr.sku = 'xyzABCDE000';  
        pdwr.price = 0;
        pdwr.qty = 1;
        pdwr.currency_x =356;
        pdwr.giftMessage ='';
        pdwr.theme ='';
        prodwrap.add(pdwr);
        oppdata.products = prodwrap;
        system.debug('OppData:'+oppdata);
        String jsbody = JSON.serialize(oppdata);
        String jsonBody = jsbody.replace('currency_x', 'currency');
        system.debug('JSON BODY : '+jsonBody);
        map<string,Object> result = (map<string,Object>)JSON.deserializeUntyped(jsonBody);
        system.debug('result '+result);
        string endresult = JSON.serialize(result);
        system.debug('endresult '+endresult);

        String customLabelValue = Label.QCAPI+'/orders';
        //signature calling
        
        XYZ__c    Qc = XYZ__c.getvalues('XYZ details');
        string secretKeyValue = Qc.Consumer_secret__c;
        string reqMethod = 'POST';
        string url = EncodingUtil.URLEncode(Label.QCAPI+'/10000028/resend','UTF-8');
        system.JSONParser requestData = JSON.createParser(jsonBody);
        string endpoint = reqMethod + '&' + url;
        system.debug('end point url '+endpoint);
        string signature;
        Blob hmacData = Crypto.generateMac('HmacSHA512', Blob.valueOf(endpoint), Blob.valueOf(secretKeyValue));
        signature = encodingUtil.convertToHex(hmacData);
        system.debug('signature '+signature);
        
        string BearerToken = QCoauth.BearerToken();
        HttpRequest request = new HttpRequest();
        request.setEndpoint(customLabelValue);
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json');
        request.setHeader('Authorization',BearerToken);
        request.setHeader('Accept','*/*');
        request.setBody(jsonBody);
        Http http = new Http();
        HttpResponse response = http.send(request);
        system.debug('get response :'+response.getBody());
        system.debug('get response :'+response);
        List<ResponseData> rd = (List<ResponseData>)JSON.deserialize(response.getBody(),List<ResponseData>.class);
        System.debug('Response Data :'+rd);
        
    }
    
    public class ShippingAddressWrap{
        public String firstname{get;set;}
        public String lastname{get;set;} 
        public String email{get;set;} 
        public String telephone{get;set;} 
        public String line1{get;set;} 
        public String line2{get;set;} 
        public String city{get;set;} 
        public String region{get;set;} 
        public String country{get;set;} 
        public String postcode{get;set;} 
        public boolean billToThis{get;set;} 
    }
    
    public class BillingAddressWrap{
        public String firstname{get;set;}
        public String lastname{get;set;} 
        public String email{get;set;} 
        public String telephone{get;set;} 
        public String line1{get;set;} 
        public String line2{get;set;} 
        public String city{get;set;} 
        public String region{get;set;} 
        public String country{get;set;} 
        public String postcode{get;set;} 
    }
    public class paymentwrap{
        public string code{get;set;}
        public double amount{get;set;}
    }
    public class productsWrap{
        public string sku{get;set;}
        public double price{get;set;}
        public integer qty{get;set;}
        public integer currency_x{get;set;}
        public string giftMessage{get;set;}
        public string theme{get;set;}
    }
    public class OpportunityDataWrap{    
        Public ShippingAddressWrap address{get;set;}
        Public BillingAddressWrap billing{get;set;}
        Public List<paymentwrap> payments{get;set;}
        public string refno{get;set;}
        public List<productsWrap> products{get;set;}
        public boolean syncOnly{get;set;}
        public String deliveryMode{get;set;} 
    }
    public class ResponseData {
        public string status;
        public List<cardwrap> cards;
    }
    public class cardwrap{
        public string cardNumber;
        public string cardPin;
    }
}
-----------
This is my Oauth code:

public class qcOauth {
    public static string AuthCode(){
        string Authcode;
        qc__c    Qc = qc__c.getvalues('qc details');
        authWrapreq Aw = new authWrapreq();
        Aw.clientId = Qc.Consumer_Key__c;
        Aw.username = Qc.UserName__c;
        Aw.password = Qc.Password__c;
        
        string endpoint = Qc.url__c+'verify';
        HttpRequest request = new HttpRequest();
        request.setEndpoint(endpoint);
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json');
        String jsonBody = JSON.serialize(Aw);
      //  system.debug('JSON BODY : '+jsonBody);
        request.setBody(jsonBody);
        Http http = new Http();
        HttpResponse response = http.send(request);
     //   system.debug('response body: '+response.getBody());
        if(response.getStatusCode() == 200){
            authRes res = (authRes)json.deserialize(response.getBody(), authRes.class);
            authcode = res.authorizationCode;
        }
     //   system.debug(authcode);
        return authcode;
    }
    
    public static string BearerToken(){
        string BearerToken;
        qc__c    Qc = qc__c.getvalues('qc details');
        BearerWrapReq Bw = new BearerWrapReq();
        Bw.clientId = Qc.Consumer_Key__c;
        Bw.clientSecret = Qc.Consumer_secret__c;
        Bw.authorizationCode = Authcode();
        
        string endpoint = Qc.url__c+'token';
        HttpRequest request = new HttpRequest();
        request.setEndpoint(endpoint);
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json');
        String jsonBody = JSON.serialize(Bw);
    //    system.debug('JSON BODY : '+jsonBody);
        request.setBody(jsonBody);
        Http http = new Http();
        HttpResponse response = http.send(request);
     //   system.debug('response body: '+response.getBody());
        if(response.getStatusCode() == 200){
            BearRes res = (BearRes)json.deserialize(response.getBody(), BearRes.class);
            BearerToken = res.token;
        }
     //   system.debug(BearerToken);
        return BearerToken;
    }

    public class authWrapreq{
        public string clientId;
        public string username;
        public string password;
    }
    public class authRes{
        public string authorizationCode;
    }
    public class BearerWrapReq{
        public string clientId;
        public string clientSecret;
        public string authorizationCode;
    }
    public class BearRes{
        public string token;
    }
}


Any idea to resolve this issue?

Thanks,
Kezia
Error: Malformed JSON: Expected '{' at the beginning of object.

I am getting this error while running this API. This is my code:

public class QcAPI {
    @future(callout=true)
    public static void callServer(String id){
        Opportunity opp =[Select Id,Account.FirstName,Account.ShippingAddress,Account.BillingAddress, Account.LastName,Email__c,DUP_Mobile__c,account.BillingStreet,account.BillingCity,account.BillingState,account.BillingCountry,account.BillingPostalCode,
                          account.ShippingStreet,account.ShippingCity,account.ShippingState,account.ShippingCountry,account.ShippingPostalCode from Opportunity where id=: id limit 1];
        
        OpportunityDataWrap oppdata = new OpportunityDataWrap();
        String rno = opp.Account.LastName+'-'+opp.Id;
        oppdata.refno = rno;
        oppdata.syncOnly = true;
        oppdata.deliveryMode = 'API';
        
        if(opp.Account.ShippingAddress !=null){
            ShippingAddressWrap cc = new ShippingAddressWrap();
            cc.firstname = opp.Account.LastName;
            cc.lastname = '';
            cc.email = opp.Email__c;
            cc.telephone = '+91'+opp.DUP_Mobile__c;
            cc.country = 'IN';
            cc.line1 = opp.Account.ShippingStreet;
            cc.line2 = '-';
            cc.city = opp.Account.ShippingCity;
            cc.postcode = opp.Account.ShippingPostalCode;
            cc.region = opp.Account.ShippingState;
            cc.billToThis = true;
            oppdata.address = cc;
        }
        
        if(opp.Account.BillingAddress !=null){
            BillingAddressWrap cb = new BillingAddressWrap();
            cb.firstname = opp.Account.lastname;
            cb.lastname = '';
            cb.email = opp.Email__c;
            cb.telephone = '+91'+opp.DUP_Mobile__c;
            cb.country = 'IN';
            cb.line1 = opp.Account.ShippingStreet;
            cb.line2 = '-';
            cb.city = opp.Account.ShippingCity;
            cb.postcode = opp.Account.ShippingPostalCode;
            cb.region = opp.Account.ShippingState; 
            oppdata.billing = cb;
        }
        List<paymentwrap> pw = new List<paymentwrap>();
        paymentwrap pwr = new paymentwrap();
        pwr.code = 'xyz';
        pwr.amount = 0;
        pw.add(pwr);
        oppdata.payments = pw;
        
        List<productsWrap> prodwrap = new List<productsWrap>();
        productsWrap pdwr = new productsWrap();
        pdwr.sku = 'xyzABCDE000';  
        pdwr.price = 0;
        pdwr.qty = 1;
        pdwr.currency_x =356;
        pdwr.giftMessage ='';
        pdwr.theme ='';
        prodwrap.add(pdwr);
        oppdata.products = prodwrap;
        system.debug('OppData:'+oppdata);
        String jsbody = JSON.serialize(oppdata);
        String jsonBody = jsbody.replace('currency_x', 'currency');
        system.debug('JSON BODY : '+jsonBody);
        map<string,Object> result = (map<string,Object>)JSON.deserializeUntyped(jsonBody);
        system.debug('result '+result);
        string endresult = JSON.serialize(result);
        system.debug('endresult '+endresult);

        String customLabelValue = Label.QCAPI+'/orders';
        //signature calling
        
        XYZ__c    Qc = XYZ__c.getvalues('XYZ details');
        string secretKeyValue = Qc.Consumer_secret__c;
        string reqMethod = 'POST';
        string url = EncodingUtil.URLEncode(Label.QCAPI+'/10000028/resend','UTF-8');
        system.JSONParser requestData = JSON.createParser(jsonBody);
        string endpoint = reqMethod + '&' + url;
        system.debug('end point url '+endpoint);
        string signature;
        Blob hmacData = Crypto.generateMac('HmacSHA512', Blob.valueOf(endpoint), Blob.valueOf(secretKeyValue));
        signature = encodingUtil.convertToHex(hmacData);
        system.debug('signature '+signature);
        
        string BearerToken = QCoauth.BearerToken();
        HttpRequest request = new HttpRequest();
        request.setEndpoint(customLabelValue);
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json');
        request.setHeader('Authorization',BearerToken);
        request.setHeader('Accept','*/*');
        request.setBody(jsonBody);
        Http http = new Http();
        HttpResponse response = http.send(request);
        system.debug('get response :'+response.getBody());
        system.debug('get response :'+response);
        ResponseData rd = (ResponseData)JSON.deserialize(response.getBody(), ResponseData.class);
        System.debug('Response Data :'+rd);
        
        Opportunity oppty = new Opportunity();
        oppty.Id = opp.id;
        oppty.ABC__c = rd.cards[0].cardNumber;
 //       oppty.Pin__c = rd.cards[0].cardPin;
        update oppty;

    }
    
    public class ShippingAddressWrap{
        public String firstname{get;set;}
        public String lastname{get;set;} 
        public String email{get;set;} 
        public String telephone{get;set;} 
        public String line1{get;set;} 
        public String line2{get;set;} 
        public String city{get;set;} 
        public String region{get;set;} 
        public String country{get;set;} 
        public String postcode{get;set;} 
        public boolean billToThis{get;set;} 
    }
    
    public class BillingAddressWrap{
        public String firstname{get;set;}
        public String lastname{get;set;} 
        public String email{get;set;} 
        public String telephone{get;set;} 
        public String line1{get;set;} 
        public String line2{get;set;} 
        public String city{get;set;} 
        public String region{get;set;} 
        public String country{get;set;} 
        public String postcode{get;set;} 
    }
    public class paymentwrap{
        public string code{get;set;}
        public double amount{get;set;}
    }
    public class productsWrap{
        public string sku{get;set;}
        public double price{get;set;}
        public integer qty{get;set;}
        public integer currency_x{get;set;}
        public string giftMessage{get;set;}
        public string theme{get;set;}
    }
    public class OpportunityDataWrap{    
        Public ShippingAddressWrap address{get;set;}
        Public BillingAddressWrap billing{get;set;}
        Public List<paymentwrap> payments{get;set;}
        public string refno{get;set;}
        public List<productsWrap> products{get;set;}
        public boolean syncOnly{get;set;}
        public String deliveryMode{get;set;} 
    }
    public class ResponseData {
        public string status;
        public List<cardwrap> cards;
    }
    public class cardwrap{
        public string cardNumber;
        public string cardPin;
    }
}

Any idea to resolve this issue?

Thanks,
Kezia