• Anirban Roy
  • NEWBIE
  • 15 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
Hi Gurus,

I am writing the below apex code to get the response from one of the other salesforce org using request/response mechanism. But getting the below error from the asynchronous block.
'First error: Apex CPU time limit exceeded'

Please find below the code

public class SendAccountUsingRESTAPI {
    
    private final string clientId = '*****';
    private final string clientSecret = '350708****';
    private final string username = 'somnath.pa****';
    private final string password = 'June2015gPe****';
    
    public class deserializeresponse
    {
        public string access_token;
        public string name;
        public string Integration_Id;
        public string id;
        public string description;
    }
    
    public string ReturnAccessToken(SendAccountUsingRESTAPI acc)
    {
        string reqBody = 'grant_type=password&client_id='+clientId+'&client_secret='+clientSecret+'&username='+username+'&password='+password;
        System.Http h = new System.Http();
        System.HttpRequest req = new System.HttpRequest();
        req.setBody(reqBody);
        req.setMethod('POST');
        req.setEndpoint('https://login.salesforce.com/services/oauth2/token');
        System.HttpResponse res = h.send(req);
        System.debug('Actual response' + res);
        deserializeresponse resp1 = (deserializeresponse)JSON.deserialize(res.getBody(), deserializeresponse.class);
        System.debug('deserialized  response' + resp1);
        return resp1.access_token;
    }
    
    @future(callout = true)
    public static void callcreateAcc( string name, Id Accountid)
    {
        SendAccountUsingRESTAPI send = new SendAccountUsingRESTAPI();
        string access_token = send.ReturnAccessToken(send);
        
        if(access_token != null)
        {
            string endpoint = 'https://ap2.salesforce.com/services/apexrest/v1/createAccount/';
            //'{"AccName" : "' + accName + '"}';
            string jsonstr = '{"AccName" : "' + name + '","accId" : "'+ Accountid + '"}';
            Http h2 = new Http();
            HttpRequest req1 = new HttpRequest();
            req1.setHeader('Authorization','Bearer ' + access_token);
            req1.setHeader('Content-Type','application/json');
            req1.setHeader('accept','application/json');
            req1.setBody(jsonstr);
            req1.setMethod('POST');
            req1.setEndpoint(endpoint);
            try
            {
            HttpResponse res = h2.send(req1);
            System.debug('Body of the response'+res.getBody());
            System.XmlStreamReader reader = new XmlStreamReader(res.getBody());
            System.debug('Response in XML format'+reader);
            Account accnt = [select description,Integration_Id__c,Id from Account where Id=:Accountid];
            
            deserializeresponse accrec;
            List<deserializeresponse> listofAcc = new List<deserializeresponse>();
            
                while(reader.hasNext())
                {
                   if(reader.getEventType()==xmltag.START_ELEMENT) 
                   {
                       if('Account' == reader.getLocalName())
                       {
                         accrec = new deserializeresponse();   
                       }
                       else if('Name' == reader.getLocalName())
                       {
                           accrec.Name = getvalufromTag(reader);
                       }
                       else if('INTEGRATION iD' == reader.getLocalName())
                       {
                           accrec.Description = getvalufromTag(reader);
                       }
                       else if('AccountId' == reader.getLocalName())
                       {
                           accrec.Integration_Id = getvalufromTag(reader);
                       }
                       
                   }
                    else if(reader.getEventType()==xmltag.END_ELEMENT)
                    {
                        if('Account' == reader.getLocalName())
                        {
                            listofAcc.add(accrec);
                        }
                        else if('Accounts'==reader.getLocalName())
                        {
                            break;
                        }
                    }
                }
                
               /* for(Account acct:listofAcc)
                {
                    acc
                }*/
                system.debug('List value'+listofAcc.size());
                
                for(deserializeresponse resp:listofAcc)
                {
                    //accnt.Descriptions = resp.description;
                    accnt.Description = resp.description;
                    accnt.Integration_Id__c= resp.Integration_Id;
                }
                
                //insert listofAcc;
                update accnt;
            }
            catch(Exception e)
            {
                System.debug('Callout error'+ e.getMessage());
            }
        }
        
    }
    
    static string getvalufromTag(XmlStreamReader reader)
    {
        
        string tagval;
        while(reader.hasNext())
        {
            if(reader.getEventType()==xmltag.END_ELEMENT)
            {
                break;
            }
            else if(reader.getEventType()==xmltag.CHARACTERS)
            {
                tagval = reader.getText();
            }
            reader.next();
        }
        return tagval;
    }

}

Incoming request is in the below format...


<?xml version="1.0" encoding="UTF-8"?>
<Accounts>
<Account>
<Name>Test International Shipping Co.</Name>
<INTEGRATION iD>00128000003nrBhAAI</INTEGRATION iD>
<AccountId>00128000003nrBhAAI</AccountId>
</Account>
<Account>
<Name>Test International Shipping Co.</Name>
<INTEGRATION iD>00128000003nrBhAAI</INTEGRATION iD>
<AccountId>00128000003nrBhAAI</AccountId>
</Account>
</Accounts>

