• patske
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 17
    Replies
I Have a trigger that needs to fire only for certain users.... Well to be honest it more accurately needs to NOT fire for 1 particular user.

Is there anyway this can be done? Can I check "$Current.User" or something like that in my trigger code?

I know I can have a trigger that will fire based on a users profile and permissions but, I still need the user to have "read / edit / create" priveleges for a certain object I just don't want them to have permission to fire the trigger that is on that object.


Anyhelp as always greatly appreciated. Thanks :)


Message Edited by patske on 08-03-2008 06:28 AM
  • August 03, 2008
  • Like
  • 0
Hi Guys,

Just trying to see if this can be done using some standard SF VF stuff or a hack combination of some of the new features.

On a Visual force page I'd like to make a <apex:inputField> which is just a text field a lookup to any object I want.

A use case for this is. A input form made in VF where someone would enter a name into an apex input field for e.g

<apex:inputField Value="{!CustomObject.Name__c}" />

but that field is just a text field. When someone starts typing it will do the kinda cool but kinda limited lame 'sf lookup autocomplete' for contacts in 'recent items (would help if this was every record!! /rant)... If someone see's that their contact is not in their 'autocomplete' list then they just type a name and click enter. This will populate "Contact.Name__c" with whatever they typed.

If they select an option from the autocomplete list then Name__c will populate with the name of the Contact found.
So really it's just an autocomplete type function from scratch. I tried implementing the old Salesforce Labs Autocomplete on Lookups S-Control (Which is GREAT because it looks up every record on an object /rant)

But unfortunately it doesn't work on VF pages :(

Any help with some sort of lookup would be great. Trying to implement 3rd Party javascript autocomplete's has turned out to be such a nightmare with salesforce formatting and VF pages.

So again Thanks in advance and any help would be greatly appreciated.




Message Edited by patske on 07-01-2008 11:59 PM
Hi All,

I've been looking at the "set methods" in the apex lnaguage reference and see that there is no 'get' method for sets.
How does someone iterate through a set of values?

For example I have a Map of type Map<String, List<String>> myMap;

for each of the keys I'd like to do something with the list of values in the map.... to find the list of keys I use the Map Method "keySet()"

so I have a Set<String> s = myMap.keySet();

then I want a loop to iterate through this set and get the list from the map based on the set.value .....

help please???

Hey guys still having a bit of trouble on this one. Main thing being that I want to pass my output string from the javascript function "GroupOrder();" to my controller or extension.... Is there anyway to do it? Kind of really need an answer :(

I've seen something similar on the forums but couldn't quite get it working. Really would appreciate any help on this one it's driving me nuts!

In dreamweaver I can get this "groupOrder();" function to execute and give me a string of what elements have what children. But in Visual force everything seems to work fine except for this one **bleep** function .

Below is my code for my controller and my visual force page Thanks in advance to anyone that can crack this one. Right now I'm pulling values from SF and using <apex:repeater" tags to format them.. then I want to get the value that gets spat out from "groupOrder()" in the javascript and parse it to upsert some objects in salesforce. Obviously any other ideas on how to solve this would be great also.

Cheers,

Code:
VISUAL FORCE PAGE

<apex:page id="p" standardController="Account" extensions="allocateticketExt" tabstyle="Ticket_Allocation__c" standardStylesheets="false">
  <apex:sectionHeader title="Allocate Tickets"/>
  <apex:form id="f">
   <script src="http://script.aculo.us/prototype.js" type="text/javascript"></script>
   <script src="http://script.aculo.us/scriptaculous.js" type="text/javascript"></script>
  

    <script language="JavaScript">
    sections = ['Tickets'];
    <apex:repeat value="{!salescontacts}" var="scCS">
    sections.push('{!scCS.id}');
    </apex:repeat>

    function createNewSection(name) {
        var name = $F('sectionName');
        if (name != '') {
            var newDiv = Builder.node('div', {id: 'group' + (sections.length + 1), className: 'section', style: 'display:none;' }, [
                Builder.node('h3', {className: 'handle'}, name)
            ]);

            sections.push(newDiv.id);
            $('page').appendChild(newDiv);
            Effect.Appear(newDiv.id);
            destroyLineItemSortables();
            createLineItemSortables();
            createGroupSortable();
        }
    }

    function createLineItemSortables() {
        for(var i = 0; i < sections.length; i++) {
            Sortable.create(sections[i],{tag:'div',dropOnEmpty: true, containment: sections,only:'lineitem'});
        }
    }

    function destroyLineItemSortables() {
        for(var i = 0; i < sections.length; i++) {
            Sortable.destroy(sections[i]);
        }
    }

    function createGroupSortable() {
        Sortable.create('page',{tag:'div',only:'section',handle:'handle'});
    }

    </script>
<style>
    body, div {
        font-family: Arial, Helvetica;
        font-size: 11px;
    }

    div.section,div#createNew {
        border: 1px solid #CCCCCC;
        margin: 30px 5px;
        padding: 0px 0px 10px 0px;
        background-color: #EFEFEF;
    }
      
    div#createNew input { margin-left: 5px; }

    div#createNew h3, div.section h3{
        font-size: 14px;
        padding: 2px 5px;
        margin: 0 0 10px 0;
        background-color: #CCCCCC;
        display: block;
    }

    div.section h3 {
        cursor: move;
    }

    div.lineitem {
        margin: 3px 10px;
        padding: 2px;
        background-color: #FFFFFF;
        cursor: move;
    }

    h1 {
        margin-bottom: 0;
        font-size: 18px;
    }
