• Philip_F
  • NEWBIE
  • 25 Points
  • Member since 2008

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 18
    Replies
To All,

Well I've looked at MANY of the already existing messages about the "invalid_session_id" error arising during attempts to use an S-Control, but don't THINK that any have really FULLY addressed my situation.

As an example, I've created a very simple HTML S-Control definition that recreates the "invalid_session_id" error:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
   <head>
      <title>Create Household S-Control</title>
      <script language="javascript"
              src="/soap/ajax/13.0/connection.js"
              type="text/javascript"></script>
      <script language="javascript"
              type="text/javascript">
<!--
function initPage() {
   //Tests S-control function by attempting to create new account rec

   alert("running initPage function");

   //Calculate name value
   var nameval = "{!Contact.FirstName} {!Contact.LastName}"
                 + " Test Account";
   alert("calculated name: " + nameval);

   var obj = new sforce.SObject("Account");
   alert("past creation of javascript SObject");
   alert("created SObject of type: " + obj.type);
   obj.Name = nameval;
   //alert("finished assigning values to javascript Sbject");

   //create db rec using SObject
   try {
      var saveResult = sforce.connection.create([obj]);
      alert("successfully created db record");
   }
   catch(error) {
      alert("Error creating db rec: (" + error.faultcode + ") "
            + error.faultstring);
   }

}
//-->
      </script>
   </head>
   <body onload="initPage()">
      <div id="js_output">
      </div>
   </body>
</html>

I've defined a detail button on the main "Contacts" layout to trigger this S-Control.  I'm running it with a profile of "system administrator", and with the "API Access" setting in place.  I've also double-checked settings of the sharing rules in effect for this instance of SalesForce to ensure both read and write privileges are avalable.  I'm using a SalesForce instance established using the non-profit template from just about 5 months ago. 

When the S-Control is executed, all goes well until the attempted "sforce.connection.create".  At this point, the "catch" block is triggered and the alert message displaying the error message is displayed.

I'll anxiously away the valuable advice/thoughts of this community...   

Thanks MUCH.

Larry

Hello All,

 

I'm working on a solution in a trigger where I need to access the entire hierarchy of parent accounts for a given account.  At the moment, I'm recursively querying the account table for each account's Parent based on ParentId.  

 

This solution is fragile because if there were enough parent account to child account layers, then the trigger would hit the query limit.

 

Is there a way to access data about accounts at each level in a hierarchy without recursive querying?  It would be splendid if I could run a single query and get back a Map of Accounts or something along those lines.

  


private static string getTopParentAccountName(Account thisAccount) {
if (thisAccount.ParentId != null) {
// Get the parent account for this account and pass it to this function for recursion
Account parentAccount = [Select a.ParentId, a.Name, a.Id From Account a where a.Id = :thisAccount.ParentId];
return getTopParentAccount(parentAccount);
}
else { // There's no parent account
return thisAccount.Name;
}
}

 

The code above is representative of the logic I'm employing.  (This isn't the actual code I'm using, it's something I worked up to illustrate my point, so please ignore any minor errors in the code.) 

 

I checked the Apex Relationship Queries Documentation and found the following comments that seem relevant:
  • In each specified relationship, no more than five levels can be specified in a child-to-parent relationship. For example, Contact.Account.Owner.FirstName (three levels).
  • In each specified relationship, only one level of parent-to-child relationship can be specified in a query. For example, if the FROM clause specified Account, the SELECT clause could only specify the Contact or other objects at that level. It could not specify a child object of Contact. 
 
Any thoughts on how to handle this situation and get around the governor limitations?     
 
All input is appreciated!
 
Cheers,
-Philip

 Hello All,

 

I have an OpportunityLineItem (oli) before insert trigger that references the oli.ListPrice value.  The trigger works great in my sandbox when manually testing through the UI but is failing due to a null value for oli.ListPrice un unit testing.

 

I have verified that the issue is specifically that the oli.ListPrice value is null when adding the oli through the unit test code, but the ListPrice is not null when adding an oli through the UI.

 

Naturally, I suspected the unit test code had an issue with the PriceBook and PriceBookEntry process.  But after scouring the code, the Apex Code Language Reference section "Testing the Sample Application", and the developer boards, I'm not seeing anything that explains why the oli.ListPrice value would be null in the unit test.

 

The behavior seems like the assignment of the oli.ListPrice from the pbe.UnitPrice isn't happening in the correct sequence when the unit test is running but is occurring correctly when the UI is used.

 