Regards
Somnath
 
Dear Friends,

I am facing some newbie jerks while trying to call a controller froma  VF Page.

This is the error which I tried to debug a lot from Developer forums, but not of much help:

Error is: Formula Expression is required on the action attributes.

My VF Page:

<apex:page controller="BankDetailsController">
     <apex:form >
   <apex:pageBlock >
      <apex:commandButton value="BANK" action="{!getbankDet}"/>
         <apex:pageBlockSection>
             Following are the Bank Details
                   {!Response}    
       </apex:pageBlockSection>
  </apex:pageBlock>
  </apex:form>
</apex:page>

My Controller: calls a web service which I imported as a Apex class in my org <basically its a web service written in another salesforce org of mine>

public class BankDetailsController {
    
    //public string bank { get { return getbankDet(); } }
    public String Response {get; set;}
    public string getbankDet() 
    {

        string accname = 'GoGlobalStrategies';
        partnerSoapSforceCom.Soap myPartnerSoap = new partnerSoapSforceCom.Soap(); 
        partnerSoapSforceCom.LoginResult partnerLoginResult = myPartnerSoap.login('somnath.paul4@cognizant.com', 'MyPasswordgPeEzXp6zqiICng3M8wKQtqd');
        soapSforceComSchemasClassGetbankdet.SessionHeader_element webserviceSessionHeader=new soapSforceComSchemasClassGetbankdet.SessionHeader_element();
        webserviceSessionHeader.sessionId = partnerLoginResult.sessionId;
        soapSforceComSchemasClassGetbankdet.GetBankDetailsofAccount getBankdet=new soapSforceComSchemasClassGetbankdet.GetBankDetailsofAccount();
        getBankdet.SessionHeader=webserviceSessionHeader;
        Response = getBankdet.getBankDetails(accname);
        return Response;
 }
}

When I click on the BANK button in my VF Page, the response should flow in, but actually the error flows out :(

Can anyone tell me where am I going wrong here?
 
Dear Friends,

I am facing some newbie jerks while trying to call a controller froma  VF Page.

This is the error which I tried to debug a lot from Developer forums, but not of much help:

Error is: Formula Expression is required on the action attributes.

My VF Page:

<apex:page controller="BankDetailsController">
     <apex:form >
   <apex:pageBlock >
      <apex:commandButton value="BANK" action="{!getbankDet}"/>
         <apex:pageBlockSection>
             Following are the Bank Details
                   {!Response}    
       </apex:pageBlockSection>
  </apex:pageBlock>
  </apex:form>
</apex:page>

My Controller: calls a web service which I imported as a Apex class in my org <basically its a web service written in another salesforce org of mine>

public class BankDetailsController {
    
    //public string bank { get { return getbankDet(); } }
    public String Response {get; set;}
    public string getbankDet() 
    {

        string accname = 'GoGlobalStrategies';
        partnerSoapSforceCom.Soap myPartnerSoap = new partnerSoapSforceCom.Soap(); 
        partnerSoapSforceCom.LoginResult partnerLoginResult = myPartnerSoap.login('somnath.paul4@cognizant.com', 'MyPasswordgPeEzXp6zqiICng3M8wKQtqd');
        soapSforceComSchemasClassGetbankdet.SessionHeader_element webserviceSessionHeader=new soapSforceComSchemasClassGetbankdet.SessionHeader_element();
        webserviceSessionHeader.sessionId = partnerLoginResult.sessionId;
        soapSforceComSchemasClassGetbankdet.GetBankDetailsofAccount getBankdet=new soapSforceComSchemasClassGetbankdet.GetBankDetailsofAccount();
        getBankdet.SessionHeader=webserviceSessionHeader;
        Response = getBankdet.getBankDetails(accname);
        return Response;
 }
}

When I click on the BANK button in my VF Page, the response should flow in, but actually the error flows out :(

Can anyone tell me where am I going wrong here?
 
Hi,

We used to use a home page component (HTML Area) that had some javascript code to hide the standard "Submit for Approval" button on our custom object Contact Approval. This button was hidden because we use a custom button for the approval flow with some extra code behind. Since Summer '15 this hiding of the standard button is not working anymore.
Is there a way to remove this standard button from the Approval History related list?
Maybe with visualforce component on the home page? I tried but didn't manage to get it done.
On the following website I saw that it would not be possible anymore (see point 8): https://help.salesforce.com/apex/HTViewSolution?urlname=Home-Page-Components-Changes-Starting-Summer-14&

Please provide me with a solution, if there is any...

Thank you!

Kind regards
Jago

Hi,

I'm facing a weird error "Formula Expression is required on the action attributes".

 

My VF Page:

<apex:commandButton value="Log-in"  action="{!loginTest}"/>

 

My Class:

public pagereference loginTest(){
pagereference redirect = new PageReference('apex/newPage');
redirect.setRedirect(true);
system.debug('Hello@@'+redirect);
return redirect;
}

 

But when I click on login button i'm facing a weird error 'Formula Expression is required on the action attributes'.

 

Syntax looks fine,but some how it is not working.

Any help is much appreciated :)