</style>
<div id="page">
    <div id="createNew">
        <h3>Add New Sales Contact</h3>
        <input type="text" id="sectionName" size="25" />
        <input type="button" onClick="createNewSection();" value="Create Sales Contact" />
    </div>
    
    <div id="Tickets" class="section">
        <h3 class="handle">Tickets</h3>
        <apex:repeat value="{!ticket}" var="t" id="AllTickets">
         <div id="{!t.id}" class="lineitem">{!t.Product_Full_Name__c}</div>
        </apex:repeat>
    </div>
        
    <apex:repeat value="{!salescontacts}" var="sc" id="Allocations">
    <div id="{!sc.id}" class="section">
        <h3 class="handle">{!sc.Name__c}  ({!sc.Role__c})</h3>
        <apex:repeat value="{!allocated}" var="aoi">
            <script type="text/javascript">
              if({!CONTAINS(sc.id,aoi.Sales_Contact__c)}){
                document.write('<div id="{!aoi.Order_Item__c}" class="lineitem">{!aoi.Order_Item__r.Product_Full_Name__c}</div>');
              }
            </script>
        </apex:repeat>
    </div>
    </apex:repeat>
</div>
<br/><br/>
<p>
 <apex:outputText value="Clicked— {!state}" id="showstate" />
</p>

<apex:outputPanel onclick="methodOneInJavascript(GroupOrder();)" styleClass="btn"> 
  Click Me 
</apex:outputPanel>

<apex:actionFunction action="{!methodOne}" name="methodOneInJavascript" rerender="showstate">
   <apex:param name="firstParam" assignTo="{!state}" value="" />
</apex:actionFunction>

<script type="text/javascript">
    // <![CDATA[
    Sortable.create('Tickets',{tag:'div',dropOnEmpty: true, containment: sections,only:'lineitem'});
    <apex:repeat value="{!salescontacts}" var="scs">
      Sortable.create('{!scs.id}',{tag:'div',dropOnEmpty: true, containment: sections,only:'lineitem'});
    </apex:repeat>
    Sortable.create('page',{tag:'div',only:'section',handle:'handle'});
    // ]]>
 </script>
 <script type="text/javascript">
         function SortIt(order){
           var trueorder = '';
           if(order.length==null){return trueorder;}
           else{
           for(x=0;x<order.length;x++){
             if(x==(order.length-1)){
              trueorder = trueorder + order[x].id;
             }
             else{
              trueorder = trueorder + order[x].id + ',';
             }
           }
           return trueorder;
           }
          }
        
         /*
         Debug Functions for checking the group and item order
         */
         function GroupOrder() {
          var sections = document.form['p:f'].getElementsByClassName('section');
          var alerttext = '';
          for(var i=0;i<sections.length;i++){
           var sectionID = sections[i].id;
           var lineitems = document.form['p:f'].getElementById(sectionID).getElementsByClassName('lineitem');
           var realorder = SortIt(lineitems);
           alerttext += sectionID + ': ' + realorder + '\n';
          }
          return alerttext;
         }
</script>
</apex:form>
</apex:page>


CONTROLLER

public class allocateticketExt {

    String aId;
    String pId;
    List<Order_Item__c> tickets;
    List<Order_Item__c> ticketsB = new List<Order_Item__c>();
    List<Sales_Contact__c> salescontacts;
    List<Ticket_Allocation__c> allocations = new List<Ticket_Allocation__c>(); // list of allocations
    List<Ticket_Allocation__c> allocated;
    
    public allocateticketExt(ApexPages.StandardController controller) {
      aId = ApexPages.currentPage().getParameters().get('aId');
      pId = ApexPages.currentPage().getParameters().get('pId');
    }
    
    public PageReference redirect(){
     PageReference pageRef = new PageReference('/'+pId);
     pageRef.setRedirect(true);
     return pageRef;
    }
    
    public void Tickets() {
      tickets = [select Product_Full_Name__c, Product_new__c, Product_new__r.RecordTypeId, Product_new__r.Ticket_Class__c, Quantity__c, Sales_Prospect__c from Order_Item__c where Sales_Prospect__c = :pId and Product_new__r.RecordTypeId='012T00000000EONIA2' order by Quantity__c DESC];
      for(integer i=0;i<tickets.size();i++){
        if(tickets[i].Quantity__c == 1){
          ticketsB.add(tickets[i]);
        }
        else{
          for(integer j=0;j<tickets[i].Quantity__c;j++){
            ticketsB.add(tickets[i]);
          }
        }
      }
    }
    
    public List<Ticket_Allocation__c> getAllocated(){
      allocated = [select Id, Order_Item__r.Product_Full_Name__c, Order_Item__c, Sales_Contact__c, Sales_Contact__r.Name__c, Sales_Contact__r.Role__c from Ticket_Allocation__c where Sales_Contact__r.Sales_Prospect__c = :pId];
      return allocated;
    }
    
    public List<Order_Item__c> getTicket() {
      Tickets();
      return ticketsB;
    }

    public List<Sales_Contact__c> getSalesContacts(){
      salescontacts = [select Id, Name__c, Contact__r.Name, Contact__c, Role__c, Sales_Prospect__c, Number_Of_Tickets_Allocated__c from Sales_Contact__c where Sales_Prospect__c = :pId];
      return salescontacts;
    }
    
    public void setState(String n) {
  state = n;
}

public String getState() {
  return state;
}

public PageReference methodOne() {
  return null;
}

private String state = 'no';
}

 

Hi guys,

I'm trying to get a pretty standard Scriptaculous drag and drop functionality using javascript to work in a visual force page. Am not having any great deal of luck right now. Can anyone help or point me in the right direction

below is the source for the drag and drop page I have done in HTML it works fine I want to try and port it to visual force, ultimately being able to use the output from the 'debug log button there' to use in a Controller Extension and create some relationships between objects.

