• MattL
  • NEWBIE
  • 0 Points
  • Member since 2007

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 26
    Replies
I have a VisualForce page that contains an attachment upload (basically, overriding the attachments related list). However, upon upload, the page refreshes entirely. This normally wouldn't be a problem, except that it doesn't re-render the detail, and that section is rather important to the overall flow of the page. I was under the impression that rerender would rebuild the list with a partial page refresh... however, I attempted to use this functionality when adding documents from Salesforce, and while the document is added, you don't see it in the list until you do a manual refresh. What am I doing wrong?

VisualForce Page
Code:
<apex:page standardController="Agreement__c" extensions="documentExt,ec_mod_cntrl" >
    <apex:detail relatedList="false" />
    <apex:pageBlock >
        <apex:pageBlockSection title="Attachments">
            <apex:pageBlockTable border="0" cellpadding="6" value="{!attachments}" var="a" id="rows">
                <apex:column headerValue="Title"><apex:outputField value="{!a.Name}" /></apex:column>
                <apex:column headerValue="Last Modified"><apex:outputField value="{!a.LastModifiedDate}" /></apex:column>
                <apex:column headerValue="Created By"><apex:outputField value="{!a.LastModifiedById}" /></apex:column>
            </apex:pageBlockTable>
            <br />
            <apex:tabPanel switchType="client" selectedTab="File">
                <apex:tab label="From File" name="File" id="file">
                    <apex:form id="newfile">
                        <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" />
                        <apex:commandButton value="submit" action="{!save}" />
                    </apex:form>
                </apex:tab>
                <apex:tab label="From Salesforce" name="SFDC" id="sfdc">
                    <apex:form id="newsf">
                        <apex:selectList size="1" value="{!selectedProd}">
                            <apex:selectoptions value="{!items}" />
                        </apex:selectList>
                        <apex:commandButton value="Find Documents" rerender="doc" />
                        <br />
                        <apex:outputPanel id="doc">
                            <apex:actionStatus startText="Polling Folder {!selectedProd}">
                                <apex:facet name="stop">
                                    <apex:selectList size="1" value="{!selectedDoc}">
                                        <apex:selectoptions value="{!items2}" />
                                    </apex:selectList>
                                </apex:facet>
                            </apex:actionStatus>
                        </apex:outputPanel>
                        <apex:commandButton value="Add Document" action="{!svdoc}" rerender="rows" />
                    </apex:form>
                </apex:tab>
                <apex:tab label="From External Respository" name="ECRepo" id="ecrepo">
                    <apex:pageMessage detail="A link to the external Repository goes here." severity="warning" />
                </apex:tab>
            </apex:tabPanel>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

 Controller Extension documentExt
Code:
public class documentExt {
 private final String ecagree;
 public Attachment attachment {get;set;}
 
 public PageReference save() {
  attachment.parentid = ecagree;
  insert attachment;
  return null;
 }
 
 public documentExt(ApexPages.StandardController controller) {
  attachment = new Attachment();
  this.ecagree = ApexPages.currentPage().getParameters().get('id');
  this.stdController = stdController;
 }
 
 ApexPages.StandardController stdController;
}

Controller Extension ec_mod_cntrl
Code:
public class ec_mod_cntrl {
 public String selectedProd {get;set;}
 public String selectedDoc {get;set;}
 public List<Attachment> attachList;
 public List<SelectOption> docs = new List<SelectOption>();
 public PageReference reset() {
     attachList = [select id, Name, LastModifiedDate, LastModifiedById from Attachment where ParentId = :ApexPages.currentPage().getParameters().get('id')];
        return null;
    }
 public List<Attachment> getAttachments() {
     if(attachList == null) reset(); 
        return attachList;
    }
    public void setAttachments(List<Attachment> Attach) {
        attachList = Attach;
    }
 public ec_mod_cntrl(ApexPages.StandardController controller) {
  
 }
 public List<SelectOption> getItems() {
     List<SelectOption> dfolder = new List<SelectOption>();
        for(Folder fd : [Select Id, Name from Folder where Type='Document']) dfolder.add(new SelectOption(fd.Id, fd.Name));
        return dfolder;
    }
    public List<SelectOption> getItems2() {
     queryDocs();
     return docs;
    }
    public PageReference queryDocs() {
     docs.clear();
     for(Document d : [Select Id, Name from Document where FolderId=:selectedProd]) docs.add(new SelectOption(d.Id, d.Name));
     return null;
    }
    public void svdoc() {
     Document d1 = [Select Id, Body, Description, Name, Type from Document where Id=:selectedDoc];
     if(d1!=null)
     {
      Attachment a1 = new Attachment();
      a1.Body=d1.Body;
      a1.ContentType=d1.Type;
      a1.Name=d1.Name;
      a1.ParentId=ApexPages.currentPage().getParameters().get('id');
      insert a1;
     }
    }
}

 

 


  • January 05, 2009
  • Like
  • 0
I've run into a bit of a problem with the governor limits on the SOQL query rows returned. Here's my situation.

The code needs to query the organization for all accounts whose type is "Customer". Then, it needs to find the largest existing Account Number, and increment it by 1, storing that new value into an account that's type is updated to Customer, or a new Customer account.

Trigger:
Code:
trigger Account_Number_Inc on Account (after insert, after update) {
 if(Trigger.new[0].Account_Number__c == null && Trigger.new[0].Type == 'Customer')
 {
  list<Account> AcctNums = [SELECT Account_Number__c From Account where Account_Number__c != null and Type = 'Customer' ORDER BY Account_Number__c DESC NULLS LAST];
  System.assert(AcctNums != null);
  Long curhigh = long.valueOf(AcctNums[0].Account_Number__c);
  curhigh++;
  Account acc = new Account(Id=Trigger.new[0].Id);
  acc.Account_Number__c=String.valueOf(curhigh);
  update(acc);
 }
}

 
Test Code:

Code:
public class AccountNumberTriggerTest {
 static testMethod void testAccountTrigger() { 
    Integer highestnum = integer.valueOf([Select Account_Number__c from Account where Account_Number__c != null and Type = 'Customer' ORDER BY Account_Number__c DESC NULLS LAST][0].Account_Number__c);
    Account b = new Account(name='blah2', type='Customer');
    insert b;
    Integer acctnum = integer.valueOf([Select Account_Number__c from Account where id =:b.id][0].Account_Number__c);
    System.assertEquals(highestnum+1, acctnum);
    }
}

 Now, my problem is that when I attempt to deploy it from the Sandbox, I get an error "Too many query rows". Upon trying to LIMIT my query, I've discovered that the LIMIT occurs before the ORDER BY, so if I limit the query, I don't get all the records and may not actually get the highest account number (depending on how Salesforce returns the records). But if I don't limit the query, I get errors of Too many query rows.

Any advice?

  • December 08, 2008
  • Like
  • 0
I'm trying to pull in the ID of a row... unfortunately, despite setting an <apex:param> for it, when I query the variable I assigned it to I always get "null" back.

Visualforce:
Code:
<apex:page controller="cntrl_ext_save" sidebar="false" >
<apex:sectionHeader title="Professional Development Products" />

 <apex:form >
 <apex:selectList size="1" required="true" value="{!selectedProd}">
<apex:selectoptions value="{!items}"/>
</apex:selectList>
<apex:commandButton action="{!add}" value="New Dev. Product" />
 <apex:pageBlock title="Items">
   <apex:pageBlockButtons >
     <apex:commandButton value="Save"  action="{!save}"  rerender="rows" status="outStatus"/>
     <apex:commandButton value="Reset" action="{!reset}" rerender="rows" status="outStatus" 
      immediate="true" />
     <apex:actionStatus startText="(.................Processing.................)" stopText="" id="outStatus" onstop="Reset"/>
   </apex:pageBlockButtons>
   <apex:pageBlockTable border="1" cellpadding="6" value="{!components}" var="a" id="rows" >
      <apex:column headerValue="Delete"><apex:commandButton value='Del' action='{!remove}' onclick="return confirm('Are you sure—');"><apex:param value="{a.Id}" assignTo="{!dParam}" /></apex:commandButton></apex:column>
      <apex:column headerValue="Product">"{!a.PricebookEntry.Name}"</apex:column>
      <apex:column headerValue="Quantity"><apex:inputField value="{!a.Quantity}" /></apex:column>     
      <apex:column headerValue="Sales Price"><apex:inputField value="{!a.UnitPrice}" /></apex:column>
      <apex:column headerValue="List Price">"{!a.ListPrice}"</apex:column>
      <apex:column headerValue="Total Price">"{!a.TotalPrice}"</apex:column>
   </apex:pageBlockTable>
  </apex:pageblock>
 </apex:form>
</apex:page>

 Controller:
Code:
public class cntrl_ext_save {
        public String selectedProd {get;set;}
        public String dParam;
        public String getdParam() {
            return dParam;
        }
        public void setdParam(String s) {
            dParam = s;
        }
        public List<OpportunityLineItem> componentList;  // list of components to appear in the multi-line.
        public PageReference reset() {
            componentList = [select id, quantity, totalprice, unitprice, listprice, PricebookEntry.name, pricebookentry.product2.Family from OpportunityLineItem where OpportunityId = :ApexPages.currentPage().getParameters().get('id') and pricebookentry.product2.Family = '03 Professional Services'];
            return null;
        }  
        public List<OpportunityLineItem> getComponents() {
            if(componentList == null) reset(); 
            return componentList;
        }
        public void setComponents(List<OpportunityLineItem> Components) {
            componentList = Components;
        }
        public PageReference save() {
            upsert componentList;
            return null;    
        }
        public PageReference add() {
            Opportunity pb = [select Pricebook2Id from Opportunity where Id = :ApexPages.currentPage().getParameters().get('id')];
            PricebookEntry prod = [select UnitPrice, Name, Id from PricebookEntry where Product2Id = :selectedProd and Pricebook2Id = :pb.Pricebook2Id];
            componentList.add(New OpportunityLineItem(OpportunityId = ApexPages.currentPage().getParameters().get('id'), UnitPrice=prod.UnitPrice, PricebookEntryId=prod.Id, Quantity=1));
            save();
            reset();
            return null;                
        }
        public PageReference remove() {
            system.debug('test '+dParam);
            OpportunityLineItem oli = Database.query('select Id from OpportunityLineItem where id='+dParam);
            delete oli;
            reset();
            return null;
        }
        public List<SelectOption> getItems() {
            List<SelectOption> op = new List<SelectOption>();
            for(Product2 prod : [select id, name from Product2 where family='03 Professional Services']) op.add(new SelectOption(prod.Id, prod.Name));
            return op;
        }
}

 


  • November 17, 2008
  • Like
  • 0
I have a relatively simple S-control that is manifesting some bizarre problems I can't easily reproduce. The only thing I get is a message from Salesforce:
 Invalid Page Redirection
    The page you attempted to access has been blocked due to an outside website or an improperly coded link or button. Please contact your Salesforce Administrator for assistance.

  Click here to return to the previous page.

The only thing I can think of is that there is something wrong with the JS I pulled off the web to process out the retUrl parameter from the URL my S-control is fed.

