• jshimkoski
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 10
    Replies

I have a javascript button called "sort products" related to an opportunity based on a custom field. We have related list hoverlinks enacted. If I click "sort products" at the top of the page in the related list, the page is refreshed within the  hover window. Conversely if I scroll to the bottom of the page to where products related list and click "sort products" button, nothing happens.

 

Why wiould the button work as intended the if it is clicked in the related hoverlist, but not at the bottom of the page. Why this problem? How can I solve it?

 

Thank you

  • September 22, 2011
  • Like
  • 0

I've lost hours trying to work around what must be bugs with the force IDE and how it calculates test coverage. Before I keep trying to hack around what seems like a very fragile system, I thought I'd get a reality check.

 

I have examples where test code in a function results in coverage % X, but if the code is moved from the function directly into the test method, the coverage changes to Y%. And there are other cases where switching calls A() and B() to B() then A() changes the test coverage values (in these cases, A() and B() simply exercise properties of separate classes).

 

I read on other posts that the web-based test-coverage tools are more helpful that the IDE. The example in the post I just read was that the web-based tool will show code hit in the test path with blue and code not hit in red. What follows is one weird example:

WebService static Integer Save( String accountName, String address1, String city, String state, String zip, String
emailAddr, String bizPhone, String cellPhone, String sfAccountId, Boolean setToFalseForTesting ) {

gdirectws.gDirectWebServiceSoap gs = new gdirectws.gDirectWebServiceSoap(); 

if( setToFalseForTesting == true ) {

acctId = gs.Save( accountName, address1, city, state, zip, emailAddr, bizPhone, cellPhone, sfAccountId );

}

return acctId;

}

 

In the code above, the whole method shows as blue (i.e. covered in the test) EXCEPT for the return. I assumed that could only be the case if there was an exception in the gs.Save call, but no exceptions are reported during the test.

 

Is the test coverage calculator unusually buggy? Is this whack-a-mole nonsense just something that salesforce development entails? Or is it really just me?

  • September 21, 2011
  • Like
  • 0

I am trying to alert a reminder if file is not selected to upload. I know i am doing something wrong in the function displaymessage(). Can someone point me to a correct way of doing this. Thanks!

 

 

<apex:page id="thePage" standardController="Account" extensions="attachmentsample">
<script type="text/javascript">
function displaymessage(){
var fileInput = document.getElementsByNameId("{!$Component.thePage.theForm.pageBlock.pageBlockSection.fileUpload}");
if(fileInput=="" ||fileInput==null){
alert("You must attach documents !");
}
else {
alert("You have successfully attached documents");
}

}
</script>

<apex:form id="theForm">
<apex:sectionHeader title="Upload a Attachment into Salesforce"/>
<apex:pageblock id="pageBlock" >
<apex:pageblocksection id="pageBlockSection" columns="1">
<apex:inputfile id="fileUpload" value="{!myfile.body}" filename="{!myfile.Name}" />
<apex:commandbutton value="Click Here to Attach File" action="{!Savedoc}" onclick="displaymessage()" immediate="true"/>
</apex:pageblocksection>
</apex:pageblock>
</apex:form>

</apex:page>

 

Currently, when a button is clicked to upload file , the object record is created first - then through actionFunction oncomplete, the document is submitted to amazon S3. I need this to be reversed... submit completion first - then create the file. I've tried to play with jQuery because research indicated it might be applicable to this problem. But...after 5 hours of being unsuccessful (i'm completely new to javascript and jQuery, and was hoping for some guidance here) - i'm looking for some advice.

 

This is the relevant code, untouched (working as is). I can post my jQuery edits if anyone requests, but i'm not sure if it's even the viable option and i'm sure something is wrong there as well.

 