I'm guessing the problem is with the way visual force pages reference ID's?? But I can't be completely sure. Any help would be great. Thanks :)


Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
 <title>Drag Drop</title>
  <script src="http://script.aculo.us/prototype.js" type="text/javascript"></script>
  <script src="http://script.aculo.us/scriptaculous.js" type="text/javascript"></script>
  

 <script language="JavaScript">
 sections = ['group1','group2','group3'];

 function createNewSection(name) {
  var name = $F('sectionName');
  if (name != '') {
   var newDiv = Builder.node('div', {id: 'group' + (sections.length + 1), className: 'section', style: 'display:none;' }, [
    Builder.node('h3', {className: 'handle'}, name)
   ]);

   sections.push(newDiv.id);
   $('page').appendChild(newDiv);
   Effect.Appear(newDiv.id);
   destroyLineItemSortables();
   createLineItemSortables();
   createGroupSortable();
  }
 }

 function createLineItemSortables() {
  for(var i = 0; i < sections.length; i++) {
   Sortable.create(sections[i],{tag:'div',dropOnEmpty: true, containment: sections,only:'lineitem'});
  }
 }

 function destroyLineItemSortables() {
  for(var i = 0; i < sections.length; i++) {
   Sortable.destroy(sections[i]);
  }
 }

 function createGroupSortable() {
  Sortable.create('page',{tag:'div',only:'section',handle:'handle'});
 }

 /*
 Debug Functions for checking the group and item order
 */
 function getGroupOrder() {
  var sections = document.getElementsByClassName('section');
  var alerttext = '';
  sections.each(function(section) {
   var sectionID = section.id;
   var order = Sortable.serialize(sectionID);
   alerttext += sectionID + ': ' + Sortable.sequence(section) + '\n';
  });
  alert(alerttext);
  return false;
 }
 </script>

<style>
 body, div {
  font-family: Arial, Helvetica;
  font-size: 11px;
 }

 div.section,div#createNew {
  border: 1px solid #CCCCCC;
  margin: 30px 5px;
  padding: 0px 0px 10px 0px;
  background-color: #EFEFEF;
 }

 div#createNew input { margin-left: 5px; }

 div#createNew h3, div.section h3{
  font-size: 14px;
  padding: 2px 5px;
  margin: 0 0 10px 0;
  background-color: #CCCCCC;
  display: block;
 }

 div.section h3 {
  cursor: move;
 }

 div.lineitem {
  margin: 3px 10px;
  padding: 2px;
  background-color: #FFFFFF;
  cursor: move;
 }

 h1 {
  margin-bottom: 0;
  font-size: 18px;
 }
</style>
</head>
<body>
<div id="page">

 <div id="createNew">

  <h3>Add New Sales Contact</h3>
  <input type="text" id="sectionName" size="25">
  <input type="button" onClick="createNewSection();" value="Create Sales Contact">
 </div>

 <div id="group1" class="section">
  <h3 class="handle">Tickets</h3>
  <div id="item_1" class="lineitem">DWD2008 VIP</div>

  <div id="item_2" class="lineitem">DWD2008 GOLD</div>
  <div id="item_3" class="lineitem">DWD2008 SILVER</div>
  <div id="item_4" class="lineitem">DWD2008 BRONZE</div>
 </div>

 <div id="group2" class="section">
  <h3 class="handle">Sales Contact 1</h3>

 </div>

 <div id="group3" class="section">
  <h3 class="handle">Sales Contact 2</h3>
 </div>

</div>

<fieldset>
 <legend>group order debug</legend>

 <input type="button" onClick="getGroupOrder()" value="output group order">
 <br>
</fieldset>

<script type="text/javascript">
 // <![CDATA[
 Sortable.create('group1',{tag:'div',dropOnEmpty: true, containment: sections,only:'lineitem'});
 Sortable.create('group2',{tag:'div',dropOnEmpty: true, containment: sections,only:'lineitem'});
 Sortable.create('group3',{tag:'div',dropOnEmpty: true, containment: sections,only:'lineitem'});
 Sortable.create('page',{tag:'div',only:'section',handle:'handle'});
 // ]]>
 </script>
</body>
</html>

 


Hi Guys,

I have a problem that has me a little stumped. I have a few triggers in my sandbox some written by me some written by another developer. On their own they work fine but they are dependant on each other in that one creates records that the other triggers off of so when they are made active I start to get some funny results and anusual errors popping every now and then.

Here's just one of the errors I'm receiving.

(1)
paymentAA: execution of AfterUpdate

caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE
_ENTITY, invoiceAction: execution of AfterInsert

caused by: System.ListException: Duplicate id in list: a0aT00000009RIzIAM

Class.InvoiceAction.updateInvo
iceAmount: line 54, column 9
Trigger.invoiceAction: line 4, column 9

Class.PaymentAA.CreateInvoice: line 65, column 12
Class.PaymentAA.CreatePayment: line 29, column 13
Trigger.paymentAA: line 2, column 4

And below are the lines of code referenced by this error well the main 'perpetraitors' as I see it

One important note to mention is that this code gives seems to only give me errors when I have more than 1 Invoice_Item__c in the list to insert. When there is just one it works fine but when there is 2 or more it seems as though it crashes I'm guessing because it calles the trigger on invoice_item__c twice too quickly? Before both records are committed? I'm not sure but any help would be great. Thanks in advance.

Code:
FROM PaymentAA

...
// define a new invoice 
           Emp_Invoice__c newinvoice = new Emp_Invoice__c();
           
           // update the value of the account it relates to to the same as the sales prospect
           newinvoice.Account__c = spAcc;
           
           // relate to sales prospect
           newinvoice.Sales_Prospect__c = spID;
           
           // sets the date on the invoice
           newinvoice.Invoice_Date__c = date.today();
                      
           // commits the new invoice to database
           insert newinvoice;

           // returns a list of all the order items associated with sales prospect
           List<Order_Item__c> orderitems = [select Name, Order_Line_Total__c from Order_Item__c where Sales_Prospect__c = :spID];
           List<Invoice_Item__c> ii = new List<Invoice_Item__c>();
           // iterate over all the line items in the order
           for (Order_Item__c oi : orderitems) {
               // create a new invoice item corresponding to each order item with the same values
               ii.add(new Invoice_Item__c(Invoice__c = newinvoice.Id, Order_Item__c = oi.Id, Line_Total_ex_GST__c = oi.Order_Line_Total__c));
           }
           insert ii;