Code:
//function to decode given URL
function decodeUrl(url)
{
   /* When decoding the URL we will do the following:

           1.) Replace + with ' '
           2.) Replace %xx with equivalent character
           3.) Put [—] in output if %xx is invalid.
   */

   //string holding our hexadecimal values
   var hexValues = "0123456789ABCDEFabcdef"; 
   //value to hold the initial URL value
   //variable to hold the final URL value
   var returnURL = "";
   //counter variable
   var count = 0;
   plainUrl = url;
   //start looping through each character in the URL
   while (count < plainUrl.length) 
   {
      //get each character on each iteration
      var charValue = plainUrl.charAt(count);
      //determine the value of the character
      switch(charValue)
      {
         //if the character is a plus sign (+) then append a space
         case "+":
             returnURL += " ";
             //increment our counter
             count++;
             break;
         //if the character is a percent sign we have a little more work to do
         case "%":
             //first determine if we have a valid character (one that is in our list)
             if (count < (plainUrl.length - 2) && hexValues.indexOf(plainUrl.charAt(count+1)) != -1 && hexValues.indexOf(plainUrl.charAt(count + 2)) != -1 ) 
             {
                 //its a valid character so unescape it
          returnURL += unescape(plainUrl.substr(count,3));
                 //increment the counter by 3
          count += 3;
      } 
             else 
             {
          //we have a bad character so append [–]
          returnURL += "%[˜]";
          count++;
             }
             break;
         default:
             //default value is to append the current character
             //to the return value
             returnURL += charValue;
             count++;
             break;
      }
    }
   //return the final decoded URL
   return returnURL;
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\™&]"+name+"=([%^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( decodeUrl(window.parent.location.href) );
  var result = decodeUrl(window.parent.location.href).substr(results.index+8,24);
  if( results == null )
    return "";
  else
    return result;
}


 And the actual call is: window.opener.location.href = "https://na1.salesforce.com/"+gup("retURL");

  • October 22, 2008
  • Like
  • 0
Code:
<—xml version="1.0" encoding="utf-8"–>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
 xmlns:salesforce="com.salesforce.*"
 applicationComplete="login();">

<mx:DateFormatter id="dateform" formatString="MM"/>
<mx:NumberFormatter id="numform" precision="0"/>

<mx:Script>
 <![CDATA[
  import flash.external.ExternalInterface;
  import com.salesforce.results.QueryResult;
  import mx.collections.ArrayCollection;
  import com.salesforce.AsyncResponder;
  import com.salesforce.objects.LoginRequest;
  import mx.controls.dataGridClasses.DataGridColumn;
  private function login():void {
   apex.login( new LoginRequest({
    server_url : this.parameters.server_url,
    session_id : this.parameters.session_id,
    callback : new AsyncResponder(render)
    })
    );
  }
  private function render(result:Object):void {
   var currId:String = ExternalInterface.call("getID");
   apex.query("Select Amount, CloseDate, OwnerId from Opportunity where AccountId='{!Account.Id}' and Probability=100",
     new AsyncResponder(
     function (qr:QueryResult):void
     {
      var month:int = 0;
      var x:int = 0;
      var amt:Array = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0);
      var name:Array = new Array(" "," "," "," "," "," "," "," "," "," "," "," "," ");
      var months:Array = new Array("0","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
      var ar:ArrayCollection = new ArrayCollection();
      values.dataProvider = ar;
      for(var j:int=0;j<qr.records.length;j++) {
       month=numform.format(dateform.format(qr.records[j].CloseDate));
       amt[month]+=qr.records[j].Amount;
       apex.query("Select Name from User where Id='"+qr.records[j].OwnerId+"'",
       new AsyncResponder(
       function (qr2:QueryResult):void
       {
        name[x]=qr2.records[0].Name;
        x++;
       },
       function (fault:Object):void {}
       ));
      }
      ar=createArray(months, amt, name, ar);
     },
     function (fault:Object):void {}
  ));
 }
 private function createArray(months:Array, amt:Array, name:Array, ar:ArrayCollection):ArrayCollection {
  for(var i:int=1;i<13;i++)
  {
   ar.addItem( {Month:months[i], Amount:amt[i], Name:name[i]});
  }
  return(ar);
 }
 ]]>
</mx:Script>

<salesforce:Connection id="apex" />
 <mx:ColumnChart x="118" y="46" id="values">
  <mx:series>
   <mx:ColumnSeries displayName="Opp Amounts" yField="Amount"/>
   <mx:ColumnSeries displayName="Owner" yField="Owner"/>
  </mx:series>
 </mx:ColumnChart>
 <mx:Legend dataProvider="{values}"/>
 
</mx:Application>

I'm learning how to code simple Flex graphs, and I'm trying to push all my information into the ArrayCollection ar. The problem is that, regardless of what method I try, I'll put a breakpoint on the line return(ar) and a breakpoint on the line x++ under my second AsynchResponder. Inevitably, the return(ar) function will activate PRIOR to the breakpoint for x++, which means none of my names are initialized before the ArrayCollection is created. How does one 'wait' for all the data to be returned?
 


Message Edited by MattL on 01-28-2008 11:38 AM
  • January 25, 2008
  • Like
  • 0
I'm developing an S-control where one of the fields is a picklist value. Ideally, I wouldn't need to hard-code the values in. Going through the Sforce Explorer, I can navigate under the field name down to "type - picklist" and then "Picklist Values", but I can't figure out how to structure my SOQL query to gain access to this data. Can anyone advise if it's even possible, or will I need to resort to hard-coding it in?  
  • January 24, 2008
  • Like
  • 0
I'm working on an S-control that pulls the date of the most recent Opportunity belonging to an Account and displays that. My problem is that when I attempt to format the field to align with the rest of SFDC fields, it works for the resolution I'm operating on, but as soon as that resolution changes it falls out of sync. I've tried using %, em, and px, and nothing seems to understand the resolution change. How does Salesforce do it?

Code below:

Code:
<!DOCTYPE HTML PUBLIC
    "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<link href="/dCSS/Theme2/default/common.css" type="text/css"
media="handheld,print,projection,screen,tty,tv"  rel="stylesheet" >
<link href="/dCSS/Theme2/default/custom.css" type="text/css"
media="handheld,print,projection,screen,tty,tv"  rel="stylesheet" >

<script type="text/javascript" src="/js/functions.js"></script>
<script type="text/javascript" src="/js/setup.js"></script>

<script src="/soap/ajax/9.0/connection.js"></script>

<html>
<head>
<script type="text/javascript">
function init()
{
sforce.connection.sessionId = "{!$Api.Session_ID}";
var acctid="{!Account.Id}";
var LatestOpportunity=sforce.connection.query("Select CloseDate from Opportunity Where AccountId='" + acctid + "'");
var LOrecs = LatestOpportunity.getArray('records');
var closeDate=LOrecs[0].get("CloseDate");
if(LatestOpportunity.size > 1){

    for(x=1;x<LatestOpportunity.size;x++)
    {
      if(LatestOpportunity.records[x].get("CloseDate")>closeDate)
      {
         closeDate=LatestOpportunity.records[x].get("CloseDate");
      }
    }
}
document.getElementById("date").innerText=closeDate;
document.getElementById("date").textContent=closeDate;
}
</script>
</head>
<body class='account' onLoad='init()'>
<DIV class="bPageBlock secondaryPalette" style="border-top:0px; border-bottom:0px; margin-bottom:0px; padding-bottom:0px">
 <DIV class=pbBody style="margin-right:0px">
 <DIV class=pbSubsection>
<div class=labelCol style="text-align:left; position:relative; left:11%; top:20%">
Last Order Date&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<span id='date'><br><br><br></div></div></div></div>
</body>

 

  • January 08, 2008
  • Like
  • 0
I have a field on the Contact record that I need to determine the Support Status of, and display a red stoplight or green stoplight based on that status. Normally, I'd use a formula field, but in this case the field I'm querying off of isn't located on the Contact record, but rather on the Account parent record. I've coded some logic into an S-control, and the actual image displays properly.

The problem is that the field is ballooned to a rather unacceptable degree. Furthermore, I cannot get the field name to center properly, nor can I get it to look like the rest of the Salesforce.com fields.

Any advice would be greatly appreciated.

Code:
<script src="/soap/ajax/9.0/connection.js"></script>

<script language="javascript">
function init()
{

var resAc = sforce.connection.query("SELECT Account.Id FROM Contact WHERE Id = '{!Contact.Id}'")
if(resAc.records != null && resAc.records.Account != null)
{

var AcId = resAc.records.Account.Id



var res = sforce.connection.query("SELECT Support_Status__c FROM Account WHERE Id = '"+AcId+"'")
if(res.getArray('records')[0].get('Support_Status__c') != null)
{

if(res.getArray('records')[0].get('Support_Status__c') == 'Support Open')
document.getElementById('Green').src="https://na5.salesforce.com/servlet/servlet.FileDownload—file=01570000000hp5A"
else
document.getElementById('Red').src="https://na5.salesforce.com/servlet/servlet.FileDownload–file=01570000000hp5B"


}

}
}
</script>

<body onLoad='init()'>

Support Status: <img id='Green' src=''></img>

</body>

 

  • December 20, 2007
  • Like
  • 0
I'm trying to develop custom code for overloading the New button on a related list. This will populate not just the Contact name (as the standard functionality does), but also populate the Member Status and Group fields from the Contact, automatically.

Code:
<html>
<head>
<script src="/soap/ajax/9.0/connection.js"></script>
<script language="Javascript">
function replace()
{
parent.document.location.href="/a00/e?00N40000001RC56={!Contact.Name}&00N40000001RC69={!Contact.Member_Status__c}&00N40000001RC64={!Contact.Group__c}";
}
</script>
</head>
<body onload="replace()">
</body>
</html>


Yet every time I click on the button, the first URL it takes me to is the proper one. Then, it reloads the page, loses the values... and then reloads the page again. And continues to just sit there reloading the page. I never actually see the new object dialog show up. Can anyone assist?
 

  • August 03, 2007
  • Like
  • 0
What, generally speaking, is the problem when you have a Flex graph that loads, but times out (Firefox sits there on "Transfering data from na1.salesforce.com" forever)?

Here's my code.

Code:
apex.query("Select Id from SFDC_Resource__c",
     new AsyncResponder(
     function (qr:QueryResult):void
     {
       for(var x:int=0;x<qr.records.length;x++)
       {
        apex.query("Select Hours, Resource__c, Resource__r.Id, Projects__c, Projects__r.Id from SFDC_Assignment__c Where Resource__c='"+qr.records[x].Id+"' and Projects__c='"+currId+"'",
        new AsyncResponder(
       function (qr2:QueryResult):void
        {
         var tempHours:int=qr2.records[0].Hours;
         for(var y:int=1;y<qr2.records.length;y++)
         {
       tempHours+=qr2.records[y].Hours;
         }
         resHours.addItem({Hours:tempHours, Resource:qr.records[y].Id});
        },
        function (fault:Object):void {}
       ));
       }
     },
     function (fault:Object):void {}
        ));

 

  • July 20, 2007
  • Like
  • 0
I'm writing a Flex app to graph out resource usage by hours. It utilizes two custom Objects, Resource and Assignment.

I first query to get the resource ID, and then inside of that for each resource, I query all Assignments that the resource is associated with, with the intention of tallying them up.

Code:
<mx:Script>
 <![CDATA[
  import mx.collections.ArrayCollection;
  import com.salesforce.AsyncResponder;
  import com.salesforce.results.QueryResult;
  import com.salesforce.AsyncResponder;
  import com.salesforce.objects.LoginRequest;
  private function login():void{
   apex.login(  new LoginRequest({
         server_url : this.parameters.server_url,
         session_id : this.parameters.session_id,
         callback : new AsyncResponder(render)
         })
         );
  }
  public var resHours:ArrayCollection = new ArrayCollection();
  private function render(result:Object):void {
           apex.query("Select Id from SFDC_Resource__c",
     new AsyncResponder(
     function (qr:QueryResult):void
     {
       for(var x:int=0;x<qr.records.length;x++)
       {
        apex.query("Select Hours, Resource__c from SFDC_Assignment__c Where Resource__r.Id='"qr.record[x].Id"'",
        new AsyncResponder(
        function (qr2:QueryResult):void
        {
         var tempHours=qr2.records[0].Hours;
         for(var y:int=1;y<qr2.records.length;y++)
         {
       tempHours+=qr2.records[y].Hours;
         }
         resHours.addItem({Hours:tempHours, Resource:qr.records[y].Id});
        },
        function (fault:Object):void {}
        ));
       }
     },
     function (fault:Object):void {}
        ));
  }
 ]]>
</mx:Script>

 My problem is that, it's throwing errors that bounce all over the place, and I can't quite get a fix on the originating error.

1078: Label must be a simple identifier.    ResourceUsage.mxml    line 31   
1084: Syntax error: expecting colon before for.    ResourceUsage.mxml    line 34   
1084: Syntax error: expecting identifier before comma.    ResourceUsage.mxml    line 39   
1084: Syntax error: expecting identifier before var.    ResourceUsage.mxml    line 33  
1084: Syntax error: expecting rightbrace before leftbrace.    ResourceUsage.mxml    line 40
1084: Syntax error: expecting rightbrace before semicolon.    ResourceUsage.mxml    line 34
1084: Syntax error: expecting rightparen before qr.    ResourceUsage.mxml    line 29  

Does anyone have any suggestions/comments? I'm presently at a loss.
  • July 09, 2007
  • Like
  • 0

I remember reading about a tricky little workflow that would allow you to map a converted Lead field to more than one record, e.g., Spending Cycle is mapped to both the Account and Opportunity record.

I'm trying to figure out/remember how a workflow field update would allow you to do this. Any thoughts?

  • June 27, 2007
  • Like
  • 0
I have a VisualForce page that contains an attachment upload (basically, overriding the attachments related list). However, upon upload, the page refreshes entirely. This normally wouldn't be a problem, except that it doesn't re-render the detail, and that section is rather important to the overall flow of the page. I was under the impression that rerender would rebuild the list with a partial page refresh... however, I attempted to use this functionality when adding documents from Salesforce, and while the document is added, you don't see it in the list until you do a manual refresh. What am I doing wrong?

VisualForce Page
Code:
<apex:page standardController="Agreement__c" extensions="documentExt,ec_mod_cntrl" >
    <apex:detail relatedList="false" />
    <apex:pageBlock >
        <apex:pageBlockSection title="Attachments">
            <apex:pageBlockTable border="0" cellpadding="6" value="{!attachments}" var="a" id="rows">
                <apex:column headerValue="Title"><apex:outputField value="{!a.Name}" /></apex:column>
                <apex:column headerValue="Last Modified"><apex:outputField value="{!a.LastModifiedDate}" /></apex:column>
                <apex:column headerValue="Created By"><apex:outputField value="{!a.LastModifiedById}" /></apex:column>
            </apex:pageBlockTable>
            <br />
            <apex:tabPanel switchType="client" selectedTab="File">
                <apex:tab label="From File" name="File" id="file">
                    <apex:form id="newfile">
                        <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" />
                        <apex:commandButton value="submit" action="{!save}" />
                    </apex:form>
                </apex:tab>
                <apex:tab label="From Salesforce" name="SFDC" id="sfdc">
                    <apex:form id="newsf">
                        <apex:selectList size="1" value="{!selectedProd}">
                            <apex:selectoptions value="{!items}" />
                        </apex:selectList>
                        <apex:commandButton value="Find Documents" rerender="doc" />
                        <br />
                        <apex:outputPanel id="doc">
                            <apex:actionStatus startText="Polling Folder {!selectedProd}">
                                <apex:facet name="stop">
                                    <apex:selectList size="1" value="{!selectedDoc}">
                                        <apex:selectoptions value="{!items2}" />
                                    </apex:selectList>
                                </apex:facet>
                            </apex:actionStatus>
                        </apex:outputPanel>
                        <apex:commandButton value="Add Document" action="{!svdoc}" rerender="rows" />
                    </apex:form>
                </apex:tab>
                <apex:tab label="From External Respository" name="ECRepo" id="ecrepo">
                    <apex:pageMessage detail="A link to the external Repository goes here." severity="warning" />
                </apex:tab>
            </apex:tabPanel>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

 Controller Extension documentExt
Code:
public class documentExt {
 private final String ecagree;
 public Attachment attachment {get;set;}
 
 public PageReference save() {
  attachment.parentid = ecagree;
  insert attachment;
  return null;
 }
 
 public documentExt(ApexPages.StandardController controller) {
  attachment = new Attachment();
  this.ecagree = ApexPages.currentPage().getParameters().get('id');
  this.stdController = stdController;
 }
 
 ApexPages.StandardController stdController;
}

Controller Extension ec_mod_cntrl
Code:
public class ec_mod_cntrl {
 public String selectedProd {get;set;}
 public String selectedDoc {get;set;}
 public List<Attachment> attachList;
 public List<SelectOption> docs = new List<SelectOption>();
 public PageReference reset() {
     attachList = [select id, Name, LastModifiedDate, LastModifiedById from Attachment where ParentId = :ApexPages.currentPage().getParameters().get('id')];
        return null;
    }
 public List<Attachment> getAttachments() {
     if(attachList == null) reset(); 
        return attachList;
    }
    public void setAttachments(List<Attachment> Attach) {
        attachList = Attach;
    }
 public ec_mod_cntrl(ApexPages.StandardController controller) {
  
 }
 public List<SelectOption> getItems() {
     List<SelectOption> dfolder = new List<SelectOption>();
        for(Folder fd : [Select Id, Name from Folder where Type='Document']) dfolder.add(new SelectOption(fd.Id, fd.Name));
        return dfolder;
    }
    public List<SelectOption> getItems2() {
     queryDocs();
     return docs;
    }
    public PageReference queryDocs() {
     docs.clear();
     for(Document d : [Select Id, Name from Document where FolderId=:selectedProd]) docs.add(new SelectOption(d.Id, d.Name));
     return null;
    }
    public void svdoc() {
     Document d1 = [Select Id, Body, Description, Name, Type from Document where Id=:selectedDoc];
     if(d1!=null)
     {
      Attachment a1 = new Attachment();
      a1.Body=d1.Body;
      a1.ContentType=d1.Type;
      a1.Name=d1.Name;
      a1.ParentId=ApexPages.currentPage().getParameters().get('id');
      insert a1;
     }
    }
}

 

 


  • January 05, 2009
  • Like
  • 0
I've run into a bit of a problem with the governor limits on the SOQL query rows returned. Here's my situation.

The code needs to query the organization for all accounts whose type is "Customer". Then, it needs to find the largest existing Account Number, and increment it by 1, storing that new value into an account that's type is updated to Customer, or a new Customer account.

Trigger:
Code:
trigger Account_Number_Inc on Account (after insert, after update) {
 if(Trigger.new[0].Account_Number__c == null && Trigger.new[0].Type == 'Customer')
 {
  list<Account> AcctNums = [SELECT Account_Number__c From Account where Account_Number__c != null and Type = 'Customer' ORDER BY Account_Number__c DESC NULLS LAST];
  System.assert(AcctNums != null);
  Long curhigh = long.valueOf(AcctNums[0].Account_Number__c);
  curhigh++;
  Account acc = new Account(Id=Trigger.new[0].Id);
  acc.Account_Number__c=String.valueOf(curhigh);
  update(acc);
 }
}

 
Test Code:

Code:
public class AccountNumberTriggerTest {
 static testMethod void testAccountTrigger() { 
    Integer highestnum = integer.valueOf([Select Account_Number__c from Account where Account_Number__c != null and Type = 'Customer' ORDER BY Account_Number__c DESC NULLS LAST][0].Account_Number__c);
    Account b = new Account(name='blah2', type='Customer');
    insert b;
    Integer acctnum = integer.valueOf([Select Account_Number__c from Account where id =:b.id][0].Account_Number__c);
    System.assertEquals(highestnum+1, acctnum);
    }
}

 Now, my problem is that when I attempt to deploy it from the Sandbox, I get an error "Too many query rows". Upon trying to LIMIT my query, I've discovered that the LIMIT occurs before the ORDER BY, so if I limit the query, I don't get all the records and may not actually get the highest account number (depending on how Salesforce returns the records). But if I don't limit the query, I get errors of Too many query rows.

Any advice?

  • December 08, 2008
  • Like
  • 0
I'm trying to pull in the ID of a row... unfortunately, despite setting an <apex:param> for it, when I query the variable I assigned it to I always get "null" back.

Visualforce:
Code:
<apex:page controller="cntrl_ext_save" sidebar="false" >
<apex:sectionHeader title="Professional Development Products" />

 <apex:form >
 <apex:selectList size="1" required="true" value="{!selectedProd}">
<apex:selectoptions value="{!items}"/>
</apex:selectList>
<apex:commandButton action="{!add}" value="New Dev. Product" />
 <apex:pageBlock title="Items">
   <apex:pageBlockButtons >
     <apex:commandButton value="Save"  action="{!save}"  rerender="rows" status="outStatus"/>
     <apex:commandButton value="Reset" action="{!reset}" rerender="rows" status="outStatus" 
      immediate="true" />
     <apex:actionStatus startText="(.................Processing.................)" stopText="" id="outStatus" onstop="Reset"/>
   </apex:pageBlockButtons>
   <apex:pageBlockTable border="1" cellpadding="6" value="{!components}" var="a" id="rows" >
      <apex:column headerValue="Delete"><apex:commandButton value='Del' action='{!remove}' onclick="return confirm('Are you sure—');"><apex:param value="{a.Id}" assignTo="{!dParam}" /></apex:commandButton></apex:column>
      <apex:column headerValue="Product">"{!a.PricebookEntry.Name}"</apex:column>
      <apex:column headerValue="Quantity"><apex:inputField value="{!a.Quantity}" /></apex:column>     
      <apex:column headerValue="Sales Price"><apex:inputField value="{!a.UnitPrice}" /></apex:column>
      <apex:column headerValue="List Price">"{!a.ListPrice}"</apex:column>
      <apex:column headerValue="Total Price">"{!a.TotalPrice}"</apex:column>
   </apex:pageBlockTable>
  </apex:pageblock>
 </apex:form>
</apex:page>

 Controller:
Code:
public class cntrl_ext_save {
        public String selectedProd {get;set;}
        public String dParam;
        public String getdParam() {
            return dParam;
        }
        public void setdParam(String s) {
            dParam = s;
        }
        public List<OpportunityLineItem> componentList;  // list of components to appear in the multi-line.
        public PageReference reset() {
            componentList = [select id, quantity, totalprice, unitprice, listprice, PricebookEntry.name, pricebookentry.product2.Family from OpportunityLineItem where OpportunityId = :ApexPages.currentPage().getParameters().get('id') and pricebookentry.product2.Family = '03 Professional Services'];
            return null;
        }  
        public List<OpportunityLineItem> getComponents() {
            if(componentList == null) reset(); 
            return componentList;
        }
        public void setComponents(List<OpportunityLineItem> Components) {
            componentList = Components;
        }
        public PageReference save() {
            upsert componentList;
            return null;    
        }
        public PageReference add() {
            Opportunity pb = [select Pricebook2Id from Opportunity where Id = :ApexPages.currentPage().getParameters().get('id')];
            PricebookEntry prod = [select UnitPrice, Name, Id from PricebookEntry where Product2Id = :selectedProd and Pricebook2Id = :pb.Pricebook2Id];
            componentList.add(New OpportunityLineItem(OpportunityId = ApexPages.currentPage().getParameters().get('id'), UnitPrice=prod.UnitPrice, PricebookEntryId=prod.Id, Quantity=1));
            save();
            reset();
            return null;                
        }
        public PageReference remove() {
            system.debug('test '+dParam);
            OpportunityLineItem oli = Database.query('select Id from OpportunityLineItem where id='+dParam);
            delete oli;
            reset();
            return null;
        }
        public List<SelectOption> getItems() {
            List<SelectOption> op = new List<SelectOption>();
            for(Product2 prod : [select id, name from Product2 where family='03 Professional Services']) op.add(new SelectOption(prod.Id, prod.Name));
            return op;
        }
}

 


  • November 17, 2008
  • Like
  • 0
Hello,
I have created a custom button to display in new window where the content source is a custom s-control (HTML).  All works well but I would like to be able to control the properties of the window before it opens (size, scroolbars, statusbar, toolbar).  Where can I find those properties?
Thanks!!!
  • February 08, 2008
  • Like
  • 0
I am trying to apply style to field label and field data in a s-control. Its getting applied but i am not getting exactly same look and feel as salesforce. I have included sfdc style sheets and i have applied the right class also but it looks like i am missing some thing. here is the small snippet.

It would be grt if someone can guide me if i am missing anything else. Thx. Deepak.
Hi,
 
I am trying to create the following formula field in a custom object named Product. I want the product name to be generated dynamically from the Brand Name and denomination field selected for the product. Brand is a lookup field in Product Obejct. When I save the following formula, it says "Error: Field Brand__r does not exist. Check spelling."
 
Formula:
 
Brand__r.Name & "-" &    TEXT(Denomination__c)
 
If I use Brand__c & "-" &    TEXT(Denomination__c) , the the 15-digit Brand ID is displayed instead of name.
 
Please let me know is there is any workaorund for this.
 
Thanks for your help.
 
Ambili
  • January 30, 2008
  • Like
  • 0
Hi,
 
I am starting to learn s-control on the job. 
 
I created a S-control ( as url, an external .Net application ).  I have two questions.
 
1. How to attatch it to a custom button ?  I am able to override a standard button. But I do not want that. I want to create new custome button and call the s-control on click of that button. Is this feature available now  in Enterprise edition?
 
2.  How to pass parameters from salesforce screen to this s-control when the user clicks on it ? I want to pass IDs of the case screen , when the user clicks on the custom button or link ? Can someone please help me with a sample code snippet,
 
 would really appreciate your answers to the questions above  !!
 
 
Thanks,
Meena
I'm looking for a way to update an Opportunity (calculate something and update some fields) whenever an Opportunity was modified.
Is there a way to implement an s-ontrol that does this and attach it to the opportunity? I heard something about inline s-controls but couldn't figure out if that's what I need.

I know that I can do that with triggers (appex code) but I would like to use an s-control.

Can someone helpe me?
  • January 29, 2008
  • Like
  • 0
I want to make the custom page in salesforce.I also want the look and feel of the custom page as any other  pages we have in salesforce(Eg Account ,Contact).

Please help me how to start with the first step in making the custom page by the help of S-controls.

Regards
Mohit


I need to update the owner on 242  cases.  We have a custom field in the cases object that contains an internal user's alias 'JSMITH' that would signify 'John Smith'.  The 242 cases need to update the owner field with the full name identified by the custom field alias name.  So, if the custom field contains 'JSMITH' then the case owner would need to be updated to 'John Smith'.
 
What would be the easiest and most efficient way to handle this batch update?
 
Thank you.
Code:
<—xml version="1.0" encoding="utf-8"–>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
 xmlns:salesforce="com.salesforce.*"
 applicationComplete="login();">

<mx:DateFormatter id="dateform" formatString="MM"/>
<mx:NumberFormatter id="numform" precision="0"/>

<mx:Script>
 <![CDATA[
  import flash.external.ExternalInterface;
  import com.salesforce.results.QueryResult;
  import mx.collections.ArrayCollection;
  import com.salesforce.AsyncResponder;
  import com.salesforce.objects.LoginRequest;
  import mx.controls.dataGridClasses.DataGridColumn;
  private function login():void {
   apex.login( new LoginRequest({
    server_url : this.parameters.server_url,
    session_id : this.parameters.session_id,
    callback : new AsyncResponder(render)
    })
    );
  }
  private function render(result:Object):void {
   var currId:String = ExternalInterface.call("getID");
   apex.query("Select Amount, CloseDate, OwnerId from Opportunity where AccountId='{!Account.Id}' and Probability=100",
     new AsyncResponder(
     function (qr:QueryResult):void
     {
      var month:int = 0;
      var x:int = 0;
      var amt:Array = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0);
      var name:Array = new Array(" "," "," "," "," "," "," "," "," "," "," "," "," ");
      var months:Array = new Array("0","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
      var ar:ArrayCollection = new ArrayCollection();
      values.dataProvider = ar;
      for(var j:int=0;j<qr.records.length;j++) {
       month=numform.format(dateform.format(qr.records[j].CloseDate));
       amt[month]+=qr.records[j].Amount;
       apex.query("Select Name from User where Id='"+qr.records[j].OwnerId+"'",
       new AsyncResponder(
       function (qr2:QueryResult):void
       {
        name[x]=qr2.records[0].Name;
        x++;
       },
       function (fault:Object):void {}
       ));
      }
      ar=createArray(months, amt, name, ar);
     },
     function (fault:Object):void {}
  ));
 }
 private function createArray(months:Array, amt:Array, name:Array, ar:ArrayCollection):ArrayCollection {
  for(var i:int=1;i<13;i++)
  {
   ar.addItem( {Month:months[i], Amount:amt[i], Name:name[i]});
  }
  return(ar);
 }
 ]]>
</mx:Script>

<salesforce:Connection id="apex" />
 <mx:ColumnChart x="118" y="46" id="values">
  <mx:series>
   <mx:ColumnSeries displayName="Opp Amounts" yField="Amount"/>
   <mx:ColumnSeries displayName="Owner" yField="Owner"/>
  </mx:series>
 </mx:ColumnChart>
 <mx:Legend dataProvider="{values}"/>
 
</mx:Application>

I'm learning how to code simple Flex graphs, and I'm trying to push all my information into the ArrayCollection ar. The problem is that, regardless of what method I try, I'll put a breakpoint on the line return(ar) and a breakpoint on the line x++ under my second AsynchResponder. Inevitably, the return(ar) function will activate PRIOR to the breakpoint for x++, which means none of my names are initialized before the ArrayCollection is created. How does one 'wait' for all the data to be returned?
 


Message Edited by MattL on 01-28-2008 11:38 AM
  • January 25, 2008
  • Like
  • 0
XXX



Message Edited by muronghe on 07-16-2008 12:08 PM
Hi I have the following S-Control and then following the Iframe opening up at the Homepage as a component...
But it is slow to load the homepage when they sign in any one has any ideas how to make it fast...PLZZZ
Code:
<html> 
<head> 
<meta http-equiv=“refresh” content=“600″ /> 
<script type="text/javascript" src="/soap/ajax/10.0/connection.js"></script> 
<script type="text/javascript"> 
window.onload=init_page; 
function init_page() 
{ 
var j= ""; 
var output=""; 
strSQL = "Select Id,AS400_Account_Number__c,Name,BillingCity,SF_DATE_ON_SERVICE__c from Account where OwnerId='{!$User.Id}' and SF_DATE_ON_SERVICE__c = LAST_N_DAYS:30 ORDER BY SF_DATE_ON_SERVICE__c DESC"; 
var result = sforce.connection.query(strSQL); 
var records = result.getArray("records"); 
for (var i=0; i<records.length; i++) 
{ 
j +='<a href="/' + records[i].Id + ' "target=_blank"">' + (i+1) +') ' + records[i].SF_DATE_ON_SERVICE__c + ' - ' + records[i].AS400_Account_Number__c + ' - ' + records[i].Name + ' - ' + records[i].BillingCity + '</a><br>&nbsp;' 
} 
document.getElementById('div_tag').innerHTML = j ; 
} 
</script> 
</head> 
<body bgcolor="#F3F3EC"> 
<font size="2" face="Verdana"> 
<div id="div_tag">No Accts</div></font> 
</body> 
</html>

 
  • January 25, 2008
  • Like
  • 0
Can salesforce report on how often a field changes or is it limited to only reporting the last modified date.  I'm trying to track how often users are editing their cases

I'm developing an S-control where one of the fields is a picklist value. Ideally, I wouldn't need to hard-code the values in. Going through the Sforce Explorer, I can navigate under the field name down to "type - picklist" and then "Picklist Values", but I can't figure out how to structure my SOQL query to gain access to this data. Can anyone advise if it's even possible, or will I need to resort to hard-coding it in?  
  • January 24, 2008
  • Like
  • 0
I am looking for a way to auto populate fileds so they are read only on a customer obkect. Esstentially a deal would have a vendor based on a relastionship look up. The vendors phone number and address are stored under their contact information. The phone number would be "shown or copied" onthe deal.

Any easy way of doing this?

Thanks

Steve
Hey,
 
There may be similar threads on this topic, but here goes anyway:
 
>>>>
YES:  SEE RECENT POST
WHICH IS THE EXACT SAME THING, OR NEARLY SO
<<<<
 
We have an org from which we're sourcing a managed package, and I'm trying to connect to it using the new Force.com Eclipse plug-in (v. 11.1.1).  The SOAP Endpoint is v. 11.1 as well.  What I get when connecting, and also when trying to 'refresh from server', or 'synchronize with server', is a msg box with the following error:
 
Unable to perform synchronization.
 
Reason:
TeamException: null: Duplicate retrieve names specified for package '<pkg name>'
 
I see a stack trace in my workspace log; if anybody wants to see it, I'd be happy to add it to this thread.
 
Does anybody have some insight into this, and what I can do about it, or how I can work around it?  Let's say for the sake of discussion that I do NOT want to re-create my org from scratch.  :^}
 
Thanks!
 
-phil m.


Message Edited by philbo on 01-14-2008 10:19 AM
  • January 14, 2008
  • Like
  • 0