Here is the unit test code that is resulting in a null oli.ListPrice when the oli before insert trigger is firing:



public class testTrigger {
static testMethod void testTriggers_Trigger () {

Product2 p = new product2(name='Test Product');
insert p;

Pricebook2 stdPb = [select Id from Pricebook2 where isStandard=true limit 1];
insert new PricebookEntry(pricebook2id = stdPb.id, product2id = p.id, unitprice=100.0, isActive=true);

Pricebook2 pb = new pricebook2(name='test pricebook');
insert pb;

PricebookEntry pbe = new PricebookEntry(pricebook2id=pb.id, product2id=p.id, unitprice=100.0, isActive=true);
insert pbe;

Opportunity o = new Opportunity(name='test', pricebook2id=pb.id, stageName='Open', CloseDate=Date.newInstance(2009,10,10) );
insert o;

OpportunityLineItem oli = new OpportunityLineItem(opportunityid=o.id, UnitPrice=100, quantity=1, pricebookentryid=pbe.Id);
insert oli;

}
}

 

 

I hope that you read this post and chuckle as you gently explain the obvious piece that I'm missing.  Otherwise, any input is appreciated.

 

Cheers,

-Philip 

 

 


 

Message Edited by Philip_F on 03-01-2009 06:01 PM
Message Edited by Philip_F on 03-01-2009 06:02 PM

how can we check the debug logs of guest users

I'd like all our case comments to be marked as public (as I have a workflow rule linked to this object that only fires if the "public"-checkbox is marked..).

 

Apparantly it is not possible to get the checkbox marked at the very moment the user creates the case comment (link).

 

However, is it possible to make the "public"-checkbox required, so that users always have to mark it?

 

 

Thanks in advance.

Hi guys.

 

Bit of a conundrum here...

 

I've got a VF page that has an inputText field that users use to scan in barcodes using a handheld barcode scanner.

The barcode scanner merely act like a keyboard: it translates the scan to keys, then types those keys and hits enter.

 

What I'd like to do, is have users scan a barcode, then conduct an apex query. If the results are good, it updates a record, if the results are bad - it throws a pageMessage.

 

I got some JS that checks when the enter key is hit, and then I envoke the apex. However, there seems to be an issue with the sequence of reRendering and apex, and JS.

 

When I do the scan into the input field - the page does a refresh - but the apex:PageMessage that should display does not...

 

Here's what I have so far:

 

 

<apex:page standardController="terminalPrepOrder__c" extensions="terminalPrepOrderController" >
<apex:variable var="prp" value="{!terminalPrepOrder__c}"/>

function checkEnter(e){ <!-- e is event object passed from function invocation -->
var characterCode <!--literal character code will be stored in this variable -->

if(e && e.which){ <!--if which property of event object is supported (NN4) -->
e = e
characterCode = e.which <!-- character code is contained in NN4's which property -->
}
else{
e = event
characterCode = e.keyCode <!-- character code is contained in IE's keyCode property -->
}

if(characterCode == 13){ <!-- if generated character code is equal to ascii 13 (if enter key) -->
alert("clicked enter");
otherFindTerminal(); <!-- submit the form -->
return false;
}
else{
return true
}
}
</script>

<apex:pageMessages id="msgs"/>
<apex:form id="theForm"> <apex:actionFunction name="findTerminal" action="{!otherFindTerminal}" reRender="msgs"/> <apex:outputText value="Scan Terminal Barcode "/> <apex:inputText value="{!searchBarcode}" onkeypress="checkEnter(event)"/> <apex:commandButton value="Find" action="{!otherFindTerminal}" id="hitMe" reRender="msgs"/> </apex:form>

 Controller:

 

	public PageReference otherFindTerminal() {  
        try {
            if (searchBarcode != '') {
              terminal__c enteredTrm = [select Id from Terminal__c T where T.barcodeNumber__c = :searchBarcode limit 1];        
           
             terminalPrepOrder__c trmPrp = (terminalPrepOrder__c) controller.getRecord();
           
             trmPrp.Terminal__c = enteredTrm.Id;
             update trmPrp;
            }
            else if (searchBarcode == '' ) {
                ApexPages.Message invalidSearch = new ApexPages.Message(ApexPages.Severity.ERROR, 'Invalid barcode.');
                ApexPages.addMessage(invalidSearch);
            }
        }
        catch (exception e) {
        
            ApexPages.Message noTrm = new ApexPages.Message(ApexPages.Severity.ERROR, searchBarcode + ' not found. Please enter the Terminal barcode.');
            ApexPages.addMessage(noTrm);
        }
        return null;
    }

 

 

 