...



AND THE WHOLE Class.InvoiceAction This Triggers from "Invoice_Item__c" after insert / after update 

public class InvoiceAction { public static void updateInvoiceAmount(Invoice_Item__c[] newInvItems) { //array of invoices that have a new amount paid List<Emp_Invoice__c> myInvoices = new List<Emp_Invoice__c>(); //iterate over all the new invoice items in this batch for (Invoice_Item__c thisInvItem:newInvItems ) { //ingnore invoice items with out an invoice if (thisInvItem.Invoice__c != null){ //get all invoice items for this invoice List<Invoice_Item__c> allInvItems = [SELECT Id, Line_Total_ex_GST__c, GST_Amount__c, Amount_Paid__c FROM Invoice_Item__c WHERE Invoice__c = :thisInvItem.Invoice__c limit 1000]; // get the invoice for this invoice item and lock it Emp_Invoice__c thisInvoice = [SELECT Id, Amount_ex_GST__c, GST_Amount__c, Amount_Paid__c FROM Emp_Invoice__c WHERE Id = :thisInvItem.Invoice__c limit 1 for update]; decimal sumApPaid = 0.0; decimal sumLtPaid = 0.0; decimal sumGstPaid = 0.0; // sum up all the invoice items for this invoice for (Invoice_Item__c cInvItem:allInvItems ) { if(cInvItem.Amount_Paid__c != null){ sumApPaid += cInvItem.Amount_Paid__c; } if(cInvItem.Line_Total_ex_GST__c != null){ sumLtPaid += cInvItem.Line_Total_ex_GST__c; } if(cInvItem.GST_Amount__c != null){ sumGstPaid += cInvItem.GST_Amount__c; } } // update the amuount paid for this invoice thisInvoice.Amount_Paid__c = sumApPaid; thisInvoice.Amount_ex_GST__c = sumLtPaid; thisInvoice.GST_Amount__c = sumGstPaid; // add this invoice to the array of invoices that have a new amount paid System.debug('[InvoiceAction -> executeTriggerAfter] adding amount paid=' + thisInvoice.Amount_Paid__c + ' to invoice id=' +thisInvoice.id); myInvoices.add(thisInvoice); } } //update all invoices that have a new amount paid update myInvoices; } }

 




Message Edited by patske on 06-19-2008 03:40 PM

Message Edited by patske on 06-19-2008 03:44 PM
Hi Guys, I've written a few VF pages that all work well. I have one that uses a custom controller I have written and would like to use it to override the edit button on a custom object.

However when I go to the custom object and click override on the edit button then select content type = "Visual Force Page"  I can only select VF pages that use that custom object as the 'standardController'.

The page I need to override the Edit Button with uses a customController. Any reason why this is the way it is?

My page with the custom controller kind of edits 3 objects at a time basically displaying the main object they clicked from along with editable related lists of related objects, then updates them on save associating the related objects to the main object they clicked from.

Any reason why I can't select pages with a custom controller when overriding?

Any info would be great.

Thanks,
Hi guys I've browsed around the forums a little and looked through the pdf's but just can't seem to get this one right. I'm missing something simple. I know I've overlooked something but I can't find it. Sorry

Can someone let me know how I can make this bit of code on my visual force page... return to the page I'm currently on once it's clicked?

Code:
URLFOR($Action.Sales_Contact__c.Delete, c.Id, null, true)

 
Basically how do I set RetURL for a URLFOR? If someone could write it out for me that would be great.

I need it to return to /apex/addsalesprospectId={!Account.Id}   when I'm finished.

Sorry and thanks to anyone that helps.


Message Edited by patske on 06-04-2008 11:14 PM
I'm just thinking this one out loud right now.

I was wondering if on my Visual Force page that I have created with custom objects and my desired custom layout. A Hover Detail style interface much like what salesforce uses in the sidebar for recent items when 'hover detail is enabled'.

Any points in the right direction would also be very much appreciated.

So basically I have a visual force page with all of my PageBlockTables... listing information I want in the layout that I'd like... now on some of those records I'd like to hover over the 'name' or the 'id' and trigger a "hover detail" style popup that will show some extra details that I can also choose to view / edit


Any thoughts?
Hi all,

I'm having some trouble passing default values into <apex:inputFields> is it possible? For instance if I want to set

<apex:inputHidden value="{c.Sales_Prospect__c}" /> to a certain value can I do it?

Basically I'm looking for a similar action to HTML where I can have something like the following

<input type="hidden" name="sales_prospect__c" value="David G">

I've looked through the attributes of <apex:inputHidden> and <apex:inputField> and noticed there are none for default value.

any help would be much appreciated.

basically my problem is that in my code {c.Sales_Prospect__c} is a lookup field. when I submit the form I have created I know what value I want to put in that field but I just can't seem to do it, it's always blank and creates an unrelated record.

P.S I am new to visual force here

Thanks,

Patrick


Message Edited by patske on 05-30-2008 12:05 AM

Message Edited by patske on 05-30-2008 12:07 AM
I Have a trigger that needs to fire only for certain users.... Well to be honest it more accurately needs to NOT fire for 1 particular user.

Is there anyway this can be done? Can I check "$Current.User" or something like that in my trigger code?

I know I can have a trigger that will fire based on a users profile and permissions but, I still need the user to have "read / edit / create" priveleges for a certain object I just don't want them to have permission to fire the trigger that is on that object.


Anyhelp as always greatly appreciated. Thanks :)


Message Edited by patske on 08-03-2008 06:28 AM
  • August 03, 2008
  • Like
  • 0
Hi All,

I've been looking at the "set methods" in the apex lnaguage reference and see that there is no 'get' method for sets.
How does someone iterate through a set of values?

For example I have a Map of type Map<String, List<String>> myMap;

for each of the keys I'd like to do something with the list of values in the map.... to find the list of keys I use the Map Method "keySet()"

so I have a Set<String> s = myMap.keySet();

then I want a loop to iterate through this set and get the list from the map based on the set.value .....

help please???

Hey guys still having a bit of trouble on this one. Main thing being that I want to pass my output string from the javascript function "GroupOrder();" to my controller or extension.... Is there anyway to do it? Kind of really need an answer :(

I've seen something similar on the forums but couldn't quite get it working. Really would appreciate any help on this one it's driving me nuts!

In dreamweaver I can get this "groupOrder();" function to execute and give me a string of what elements have what children. But in Visual force everything seems to work fine except for this one **bleep** function .

Below is my code for my controller and my visual force page Thanks in advance to anyone that can crack this one. Right now I'm pulling values from SF and using <apex:repeater" tags to format them.. then I want to get the value that gets spat out from "groupOrder()" in the javascript and parse it to upsert some objects in salesforce. Obviously any other ideas on how to solve this would be great also.

Cheers,

Code:
VISUAL FORCE PAGE

<apex:page id="p" standardController="Account" extensions="allocateticketExt" tabstyle="Ticket_Allocation__c" standardStylesheets="false">
  <apex:sectionHeader title="Allocate Tickets"/>
  <apex:form id="f">
   <script src="http://script.aculo.us/prototype.js" type="text/javascript"></script>
   <script src="http://script.aculo.us/scriptaculous.js" type="text/javascript"></script>
  

    <script language="JavaScript">
    sections = ['Tickets'];
    <apex:repeat value="{!salescontacts}" var="scCS">
    sections.push('{!scCS.id}');
    </apex:repeat>

    function createNewSection(name) {
        var name = $F('sectionName');
        if (name != '') {
            var newDiv = Builder.node('div', {id: 'group' + (sections.length + 1), className: 'section', style: 'display:none;' }, [
                Builder.node('h3', {className: 'handle'}, name)
            ]);

            sections.push(newDiv.id);
            $('page').appendChild(newDiv);
            Effect.Appear(newDiv.id);
            destroyLineItemSortables();
            createLineItemSortables();
            createGroupSortable();
        }
    }

    function createLineItemSortables() {
        for(var i = 0; i < sections.length; i++) {
            Sortable.create(sections[i],{tag:'div',dropOnEmpty: true, containment: sections,only:'lineitem'});
        }
    }

    function destroyLineItemSortables() {
        for(var i = 0; i < sections.length; i++) {
            Sortable.destroy(sections[i]);
        }
    }

    function createGroupSortable() {
        Sortable.create('page',{tag:'div',only:'section',handle:'handle'});
    }

    </script>
<style>
    body, div {
        font-family: Arial, Helvetica;
        font-size: 11px;
    }

    div.section,div#createNew {
        border: 1px solid #CCCCCC;
        margin: 30px 5px;
        padding: 0px 0px 10px 0px;
        background-color: #EFEFEF;
    }
      