Is there a javascript function (i've googled, and no examples ive found help) that invokes a method in salesforce, AFTER the document submission? not onsubmit, must be after a successful "upload"

 

   <apex:pageMessages id="pageErrors"></apex:pageMessages>
   
    <form name="s3Form" action="https://s3.amazonaws.com/mycompanybucket" method="post" enctype="multipart/form-data">   
        
        <input type="hidden" name="key"/> 
        <input type="hidden" name="AWSAccessKeyId" value="{!key}"/> 
        <input type="hidden" name="policy" value="{!policy}"/>
        <input type="hidden" name="signature" value="{!signedPolicy}"/> 
        <input type="hidden" name="acl" value="private"/> 
        <input type="hidden" name="x-amz-meta-FileId" value="{!File__c.id}"/>
        <input type="hidden" name="x-amz-meta-OrderId" value="{!OrderId}"/>
        <input type="hidden" name="x-amz-meta-CustomerId" value="{!CustomerId}"/>     
        <input type="hidden" name="success_action_redirect" value="{!serverUrl}{!OrderId}"/>           
        
        <apex:pageBlock title="New File Upload" mode="maindetail" tabStyle="File__c">
        
            <apex:pageBlockSection title="File Information" columns="2" collapsible="false" showHeader="false"> 
                                                                       
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Select File" for="selectFile"/>            
                    <input id="selectedFile" type="file" size="25" name="file" onChange="setFileName(this.value)"/>                
                </apex:pageBlockSectionItem>    

                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Select File" for="fType"/>                            
                    <select id="fType" onChange="setFileType(this.value)">
                        <option value="--None--">--None--</option>
                        <option value="Valuation">Valuation</option>
                        <option value="Data Sheet">Data Sheet</option>
                        <option value="Invoice">Invoice</option>
                        <option value="Review">Review</option>
                        <option value="Other">Other</option>
                    </select>                          
                </apex:pageBlockSectionItem>                                        
                           
            </apex:pageBlockSection>

            <apex:pageBlockButtons location="bottom">
                <input class="btn" type="button" value="Upload File" onClick="checkFile();return false;"/>                
                <input class="btn" type="button" value="Cancel" onClick="cancelFile();return false;"/>
                <input class="btn" type="button" value="Complete Order" onClick="completeFile();return false;"/>
            </apex:pageBlockButtons>          

        </apex:pageBlock>
       
    </form> 
    
     <apex:form id="sfForm">
     
        <apex:inputHidden id="hiddenServerURL"  value="{!serverURL}"/>
        <apex:inputHidden id="fileName" value="{!fileName}"/>
        <apex:inputHidden id="contentType" value="{!contentType}"/>
        <apex:inputHidden id="fileType" value="{!fileType}"/>
        <apex:actionFunction name="insertFile" action="{!insertFile}" oncomplete="submitFile();return false;"/>
        <apex:actionFunction name="completeOrder" action="{!completeOrder}"/>

        
        <script type="text/javascript">
        var sendFile = false;
        document.getElementById('{!$Component.hiddenServerURL}').value = '{!$Api.Enterprise_Server_URL_140}';       
        function setFileName(file) {
            var f = file.replace(/\\/g, "");
            f = f.replace(/C\:fakepath/g, ""); <!--Required for IE8-->
            document.s3Form.key.value = "{!CustomerName}/{!OrderName}/" + f;
            document.getElementById('{!$Component.fileName}').value = f;
            suffix = f.lastIndexOf(".") + 1;
            contentType = f.slice(suffix);
            document.getElementById('{!$Component.contentType}').value = contentType;
        }
        function setFileType(type) {
            document.getElementById('{!$Component.fileType}').value = type;
        }
        function checkFile() {
            if (document.s3Form.file.value=="") {
                alert("Please, select a file.");
                return false;
            } 
            else if (document.s3Form.fType.value=="--None--") {
                alert("Please, select a file type.");
                return false;
            }
            else {     
            	alert("Uploading...Please click OK and wait for page to refresh.");        
              	insertFile();
               	sendFile = true;
            }
        }
        function submitFile() {
            if(sendFile = false) {
            return false;
            }
            else {
            document.s3Form.submit();
            }
        } 


insertFile() Method on extension:

//SF File insert on an object (passed from page)
    public PageReference insertFile() {
        this.file.Name = fileName;
        this.file.Type__c = fileType;
        this.file.Content__c = contentType;
        insert this.file;
        return null;
    }

 

  • August 15, 2011
  • Like
  • 0

Though lots of many nights and trial and error with various syntax, I've munged together a set of scripts that help me integrate with Salesforce via Applescript. Many thanks to Simon and all the folks that have put these mac tools together for us to use and and abuse.

 

I thought I'd had everything licked, but then came upon a discovery - the script that I'd used to take data from Address Book and create accounts and contacts was inserting a "0" where the last name should go in the Contact record.

 

Here's the code:

 

tell application "SalesforceScripting"
	activate
	set session to login with saved credentials
	
	set ContactFirstName to "Joe"
	set ContactLastName to "Blow"
	
	set cont to make SObject
	set type of cont to "Contact"
	cont setField named "FirstName" to ContactFirstName
	cont setField named "LastName" to ContactLastName
	--	cont setField named "AccountId" to NewAccountID
	--	cont setField named "PDS__Primary_Contact__c" with to
	--	cont setField named "Email" to EmailAddy
	
	set res2 to session create sobjects cont
	set NewContactID to Id of first item of res2
	
	open location "https://na9.salesforce.com/" & NewContactID
	
end tell

 

Here's the results of that script from the AS Log:

 

tell application "SalesforceScripting"
	activate
	login with saved credentials
		--> UserSession id "us_31068"
	make new SObject
		--> SObject id "row_31070"
	set type of SObject id "row_31070" to "Contact"
	setField SObject id "row_31070" named "FirstName" to "Joe"
	setField SObject id "row_31070" named "LastName" to "Blow"
	create UserSession id "us_31068" sobjects SObject id "row_31070"
		--> {SaveResult id "sr_31071" of UserSession id "us_31068"}
	get Id of SaveResult id "sr_31071" of UserSession id "us_31068"
		--> "003E0000005uds7IAA"
	open location "https://na9.salesforce.com/003E0000005uds7IAA"
end tell

 

If I hard code the ContactLastName, like:

 

cont setField named "LastName" to "Blow"

 the log returns an identical result, and the record is written properly to Salesforce.com. But if "LastName" is written with a variable, I get a big fat ZERO.

 

Any clues?

 

 

 

  • July 11, 2011
  • Like
  • 0

 

   In my application I need to fade the page on load(when it is loading).

 

      I have used this code but its not working...

 

<script>
$(document).ready(function(){

 

$(document).ready(function () {$('.nav').fadeIn(3000);});
});</script>

    and then div tag <div class="nav" style="display:none"> 

before closing page tag.

 

Can any one help me.

  • January 24, 2011
  • Like
  • 0