So when I click the commandButton - it functions perfectly - It does the query, and rerenders the messages...

 

When I use the input field and hit enter... it refreshes the page but does nothing...

 

 

Please help!

Thanks

  • May 10, 2010
  • Like
  • 0

Hi all,

Trying to allow users to create a case via sites on our intranet.  That isnt a problem, however I dont seem to be able to allow the user to create Attachments.

 

There's nothing in the user profile to allow access to Attachments that I can see but I'm getting Authorization errors when I try and insert an attachment.

 

Anyone know how I can do this?

 

Thanks

Steven

I have created a web2contact form using Sites however whenever you submit on the form you are presented with an "Authorization Required" error message.

 

Has anyone else come across this before ? 

 

I have checked everything including the Guest User Profile permissions, field level security on Contacts object etc. but all looks fine.

 

Really appreciate any help with this one !

I'm having a bear of a time importing attachments using the excel connector.  I have the full file name in the body field (C:\Attachments\filename.xxx).  It's just inserting the description information with no content.  It places that information in the right location.  Just no data.

 

Any thoughts?  Any tricks I should be looking for that I might be missing?

 

Thanks. 

Hello,

 

I created a Visualforce page for Contacts for looking at a filtered Activity History.  I ran into an issue where if I used the object "ActivityHistories", users got an Internal Server error; however, if I changed this to Tasks, the page rendered fine.

 

Does anyone know the difference here?  Looking at the Profile Management screen, I cannot see any specific setting options for Activity History that would explain this.

 

Below is the page for reference.  The line in question is the <apex:repeat> section, where if I change the value to {!Contact.ActivityHistories}, the page renders fine for me (Sys Admin) but not for other users.

 

Thank you.

 

 

 

<apex:page standardController="Contact"> <apex:pageBlock title="{!contact.name}"> You are viewing the {!contact.name}'s Activity History. <a href='/{!contact.Id}'>Back to Contact Record</a> </apex:pageBlock> <apex:pageBlock title="{!contact.name} Activity History"> <apex:repeat value="{!contact.Tasks}" var="task" > <apex:pageBlockSection title="{!task.Subject} ({!task.ActivityDate})" columns="1" rendered="{!IF(task.WhatId == null, true, false)}"> <apex:outputField value="{!task.Subject}" /> <apex:outputField title="Due Date" value="{!task.ActivityDate}"/> <apex:outputField value="{!task.OwnerId}"/> <apex:outputField value="{!task.LastModifiedDate}"/> <apex:outputField value="{!task.Description}"/> </apex:pageBlockSection> </apex:repeat> </apex:pageBlock> </apex:page>

 

 

 

I've seen lots of pages asking about embedding a VF to the standard Edit Page layout (not supported).

 

I'm looking at maybe doing the opposite. I would like to be able to have a visualforce page that I can embed the standard Edit layout for that object.

 

I know we can use apex detail to display the Detail page - but of course if they click edit it takes them to the standard page layout. I've thought I could use an Iframe to display the edit page, but then I get all the sidebar and headers (ick).

 

I'm hoping this is possible so I don't have to re-create the standard edit layout verbatim just to be able to add some VF functionalty to the Edit page... or have to go back and update the page each time we add a field or update the page layout for all our profile groups.

Hi,

 

Following query line is generating

 

 

for (Lead l : [select Id, Email, HasOptedOutOfEmail, Spot_Profile__c, SPOT_Communication_Types__c, SPOT_Alternative_Investments__c,SPOT_Banks__c,SPOT_Benefit_Administration__c, SPOT_Brokerage_and_Clearance_Solutions__c,SPOT_Capital_Markets__c,SPOT_Consulting_Services__c, SPOT_Corporations__c,SPOT_Energy__c,SPOT_Enterprise_Solutions__c,SPOT_Institutional_Asset_Management__c, SPOT_Insurance__c,SPOT_Trading__c,SPOT_Wealth_Management__c,SPOT_Workflow_and_Business_Processing__c, SPOT_Global_Trading__c from Lead where isConverted != True and isDeleted != True and Email != null and Email in :profilesMap.keySet() limit :recordLimit for update]) { }

 

 following error.

 

 

System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)

 

The same code is working fine for the same user in testMethod but shows above error during manual update through browser. Also code is working fine for Administratror profile. Please help!

 

 