    div#createNew input { margin-left: 5px; }

    div#createNew h3, div.section h3{
        font-size: 14px;
        padding: 2px 5px;
        margin: 0 0 10px 0;
        background-color: #CCCCCC;
        display: block;
    }

    div.section h3 {
        cursor: move;
    }

    div.lineitem {
        margin: 3px 10px;
        padding: 2px;
        background-color: #FFFFFF;
        cursor: move;
    }

    h1 {
        margin-bottom: 0;
        font-size: 18px;
    }
</style>
<div id="page">
    <div id="createNew">
        <h3>Add New Sales Contact</h3>
        <input type="text" id="sectionName" size="25" />
        <input type="button" onClick="createNewSection();" value="Create Sales Contact" />
    </div>
    
    <div id="Tickets" class="section">
        <h3 class="handle">Tickets</h3>
        <apex:repeat value="{!ticket}" var="t" id="AllTickets">
         <div id="{!t.id}" class="lineitem">{!t.Product_Full_Name__c}</div>
        </apex:repeat>
    </div>
        
    <apex:repeat value="{!salescontacts}" var="sc" id="Allocations">
    <div id="{!sc.id}" class="section">
        <h3 class="handle">{!sc.Name__c}  ({!sc.Role__c})</h3>
        <apex:repeat value="{!allocated}" var="aoi">
            <script type="text/javascript">
              if({!CONTAINS(sc.id,aoi.Sales_Contact__c)}){
                document.write('<div id="{!aoi.Order_Item__c}" class="lineitem">{!aoi.Order_Item__r.Product_Full_Name__c}</div>');
              }
            </script>
        </apex:repeat>
    </div>
    </apex:repeat>
</div>
<br/><br/>
<p>
 <apex:outputText value="Clicked— {!state}" id="showstate" />
</p>

<apex:outputPanel onclick="methodOneInJavascript(GroupOrder();)" styleClass="btn"> 
  Click Me 
</apex:outputPanel>

<apex:actionFunction action="{!methodOne}" name="methodOneInJavascript" rerender="showstate">
   <apex:param name="firstParam" assignTo="{!state}" value="" />
</apex:actionFunction>

