• Venkat@12
  • NEWBIE
  • 0 Points
  • Member since 2012

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

Hi,

 

Below is my code. I pasted it from a Ajax api tool kit pdf available on the site

 

When i save the code, i gives me an error Object Expected. Please help

 

<apex:page >

<script src="../../soap/ajax/25.0/connection.js"
type="text/javascript"></script>

    <script type="text/javascript">
    window.onload = test;
    function test(){
     
      try{
        var result = sforce.connection.query("Select Name, Id from User");
        var records = result.getArray("records");
        for (var i=0; i< records.length; i++) {
        var record = records[i];
        sforce.debug.log(record.Name + " -- " + record.Id);
        } catch(error){
            sforce.debug.log(error);
          }
           
       }
       
    </script>
 
  <div id="output"> </div>
</apex:page>

 

 

Thanks,

Venkat

Hi,

I Have created a custom object and inserted data into it. I have written a VisualForce Page and an Apex Controller to search the data. I could see the count in logs, but the data is not displaying on the VF Page. Below is my Code

 

VisualForce Page

 

<apex:page controller="ItemController">
<style>
.activeTab {background-color: #236FBD; color:white;
background-image:none}
.inactiveTab { background-color: lightgrey; color:black;
background-image:none}
</style>
<apex:tabPanel title="Panel1" inactiveTabClass="inactiveTab" switchType="client" selectedTab="addItem" activeTabClass="activeTab">
<apex:tab label="Add Items" name="Master1" id="addItem">
<apex:outputText >You Can add/Remove Items Details Here</apex:outputText>
<apex:form >
<!-- <apex:commandButton value="Add Item" reRender="details"/>-->

<apex:pageBlock title="details">
<apex:pageBlockSection title="ADD ITEMS">
<p> Item Name:<apex:inputText value="{!Name}"/></p>
<p> Item Desc:<apex:inputTextarea value="{!Name}" rows="3"/></p>
<p> Item Price:<apex:inputText value="{!Name}"/></p>
<p> Added By:<apex:inputText value="{!Name}"/></p>
<p> Added On:<apex:inputText value="{!Name}"/></p>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:tab>
<apex:tab label="Search Items" id="Master2">
<APEX:OUTputLabel >You Can Search For Items Here</APEX:OUTputLabel>
<apex:form >
<apex:outputLabel >Enter Item:</apex:outputLabel>
<apex:inputText id="searchText" value="{!searchText}"/>
<apex:commandButton value="Search" action="{!searchItem}" rerender="Results" status="status">
</apex:commandButton>

<apex:pageBlock >
<apex:actionStatus id="status" startText="requesting..."/>
<apex:pageBlockSection title="Results" id="results" columns="1">
<apex:pageBlockTable value="{!itemDetails}" var="items" rendered="{!NOT(ISNULL(itemDetails))}">
<apex:column value="{!items.Price__c}" headerValue="Price"/>

</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>

 

</apex:form>


</apex:tab>
<apex:tab label="View Sales" id="viewSales">
<apex:outputText >You can view the Sales Report Here</apex:outputText>
</apex:tab>
<apex:tab label="Buy Items" id="butItems">
<apex:outputText >You Can Buy Items here</apex:outputText>
</apex:tab>
</apex:tabPanel>
<apex:toolbar >
</apex:toolbar>

</apex:page>

 

Apex Controller

-------------------------

public class ItemController {
public String results { get; set; }
public List<ShopItem__c> itemDetails {get;set;}

public PageReference searchItem() {

String qry = 'select Price__c from ShopItem__c where ItemName__c =:searchText order By Price__c';
system.debug('Query:'+qry);
itemDetails = Database.query(qry);
// itemDetails = (List<ShopItem__c>)[select ItemName__c from ShopItem__c];
system.Debug('itemDetailssize***:'+itemDetails.size());
return null;
}


public String searchText { get; set; }

public String Name { get; set; }

public String ShopItem { get; set; }


public PageReference saveItem() {

return null;
}

}

 

Kindly Please help

 

Regards

Venkat

Hi,

I Have created a custom object and inserted data into it. I have written a VisualForce Page and an Apex Controller to search the data. I could see the count in logs, but the data is not displaying on the VF Page. Below is my Code

 

VisualForce Page

 

<apex:page controller="ItemController">
<style>
.activeTab {background-color: #236FBD; color:white;
background-image:none}
.inactiveTab { background-color: lightgrey; color:black;
background-image:none}
</style>
<apex:tabPanel title="Panel1" inactiveTabClass="inactiveTab" switchType="client" selectedTab="addItem" activeTabClass="activeTab">
<apex:tab label="Add Items" name="Master1" id="addItem">
<apex:outputText >You Can add/Remove Items Details Here</apex:outputText>
<apex:form >
<!-- <apex:commandButton value="Add Item" reRender="details"/>-->

<apex:pageBlock title="details">
<apex:pageBlockSection title="ADD ITEMS">
<p> Item Name:<apex:inputText value="{!Name}"/></p>
<p> Item Desc:<apex:inputTextarea value="{!Name}" rows="3"/></p>
<p> Item Price:<apex:inputText value="{!Name}"/></p>
<p> Added By:<apex:inputText value="{!Name}"/></p>
<p> Added On:<apex:inputText value="{!Name}"/></p>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:tab>
<apex:tab label="Search Items" id="Master2">
<APEX:OUTputLabel >You Can Search For Items Here</APEX:OUTputLabel>
<apex:form >
<apex:outputLabel >Enter Item:</apex:outputLabel>
<apex:inputText id="searchText" value="{!searchText}"/>
<apex:commandButton value="Search" action="{!searchItem}" rerender="Results" status="status">
</apex:commandButton>

<apex:pageBlock >
<apex:actionStatus id="status" startText="requesting..."/>
<apex:pageBlockSection title="Results" id="results" columns="1">
<apex:pageBlockTable value="{!itemDetails}" var="items" rendered="{!NOT(ISNULL(itemDetails))}">
<apex:column value="{!items.Price__c}" headerValue="Price"/>

</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>

 

</apex:form>


</apex:tab>
<apex:tab label="View Sales" id="viewSales">
<apex:outputText >You can view the Sales Report Here</apex:outputText>
</apex:tab>
<apex:tab label="Buy Items" id="butItems">
<apex:outputText >You Can Buy Items here</apex:outputText>
</apex:tab>
</apex:tabPanel>
<apex:toolbar >
</apex:toolbar>

</apex:page>

 

Apex Controller

-------------------------

public class ItemController {
public String results { get; set; }
public List<ShopItem__c> itemDetails {get;set;}

public PageReference searchItem() {

String qry = 'select Price__c from ShopItem__c where ItemName__c =:searchText order By Price__c';
system.debug('Query:'+qry);
itemDetails = Database.query(qry);
// itemDetails = (List<ShopItem__c>)[select ItemName__c from ShopItem__c];
system.Debug('itemDetailssize***:'+itemDetails.size());
return null;
}


public String searchText { get; set; }

public String Name { get; set; }

public String ShopItem { get; set; }


public PageReference saveItem() {

return null;
}

}

 

Kindly Please help

 

Regards

Venkat

Hi,

 

I'm using AJAS toolkit to call Apex class method from Javascript. The javascript used for calling Apex class method is added in SFDC using Custom Home Page component.

 

To call Apex class method, it is mandatory to use "sforce.connection.login" method to get sessionId. The login method accepts username, password and token to authenticate and create session. Once authentication is successful, I can use "sforce.apex.execute" method to call Apex class method.

 

I wish to skip call to "sforce.connection.login" and use logged-in users session so that I don't have to specify User Name, password and token in javascript. Is there any way I can use logged-in Users session in AJAX toolkit. Any help in this regard is appriciated.

 

Thanks,

Prasad

 

 

<apex:page >
<html>
<head>
<title> Ajax ToolKit </title>
 <script src="/soap/ajax/22.0/connection.js" type="text/javascript"></script>
  <script language="JavaScript">
  function check()
  {
 
 try{
    var result = sforce.connection.login("a@abc.com", "password");
    alert("result");
    alert("you are loged in");
    
    log("logged in with session id " + result.sessionId);
  }

catch(error) {


  alert("Wrong user name and password");

    if (error.faultcode.indexOf("INVALID_LOGIN") != -1) {
   // alert(error);
      sforce.debug.log("check your username and passwd, invalid login");
    } else {
      sforce.debug.log(error);
    }
  }
   }
  </script>
  
</head>
  <body>
  <apex:form >
  <apex:commandButton onclick="check();" value="Click"/>
</apex:form>
</body>
</html>
</apex:page>

 

// When I run this code it wil not respond me correctly either i entered correct credentials in mentioned red line above.

It took me at the alert message " Wrone Username and Password"

Please help me. If there is any error in my code let me.

  • June 03, 2011
  • Like
  • 0