Hello,

 

I'm having an issue with sending an email.  I'm using the following code and the email is indeed getting sent if I don't include the WhatIds but it is not getting the merge fields populated.  If I include the WhatIds then I get an error message - "{faultcode:'soapenv:Client', faultstring:'Element {urn:partner.soap.sforce.com}WhatIds invalid at this location', }:result ="

I'm looking to send an internal email based on data in a Contract.  I have created an email template using the merge fields from the contract object.  I did read that the WhatIds only work on emails being sent to Contacts but all of our internal people are Contacts also so this doesn't pose a problem.

 

Any help would be greatly appreciated.

 

 

<html>
   <head>
   <script src="/soap/ajax/10.0/connection.js" type="text/javascript"></script>
   <script>
      alert("Starting script");
      var contactId = "{!Contact.Id}";
      var contractId = "{!Contract.Id}";
      alert("ContactId: " + contactId);
      alert("ContractId: " + contractId);
      function sendEmail() {
            alert("Starting sendEmail function");
            var result = "";
            try {
                     alert("Starting Try");  

                        var mass = new sforce.MassEmailMessage();
           
                        mass.replyTo = "rleblanc@syberworks.com";
                        alert("mass.replyTo: " + mass.replyTo);
                        mass.subject = "Mass Email from SF!";
                        alert("mass.subject: " + mass.subject);
                        var a = new Array(1);
                        a[0] = contactId;
                        alert("Contact ID - a[0]: " + a[0]);
                        mass.targetObjectIds = "0035000000ZxRr7";
                        alert("Mass targetObjectIds: " + mass.targetObjectIds);
                         mass.saveAsActivity = false;
                        mass.WhatIds = contractId;
                        alert("mass.WhatIds: " + mass.WhatIds);
                         mass.templateId = "00X50000000xsVKEAY";
                         alert("Mass.templateId: " + mass.templateId);
                        var sendMailRes = sforce.connection.sendEmail([mass]);
                     output.innerHTML = "Email sent! " + "result: " + result;
            } catch(error) {
                        output.innerHTML =  error + ":result = " + result;
            }
      }
   </script>
   <body onload="sendEmail()">
      <div id="output"></div>
   </body>
</html>

 

I got this code from a previous post and modified it some but if I can get it to work will likely continue to modify it.

 

Thanks!

Renee

Hello All,

 

I'm working on a solution in a trigger where I need to access the entire hierarchy of parent accounts for a given account.  At the moment, I'm recursively querying the account table for each account's Parent based on ParentId.  

 

This solution is fragile because if there were enough parent account to child account layers, then the trigger would hit the query limit.

 

Is there a way to access data about accounts at each level in a hierarchy without recursive querying?  It would be splendid if I could run a single query and get back a Map of Accounts or something along those lines.

  


private static string getTopParentAccountName(Account thisAccount) {
if (thisAccount.ParentId != null) {
// Get the parent account for this account and pass it to this function for recursion
Account parentAccount = [Select a.ParentId, a.Name, a.Id From Account a where a.Id = :thisAccount.ParentId];
return getTopParentAccount(parentAccount);
}
else { // There's no parent account
return thisAccount.Name;
}
}

 

The code above is representative of the logic I'm employing.  (This isn't the actual code I'm using, it's something I worked up to illustrate my point, so please ignore any minor errors in the code.) 

 

I checked the Apex Relationship Queries Documentation and found the following comments that seem relevant:
  • In each specified relationship, no more than five levels can be specified in a child-to-parent relationship. For example, Contact.Account.Owner.FirstName (three levels).
  • In each specified relationship, only one level of parent-to-child relationship can be specified in a query. For example, if the FROM clause specified Account, the SELECT clause could only specify the Contact or other objects at that level. It could not specify a child object of Contact. 
 
Any thoughts on how to handle this situation and get around the governor limitations?     
 
All input is appreciated!
 
Cheers,
-Philip

Suppose I embed a Visual Force page in a standard layout and write a controller extention based on the controller on the same object as what the page layout is based.  For example, embed a Visual Force page in the Display page for Opportunity and write a class that extends the Opportunity controller. I'm was hoping to use standard control for the rest of the layout and extend the standard control for a few functions on my VF page but I still want to work in the context of the object on the page layout. I want to be able to pass data back and forth.

 

If I extend the Opportunity controller, do I get a new instance of the Opportunity controller that isn't the one control the regular page layout?

 