<script type="text/javascript">
    // <![CDATA[
    Sortable.create('Tickets',{tag:'div',dropOnEmpty: true, containment: sections,only:'lineitem'});
    <apex:repeat value="{!salescontacts}" var="scs">
      Sortable.create('{!scs.id}',{tag:'div',dropOnEmpty: true, containment: sections,only:'lineitem'});
    </apex:repeat>
    Sortable.create('page',{tag:'div',only:'section',handle:'handle'});
    // ]]>
 </script>
 <script type="text/javascript">
         function SortIt(order){
           var trueorder = '';
           if(order.length==null){return trueorder;}
           else{
           for(x=0;x<order.length;x++){
             if(x==(order.length-1)){
              trueorder = trueorder + order[x].id;
             }
             else{
              trueorder = trueorder + order[x].id + ',';
             }
           }
           return trueorder;
           }
          }
        
         /*
         Debug Functions for checking the group and item order
         */
         function GroupOrder() {
          var sections = document.form['p:f'].getElementsByClassName('section');
          var alerttext = '';
          for(var i=0;i<sections.length;i++){
           var sectionID = sections[i].id;
           var lineitems = document.form['p:f'].getElementById(sectionID).getElementsByClassName('lineitem');
           var realorder = SortIt(lineitems);
           alerttext += sectionID + ': ' + realorder + '\n';
          }
          return alerttext;
         }
</script>
</apex:form>
</apex:page>


CONTROLLER

public class allocateticketExt {

    String aId;
    String pId;
    List<Order_Item__c> tickets;
    List<Order_Item__c> ticketsB = new List<Order_Item__c>();
    List<Sales_Contact__c> salescontacts;
    List<Ticket_Allocation__c> allocations = new List<Ticket_Allocation__c>(); // list of allocations
    List<Ticket_Allocation__c> allocated;
    
    public allocateticketExt(ApexPages.StandardController controller) {
      aId = ApexPages.currentPage().getParameters().get('aId');
      pId = ApexPages.currentPage().getParameters().get('pId');
    }
    
    public PageReference redirect(){
     PageReference pageRef = new PageReference('/'+pId);
     pageRef.setRedirect(true);
     return pageRef;
    }
    
    public void Tickets() {
      tickets = [select Product_Full_Name__c, Product_new__c, Product_new__r.RecordTypeId, Product_new__r.Ticket_Class__c, Quantity__c, Sales_Prospect__c from Order_Item__c where Sales_Prospect__c = :pId and Product_new__r.RecordTypeId='012T00000000EONIA2' order by Quantity__c DESC];
      for(integer i=0;i<tickets.size();i++){
        if(tickets[i].Quantity__c == 1){
          ticketsB.add(tickets[i]);
        }
        else{
          for(integer j=0;j<tickets[i].Quantity__c;j++){
            ticketsB.add(tickets[i]);
          }
        }
      }
    }
    
    public List<Ticket_Allocation__c> getAllocated(){
      allocated = [select Id, Order_Item__r.Product_Full_Name__c, Order_Item__c, Sales_Contact__c, Sales_Contact__r.Name__c, Sales_Contact__r.Role__c from Ticket_Allocation__c where Sales_Contact__r.Sales_Prospect__c = :pId];
      return allocated;
    }
    
    public List<Order_Item__c> getTicket() {
      Tickets();
      return ticketsB;
    }

    public List<Sales_Contact__c> getSalesContacts(){
      salescontacts = [select Id, Name__c, Contact__r.Name, Contact__c, Role__c, Sales_Prospect__c, Number_Of_Tickets_Allocated__c from Sales_Contact__c where Sales_Prospect__c = :pId];
      return salescontacts;
    }
    
    public void setState(String n) {
  state = n;
}

public String getState() {
  return state;
}

public PageReference methodOne() {
  return null;
}

private String state = 'no';
}

 

Hi guys,

I'm trying to get a pretty standard Scriptaculous drag and drop functionality using javascript to work in a visual force page. Am not having any great deal of luck right now. Can anyone help or point me in the right direction

below is the source for the drag and drop page I have done in HTML it works fine I want to try and port it to visual force, ultimately being able to use the output from the 'debug log button there' to use in a Controller Extension and create some relationships between objects.

I'm guessing the problem is with the way visual force pages reference ID's?? But I can't be completely sure. Any help would be great. Thanks :)


Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
 <title>Drag Drop</title>
  <script src="http://script.aculo.us/prototype.js" type="text/javascript"></script>
  <script src="http://script.aculo.us/scriptaculous.js" type="text/javascript"></script>
  

 <script language="JavaScript">
 sections = ['group1','group2','group3'];

 function createNewSection(name) {
  var name = $F('sectionName');
  if (name != '') {
   var newDiv = Builder.node('div', {id: 'group' + (sections.length + 1), className: 'section', style: 'display:none;' }, [
    Builder.node('h3', {className: 'handle'}, name)
   ]);

   sections.push(newDiv.id);
   $('page').appendChild(newDiv);
   Effect.Appear(newDiv.id);
   destroyLineItemSortables();
   createLineItemSortables();
   createGroupSortable();
  }
 }

 function createLineItemSortables() {
  for(var i = 0; i < sections.length; i++) {
   Sortable.create(sections[i],{tag:'div',dropOnEmpty: true, containment: sections,only:'lineitem'});
  }
 }

 function destroyLineItemSortables() {
  for(var i = 0; i < sections.length; i++) {
   Sortable.destroy(sections[i]);
  }
 }

 function createGroupSortable() {
  Sortable.create('page',{tag:'div',only:'section',handle:'handle'});
 }

 /*
 Debug Functions for checking the group and item order
 */
 function getGroupOrder() {
  var sections = document.getElementsByClassName('section');
  var alerttext = '';
  sections.each(function(section) {
   var sectionID = section.id;
   var order = Sortable.serialize(sectionID);
   alerttext += sectionID + ': ' + Sortable.sequence(section) + '\n';
  });
  alert(alerttext);
  return false;
 }
 </script>

<style>
 body, div {
  font-family: Arial, Helvetica;
  font-size: 11px;
 }

 div.section,div#createNew {
  border: 1px solid #CCCCCC;
  margin: 30px 5px;
  padding: 0px 0px 10px 0px;
  background-color: #EFEFEF;
 }

 div#createNew input { margin-left: 5px; }

 div#createNew h3, div.section h3{
  font-size: 14px;
  padding: 2px 5px;
  margin: 0 0 10px 0;
  background-color: #CCCCCC;
  display: block;
 }

 div.section h3 {
  cursor: move;
 }

 div.lineitem {
  margin: 3px 10px;
  padding: 2px;
  background-color: #FFFFFF;
  cursor: move;
 }

 h1 {
  margin-bottom: 0;
  font-size: 18px;
 }
</style>
</head>
<body>
<div id="page">

 <div id="createNew">

  <h3>Add New Sales Contact</h3>
  <input type="text" id="sectionName" size="25">
  <input type="button" onClick="createNewSection();" value="Create Sales Contact">
 </div>

 <div id="group1" class="section">
  <h3 class="handle">Tickets</h3>
  <div id="item_1" class="lineitem">DWD2008 VIP</div>

  <div id="item_2" class="lineitem">DWD2008 GOLD</div>
  <div id="item_3" class="lineitem">DWD2008 SILVER</div>
  <div id="item_4" class="lineitem">DWD2008 BRONZE</div>
 </div>

 <div id="group2" class="section">
  <h3 class="handle">Sales Contact 1</h3>

 </div>

 <div id="group3" class="section">
  <h3 class="handle">Sales Contact 2</h3>
 </div>

</div>

<fieldset>
 <legend>group order debug</legend>

 <input type="button" onClick="getGroupOrder()" value="output group order">
 <br>
</fieldset>

<script type="text/javascript">
 // <![CDATA[
 Sortable.create('group1',{tag:'div',dropOnEmpty: true, containment: sections,only:'lineitem'});
 Sortable.create('group2',{tag:'div',dropOnEmpty: true, containment: sections,only:'lineitem'});
 Sortable.create('group3',{tag:'div',dropOnEmpty: true, containment: sections,only:'lineitem'});
 Sortable.create('page',{tag:'div',only:'section',handle:'handle'});
 // ]]>
 </script>
</body>
</html>

 


Hi Guys,

I have a problem that has me a little stumped. I have a few triggers in my sandbox some written by me some written by another developer. On their own they work fine but they are dependant on each other in that one creates records that the other triggers off of so when they are made active I start to get some funny results and anusual errors popping every now and then.

Here's just one of the errors I'm receiving.

(1)
paymentAA: execution of AfterUpdate

caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE
_ENTITY, invoiceAction: execution of AfterInsert

caused by: System.ListException: Duplicate id in list: a0aT00000009RIzIAM

Class.InvoiceAction.updateInvo
iceAmount: line 54, column 9
Trigger.invoiceAction: line 4, column 9

Class.PaymentAA.CreateInvoice: line 65, column 12
Class.PaymentAA.CreatePayment: line 29, column 13
Trigger.paymentAA: line 2, column 4

And below are the lines of code referenced by this error well the main 'perpetraitors' as I see it

One important note to mention is that this code gives seems to only give me errors when I have more than 1 Invoice_Item__c in the list to insert. When there is just one it works fine but when there is 2 or more it seems as though it crashes I'm guessing because it calles the trigger on invoice_item__c twice too quickly? Before both records are committed? I'm not sure but any help would be great. Thanks in advance.

Code:
FROM PaymentAA

...
// define a new invoice 
           Emp_Invoice__c newinvoice = new Emp_Invoice__c();
           
           // update the value of the account it relates to to the same as the sales prospect
           newinvoice.Account__c = spAcc;
           
           // relate to sales prospect
           newinvoice.Sales_Prospect__c = spID;
           
           // sets the date on the invoice
           newinvoice.Invoice_Date__c = date.today();
                      
           // commits the new invoice to database
           insert newinvoice;

           // returns a list of all the order items associated with sales prospect
           List<Order_Item__c> orderitems = [select Name, Order_Line_Total__c from Order_Item__c where Sales_Prospect__c = :spID];
           List<Invoice_Item__c> ii = new List<Invoice_Item__c>();
           // iterate over all the line items in the order
           for (Order_Item__c oi : orderitems) {
               // create a new invoice item corresponding to each order item with the same values
               ii.add(new Invoice_Item__c(Invoice__c = newinvoice.Id, Order_Item__c = oi.Id, Line_Total_ex_GST__c = oi.Order_Line_Total__c));
           }
           insert ii;
...



AND THE WHOLE Class.InvoiceAction This Triggers from "Invoice_Item__c" after insert / after update 