Do I get a different instance of the controller? (if that even makes sense, does a controller also drive standard layouts)

 

Is there anyway in my controller extention to refer back to the page layout?  What I really will want to do is rerender part, or maybe all, of the page.

 

Is there an easy way to only display the Time of a DateTime object in VisualForce?

 

Also is there an easy way to display the Day-of-the-week like 'Friday' in VisualForce?

 

Currently, I'm using a switch statement taken from the pdf on Formulas, but am wondering if there is a better method:

{!CASE(MOD( TODAY() - DATE(1900, 1, 7), 7),0, "Sunday",1, "Monday",2, "Tuesday",3, "Wednesday",4, "Thursday",5, "Friday",6, "Saturday", "Error")}

 

Thanks

Parker

 

To All,

Well I've looked at MANY of the already existing messages about the "invalid_session_id" error arising during attempts to use an S-Control, but don't THINK that any have really FULLY addressed my situation.

As an example, I've created a very simple HTML S-Control definition that recreates the "invalid_session_id" error:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
   <head>
      <title>Create Household S-Control</title>
      <script language="javascript"
              src="/soap/ajax/13.0/connection.js"
              type="text/javascript"></script>
      <script language="javascript"
              type="text/javascript">
<!--
function initPage() {
   //Tests S-control function by attempting to create new account rec

   alert("running initPage function");

   //Calculate name value
   var nameval = "{!Contact.FirstName} {!Contact.LastName}"
                 + " Test Account";
   alert("calculated name: " + nameval);

   var obj = new sforce.SObject("Account");
   alert("past creation of javascript SObject");
   alert("created SObject of type: " + obj.type);
   obj.Name = nameval;
   //alert("finished assigning values to javascript Sbject");

   //create db rec using SObject
   try {
      var saveResult = sforce.connection.create([obj]);
      alert("successfully created db record");
   }
   catch(error) {
      alert("Error creating db rec: (" + error.faultcode + ") "
            + error.faultstring);
   }

}
//-->
      </script>
   </head>
   <body onload="initPage()">
      <div id="js_output">
      </div>
   </body>
</html>

I've defined a detail button on the main "Contacts" layout to trigger this S-Control.  I'm running it with a profile of "system administrator", and with the "API Access" setting in place.  I've also double-checked settings of the sharing rules in effect for this instance of SalesForce to ensure both read and write privileges are avalable.  I'm using a SalesForce instance established using the non-profit template from just about 5 months ago. 

When the S-Control is executed, all goes well until the attempted "sforce.connection.create".  At this point, the "catch" block is triggered and the alert message displaying the error message is displayed.

I'll anxiously away the valuable advice/thoughts of this community...   

Thanks MUCH.

Larry
I want to add new fields(columns) to this.  i can do that, but I get crzy JS errors when i do.

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

Example:

columns = [ // 'AccountId', 'Name','Sites','StageName','CloseDate', 'Amount', 'Id'
{ name:'Account',sfname:'AccountId', comparator: nameCompare ,
width: 128, readonly:true, formatter: turbo.grid.format.link },
{ name:'Name', comparator: nameCompare ,
width: 188, readonly:true , formatter: turbo.grid.format.link } ,
{ name:'Sites', sfname:'Sites', comparator: nameCompare ,
width: 188, readonly:true , formatter: turbo.grid.format.link } ,

[ turbo.grid.columns.sfenumerated, { name:'Stage', sfname:'stagename', comparator: stageCompare, width: 125,
options: getOptionsArray(bean,'stagename'), values: getOptionsArray(bean,'stagename') } ],

{ name:'Close Date', sfname:'CloseDate', comparator: dateCompare ,
width: 75, align: 'left', formatter: turbo.grid.format.dateonly, editor: turbo.grid.edit.dateonly },
{ name:'Amount', sfname:'Amount' ,
width: 86, align: 'right', digits: 4, formatter: turbo.grid.format.sfmoney, editor: turbo.grid.edit.decimal}
,{ name:'Id', formatter:null }
];

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

I added the custom field 'Sites' to this.  But i get this error message each time:

"Exception thrown, but not caught"


How can  I upload my own .js file on salesforce.com and how to use it in Custom s-control.
I want to upload that .js file for displaying data in the grid from database.

Using PHP to add Attachments

Does anyone have a complete piece of PHP code to add attachments?

(PHP5/API7).

I’m getting “INVALID_TYPE: sObject type 'sObject' is not supported.”

 

Thx – joshQ

  • June 06, 2006
  • Like
  • 0