public class InvoiceAction { public static void updateInvoiceAmount(Invoice_Item__c[] newInvItems) { //array of invoices that have a new amount paid List<Emp_Invoice__c> myInvoices = new List<Emp_Invoice__c>(); //iterate over all the new invoice items in this batch for (Invoice_Item__c thisInvItem:newInvItems ) { //ingnore invoice items with out an invoice if (thisInvItem.Invoice__c != null){ //get all invoice items for this invoice List<Invoice_Item__c> allInvItems = [SELECT Id, Line_Total_ex_GST__c, GST_Amount__c, Amount_Paid__c FROM Invoice_Item__c WHERE Invoice__c = :thisInvItem.Invoice__c limit 1000]; // get the invoice for this invoice item and lock it Emp_Invoice__c thisInvoice = [SELECT Id, Amount_ex_GST__c, GST_Amount__c, Amount_Paid__c FROM Emp_Invoice__c WHERE Id = :thisInvItem.Invoice__c limit 1 for update]; decimal sumApPaid = 0.0; decimal sumLtPaid = 0.0; decimal sumGstPaid = 0.0; // sum up all the invoice items for this invoice for (Invoice_Item__c cInvItem:allInvItems ) { if(cInvItem.Amount_Paid__c != null){ sumApPaid += cInvItem.Amount_Paid__c; } if(cInvItem.Line_Total_ex_GST__c != null){ sumLtPaid += cInvItem.Line_Total_ex_GST__c; } if(cInvItem.GST_Amount__c != null){ sumGstPaid += cInvItem.GST_Amount__c; } } // update the amuount paid for this invoice thisInvoice.Amount_Paid__c = sumApPaid; thisInvoice.Amount_ex_GST__c = sumLtPaid; thisInvoice.GST_Amount__c = sumGstPaid; // add this invoice to the array of invoices that have a new amount paid System.debug('[InvoiceAction -> executeTriggerAfter] adding amount paid=' + thisInvoice.Amount_Paid__c + ' to invoice id=' +thisInvoice.id); myInvoices.add(thisInvoice); } } //update all invoices that have a new amount paid update myInvoices; } }

 




Message Edited by patske on 06-19-2008 03:40 PM

Message Edited by patske on 06-19-2008 03:44 PM
Hi Guys, I've written a few VF pages that all work well. I have one that uses a custom controller I have written and would like to use it to override the edit button on a custom object.

However when I go to the custom object and click override on the edit button then select content type = "Visual Force Page"  I can only select VF pages that use that custom object as the 'standardController'.

The page I need to override the Edit Button with uses a customController. Any reason why this is the way it is?

My page with the custom controller kind of edits 3 objects at a time basically displaying the main object they clicked from along with editable related lists of related objects, then updates them on save associating the related objects to the main object they clicked from.

Any reason why I can't select pages with a custom controller when overriding?

Any info would be great.

Thanks,
Hello,
 
I've a requirement to display input fields of a particular standard object on my VF page; but the catch is, the set of fields I need displayed is going to be customizable (field names stored in a custom object, for example). How can I dynamically display these input fields based on the selections the user has made?
 
Thanks in advance.


Message Edited by santosh on 06-10-2008 02:46 AM
Hi

I know it's possible to send outbound email from an Apex Class using a template.  But what if the template has merge fields?  Will those merge fields be resolved correctly?  For example, lets say I have a custom object called XXX, and I create a trigger to call an Apex Class whenever a record of that custom object is created.  If the template has references to XXX merge fields, will these be resolved?

Thx,
Hamayoun
Hi guys I've browsed around the forums a little and looked through the pdf's but just can't seem to get this one right. I'm missing something simple. I know I've overlooked something but I can't find it. Sorry

Can someone let me know how I can make this bit of code on my visual force page... return to the page I'm currently on once it's clicked?

Code:
URLFOR($Action.Sales_Contact__c.Delete, c.Id, null, true)

 
Basically how do I set RetURL for a URLFOR? If someone could write it out for me that would be great.

I need it to return to /apex/addsalesprospectId={!Account.Id}   when I'm finished.

Sorry and thanks to anyone that helps.


Message Edited by patske on 06-04-2008 11:14 PM
Code:
<apex:pageBlock title="Lost Opportunites">
    <apex:pageBlockTable value="{!LostOpportunities}" var="aOpportunity" width="100%" >
                <apex:column headervalue="Opportunity Name" value="{!aOpportunity.Name}"/>
                <apex:column headervalue="Stage" value="{!aOpportunity.Stagename}"/>
                <apex:column headerdir="RTL" headervalue="Net Revenue" dir="RTL" value="{!aOpportunity.Sum_Net_Revenue__c}"/>
    </apex:pageBlockTable >
</apex:pageBlock>

 This code results in the last column having the header left justified and the value right justified.  I want both header and value to be right justified (RTL).  Have I done this wrong or is it a bug?

 
 


Message Edited by GerhardNewman2 on 06-06-2008 12:35 AM
I'm just thinking this one out loud right now.

I was wondering if on my Visual Force page that I have created with custom objects and my desired custom layout. A Hover Detail style interface much like what salesforce uses in the sidebar for recent items when 'hover detail is enabled'.

Any points in the right direction would also be very much appreciated.

So basically I have a visual force page with all of my PageBlockTables... listing information I want in the layout that I'd like... now on some of those records I'd like to hover over the 'name' or the 'id' and trigger a "hover detail" style popup that will show some extra details that I can also choose to view / edit


Any thoughts?
Hi all,

I'm having some trouble passing default values into <apex:inputFields> is it possible? For instance if I want to set

<apex:inputHidden value="{c.Sales_Prospect__c}" /> to a certain value can I do it?

Basically I'm looking for a similar action to HTML where I can have something like the following

<input type="hidden" name="sales_prospect__c" value="David G">

I've looked through the attributes of <apex:inputHidden> and <apex:inputField> and noticed there are none for default value.

any help would be much appreciated.

basically my problem is that in my code {c.Sales_Prospect__c} is a lookup field. when I submit the form I have created I know what value I want to put in that field but I just can't seem to do it, it's always blank and creates an unrelated record.

P.S I am new to visual force here

Thanks,

Patrick


Message Edited by patske on 05-30-2008 12:05 AM

Message Edited by patske on 05-30-2008 12:07 AM
Hi All,

First time poster long time lurker.

I'm having a little trouble getting my head around person account creation using the API.

basically my client has a B2C website with a registration form offering the option to create a 'personal account' or a 'business account' essentially all the is different between these is that one contains an additional company field on the web form.

Okay so my question is how do I create person accounts or refer to them? I understand that person accounts are still just accounts and contacts sort of squashed together and still exist on their own.

I know how to create an account and related contact for a web registration but that's only the case for a 'business account' rego via the website. If a user decides to create a "Personal account" via the website is it as simple as doing exactly the same as I would for a business account and then just setting the recordtypeid ? Or is it more like writing to fields like Account.PersonFirstName  etc...?

I'm not actually doing the development but someone with just as little knowledge as me is, so any help I can pass on to them would be greatly appreciated.

Thanks guys :)
  • May 22, 2008
  • Like
  • 0