• Elke
  • NEWBIE
  • 25 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 8
    Replies

Hi,

 

has anybody experiences in using JS libraries as ext.js inside the javascript code of a custom button for executing javascript?

 

I would like to use custom list buttons with the onclick functionality for selected records in the list view, depending on input values by the user. I want to use the standard Salesforce list views here (no custom VF Page with controller functionality).

The problem is how to invoke any InputBox (or better a Listbox/Combobox with suggestions) by the javascript code to wait for a user input. At the moment I use the "promp()" JS function. I would prefer using MessageBoxes or similar from an external JS library as ext.js or jQuery.  Is this possible at all?

I would appreciate any litte running sample how to invoke such an input box and use the result for further handling inside the custom button code.

 

Thanks in advance,

Elke

  • July 05, 2012
  • Like
  • 0

Hi everybody,

I have a problem with updating Opportunity Products. User can change the Discount, the Quantity and the Sales Price (in special cases only). The Total Price shall be calculated by the system and displayed at the VF page. In some cases Discount can be set to 100%. If so, I detected the issue that  the Sales Price (OpportunityLineItem.UnitPrice, so I call it UnitPrice in the following description) is set to null by the system during the Update.

In Forum Threads and in the Documentation of the OpportunityLineItem Object I read that UnitPrice and TotalPrice must not be set both during an Update. That’s why I force the TotalPrice to be null before I update a record which is selected from the database before. Indead, this solves the problem. The UnitPrice is stored into the database as expected and TotalPrice is calculated to 0.0 which is correct. Unfortunately the next update in exactly the same manner is failing. I get an exception that the TotalPrice must not be null…

 

I narrowed down the behavior with a simple test class in a developer edition. There are no custom fields, no triggers and no validation rules for the object OpportunityLineItem.

 

Here is the code of my test class mixed with the corresponding Debug information picked out from Apex Test Runner window in the IDE (Eclipse).

 

    static testMethod void myUnitTest() {
        // insert a dummy Product with PricebookEntries then check that they were created
        Product2 pr1 = new Product2(Name='Unit Test Product PR1 Dummy');
        insert pr1;
 
 	//Get the PriceBook
 	PriceBook2 pb=[Select Name, IsStandard, IsActive, Id From Pricebook2 Where IsStandard=true Limit 1];
 	PricebookEntry pe1 = New PriceBookEntry(Product2Id=pr1.Id,PriceBook2Id=pb.Id,unitPrice=444.0,isactive=true);
 	insert pe1; 
        
     
        Account ac1 = new Account(Name='Unit Test Parent');
        insert ac1;
        
        Opportunity op1 = new Opportunity(Name = 'Unit Test Parent', StageName='Prospecting', 
        CloseDate=System.today().addDays(1), AccountId=ac1.Id);
        insert op1;
        Opportunity op1s = [SELECT ID FROM Opportunity WHERE Id=:op1.Id];
 
        //check calculation Prices
        OpportunityLineItem ol1 = new OpportunityLineItem(OpportunityId=op1.Id, 
            UnitPrice=123.00, Quantity=1,Description=null, Discount=100, PricebookEntryId=pe1.Id);

        System.debug(LoggingLevel.INFO, '**********Before Insert Id=null ListPrice= '
        +ol1.ListPrice+' UnitPrice=' + ol1.UnitPrice+' Discount='+ol1.Discount+' TotalPrice='+ol1.TotalPrice);

 

 

14:17:14.598 (1598203000)|USER_DEBUG|[27]|INFO|**********Before Insert Id=null ListPrice= null UnitPrice=123.00 Discount=100 TotalPrice=null

        insert ol1;

       OpportunityLineItem ol2=[Select  o.UnitPrice, o.TotalPrice,
       o.Quantity, o.PricebookEntryId, o.ListPrice,
       o.Id, o.Discount From OpportunityLineItem o where o.id=:ol1.Id];
        
        System.debug(LoggingLevel.INFO, '**********After Insert Id='+ol2.Id+
        ' ListPrice= '+ol2.ListPrice+' UnitPrice=' + ol2.UnitPrice+
        ' Discount='+ol2.Discount+' TotalPrice='+ol2.TotalPrice);

 

14:17:14.688 (1688622000)|USER_DEBUG|[34]|INFO|**********After Insert Id=00kG000000HBCU9IAP ListPrice= 444.00 UnitPrice=123.00 Discount=100.00 TotalPrice=0.00

 

OKAY

 

 		Update ol2;
 		
 
        OpportunityLineItem  ol3=[Select  o.UnitPrice, o.TotalPrice,
        o.Quantity, o.PricebookEntryId, o.ListPrice, o.Id,
        o.Discount From OpportunityLineItem o where o.id=:ol2.Id];
 
        System.debug(LoggingLevel.INFO, '**********After Update '
        +ol3.Id+'ListPrice= '+ol3.ListPrice+ ' UnitPrice=' 
        + ol3.UnitPrice+' Discount='+ol3.Discount+' TotalPrice='
        +ol3.TotalPrice);

 

14:17:14.739 (1739783000)|USER_DEBUG|[42]|INFO|**********After Update 00kG000000HBCU9IAPListPrice= 444.00 UnitPrice=null Discount=100.00 TotalPrice=0.00

 

Problem: UnitPrice is set to null. Trying to hide this by setting TotalPrice to null:

 

	//Try to set TotalPrice to null  because it's 0.0 after update
 	ol2.TotalPrice=null;
  	Update ol2;
 		
 	ol3=[Select  o.UnitPrice, o.TotalPrice, o.Quantity, 
          o.PricebookEntryId, o.ListPrice,o.Id, o.Discount 
          From OpportunityLineItem o where o.id=:ol2.Id];
        
        System.debug(LoggingLevel.INFO,
        '**********After Update with TotalPrice set to null '
         +ol3.Id+'ListPrice= '+ol3.ListPrice+ ' UnitPrice=' 
         + ol3.UnitPrice+' Discount='+ol3.Discount+' TotalPrice='
         +ol3.TotalPrice);

 

14:17:14.790 (1790286000)|USER_DEBUG|[50]|INFO|**********After Update with TotalPrice set to null 00kG000000HBCU9IAPListPrice= 444.00 UnitPrice=123.00 Discount=100.00 TotalPrice=0.00

 

OKAY! But what if user updates a second time:

 

 	//Try to set TotalPrice to null again because it's 0.0 after update
  	ol2.TotalPrice=null;
  	Update ol2;

	ol3=[Select  o.UnitPrice, o.TotalPrice, o.Quantity, 
          o.PricebookEntryId, o.ListPrice,o.Id, o.Discount 
          From OpportunityLineItem o where o.id=:ol2.Id];
 
         System.debug(LoggingLevel.INFO, 
        '**********After 2. Update with TotalPrice set to null '
        +ol3.Id+'ListPrice= '+ol3.ListPrice+ ' UnitPrice=' 
        + ol3.UnitPrice+' Discount='+ol3.Discount+' TotalPrice='
        +ol3.TotalPrice);
 
    }
}

 

14:17:15.099 (2099067000)|FATAL_ERROR|System.DmlException: Update failed. First exception on row 0 with id 00kG000000HBCU9IAP; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: TotalPrice (total price must be specified): [TotalPrice]

 

Why can't I update the same record twice with TotalPrice set to null? Maybe I'm wrong with anything...

 

Any explainings for this behavior? I urgently need an idea how to solve this trouble. Seems to be the same problem in Winter’12 and Spring ’12.

 

Thanks in advance,

Elke

  • February 02, 2012
  • Like
  • 0

 

Hi everybody,

 

We’ve overridden the Account View with a little VF page.  Inside this VF page we use apex:detail to show the Account page layout. After upgrading our sandbox to the Salesforce Release Winter’12 we recognized that the line in top of the page with the quick links to all related lists is missing.

 

 

Same VF page in another Salesforce Instance with release Summer ’11 still shows this line.

We used following statement

<apex:detail showChatter="true" relatedList="true" relatedListHover="true" inlineEdit="true"/>

 

Any advice how to get this line back in the new release? Please note, that all related lists are shown as expected. We only miss the line with the links to the related lists in top of the page.

 

Thanks,

Elke

  • September 26, 2011
  • Like
  • 0

Hi everybody,

 

Is it possible to override the standard button for adding new Account Team Members in the related list of an Account with a Visualforce page?

We want to restrict adding Account Team Members (not more than 5 members per account, not more than one Account Manager…and so on). Since we cannot use a trigger for Account Team we are thinking about controlling this by a VF page.

Any better idea would also be highly appreciated..

Thanks,

Elke

  • June 21, 2011
  • Like
  • 0

Hi all,

 

does anybody know a way to upload photos to user profiles by batch? We want to upload images and set the FullPhotoURL attribute of our users programmatically so that all of them have a photo if we roll out chatter. I'm not sure if this is possible at all. Any other ideas for solving this problem would be helpful, too.

Thanks,

Elke

  • April 27, 2011
  • Like
  • 0

We want to override the VF page for adding products to an opportunity.

We added 3 custom fields to our Product2 object for choosing the products. These are picklist fields with field dependencies in order to filter our list of products. The content of “Product Sub-Group” depends on a selection of “Product Group” whereby “Product Group” depends on the selection of “Main Article Group”.

This is very simple to develop if we use a variable p of type Product2 which is declared in the controller extension and accessed in the VF Page with <apex:inputField..> .  See this little code:

public without sharing class yAddProducts { public Product2 p {get;set;} public yAddProducts(ApexPages.StandardController controller) { p=new Product2(); } } <apex:page standardcontroller="Opportunity" extensions="yAddProducts"> <apex:Form > <apex:PageBlock > <apex:outputText value="{!$ObjectType.Product2.Fields.yMainArticleGroup__c.Label}"/><BR/> <apex:Inputfield value="{!p.yMainArticleGroup__c}"/><BR/> <apex:outputText value="{!$ObjectType.Product2.Fields.yProductGroup__c.Label}"/><BR/> <apex:inputField value="{!p.yProductGroup__c}"/><BR/> <apex:outputText value="{!$ObjectType.Product2.Fields.yProductSubGroup__c.Label}"/><BR/> <apex:Inputfield value="{!p.yProductSubGroup__c}"/><BR/> </apex:pageBlock> </apex:Form> </apex:page>

It’s possible to select values from the picklist with dependencies. Everything works as expected if we are logged in as system administrator.  But our users have only read permissions for the Product2 Object.  These users don’t see any listbox for the picklists at the VF page. The problem exists because of the permissions, but our users shall not be allowed to create, update or delete products. Note: we don’t want to save the product in variable p, we only need this as a "template" for the comfortable input with dependencies of the list boxes to use it as a filter. Of course, we could develop the dependencies of the picklist values with string arrays or whatever, but this is lot of work, especially if values in the picklist fields and their dependencies will change some day. Any idea how I can use <apex:inputField..> for an SObject independent of the given CRUD permissions for the logged in user?

Thanks,

Elke

  • April 13, 2011
  • Like
  • 0

Hi all, I try to collapse a pageBlockSection using JavaScript with the method twistSection based on this: http://boards.developerforce.com/t5/Visualforce-Development/Setting-how-a-Collapsible-PageBlockSection-is-rendered/m-p/63577

Here is my very simple VF page.

<apex:page id="MyPage">
 
<script type="text/javascript"> 

 function customToggleSection(el){
  
 if(typeof twistSection == 'function'){
    var theTwist = document.getElementById(el);
   //alert (el);
   //alert (theTwist);
  
   if(theTwist){
     // twistSection expects you to click on the IMG link, this targets that img HTMLelement
     twistSection(theTwist.childNodes[0].childNodes[0])​;
     
   } 
 }
}

customToggleSection('{!$Component.MyPage.MyForm.theBlock.theSection}');

</script>
<apex:Form id="MyForm">
<apex:pageBlock mode="detail" id="theBlock">


<apex:pageBlockSection title="MySection" id="theSection" columns="1">
<!-- Section contents here -->
Text1
Text2
Text3<BR/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:commandButton value="Click" onClick="customToggleSection('{!$Component.MyPage.MyForm.theBlock.theSection}');return false;"></apex:commandButton>
</apex:Form>



</apex:page>

The code is working fine in Firefox. But in Internet Explorer (version 8.0.7600.xxx)  I get an error on the page, to be seen in the status bar.

If I comment the line

   twistSection(theTwist.childNodes[0].childNodes[0])​;

the error disappears, but of course nothing happens…

Can anybody help me to find the reason for this? 

Thanks - Elke

  • March 14, 2011
  • Like
  • 0

Hi,

 

based on this helpful article

http://blog.jeffdouglas.com/2010/07/13/building-a-dynamic-search-page-in-visualforce/

I try to develop a VF page with a custom controller extension to prepare a dynamic search for a name string.

I’m using a custom object named “ySkill__c” which has a relation to the SF User object (1:1).

Everything works as expected. I see a table of all my records, I can type in a search string. If I type in any letter in the input text field of my search the “onkeyup” event occurs. I get into the method runSearch() and at least into the method runQuery(). But the table is not filtered with the new query, I see the same set of records. Maybe the page is not refreshed?? If I press “Enter” the query is executed the records are filtered on the page. But it should also work with “KeyUp”, not only if I hit “Enter”.

Can anybody please help me to find my mistake? Attached is the code of my VF page and the Apex custom controller.

 

Thanks a lot,

Elke

<apex:page standardController="ySkill__c" recordSetvar="employees" extensions="TestListExt">
  <apex:form >
    <apex:pageMessages id="errors" />
    
    <apex:pageBlock title="Find Employees" mode="edit">
    <table width="100%" border="0">
        <tr>
            <td width="200" valign="top">
            <apex:pageBlock title="Search for:" mode="edit" id="criteria">
            
            <script type="text/javascript">
            function doSearch () {
               alert(document.getElementById("firstName").value);
               searchServer( document.getElementById("firstName").value);
            }
            </script>
            
            <apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug, errors">
                <apex:param name="firstName" value="" />
            </apex:actionFunction>
            <table cellpadding="2" cellspacing="2">
                <tr>
                    <td style="font-weight:bold;">Name<br/>
                    <input type="text" id="firstName" onkeyup="doSearch();"/>
                    </td>
                </tr>
            </table>
            </apex:pageBlock>
            </td>   
            <td valign="top">
            <apex:pageBlockTable value="{!employees}" var="e">
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Name" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="Name" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!e.Name}"/>
            </apex:column>
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Alias Name" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="yUserName__r.Alias" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!e.yUserName__r.Alias}"/>
            </apex:column>
            
         </apex:pageBlockTable>
     </td>
  </tr>
  </table>

 </apex:pageBlock>
 
  <apex:pageBlock title="Debug - SOQL" id="debug">
      <apex:outputText value="{!debugSoql}" />           
  </apex:pageBlock>    
 
  </apex:form>

</apex:page>

 

public with sharing class TestListExt {


    public TestListExt(ApexPages.StandardSetController controller) {
        soql = 'SELECT id, name, yUserName__r.name, yUserName__r.Alias FROM ySkill__c, ySkill__c.yUserName__r ';
        runQuery();


    }


  // the soql without the order and limit
  private String soql {get;set;}
  // the collection of employees based on custom onject ySkill__c to display
  public List<ySkill__c> employees {get;set;}
 
   // the current sort direction. defaults to asc
  public String sortDir {
    get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
    set;
  }
 
  // the current field to sort by. defaults to last name
  public String sortField {
    get  { if (sortField == null) {sortField = 'Name'; } return sortField;  }
    set;
  }
 
 
   // format the soql for display on the visualforce page
  public String debugSoql {
    get { return soql + ' order by ' + sortField + ' ' + sortDir ; }
    set;
  }
 
    // toggles the sorting of query from asc<-->desc
  public void toggleSort() {
    // simply toggle the direction
    sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
    // run the query again
    runQuery();
  }
 public void runQuery() {
  //for test only
       ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, soql));

    try {
      employees = Database.query(soql + ' order by ' + sortField + ' ' + sortDir);
    } catch (Exception e) {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Wrong SQL!'));
    }
 
  }
    // runs the search with parameters passed via Javascript
  public PageReference runSearch() {
     String theName = Apexpages.currentPage().getParameters().get('firstName');
        soql = 'SELECT id, name, yUserName__r.name, yUserName__r.Alias FROM ySkill__c, ySkill__c.yUserName__r ';
   if (!theName.equals(''))
      soql += ' where name LIKE \''+String.escapeSingleQuotes(theName)+'%\'';
   
   runQuery();
 
    return null;
  }
  
}

 

  • March 07, 2011
  • Like
  • 0

I’ve created 2 custom objects. One of them (‘Visit’) has got a field (‘Guest’) with data type 'Lookup Relationship'  to the other object (‘Address’)

 

I want to access data from the record in the custom object ‘Visit’ and the related object ‘Address’ to add it to a Visualforce Page.

 

As  read in the Visualforce Developer Guide it should be possible to use the merge field syntax to retrieve data from related records if using standard controllers for the objects. Here is what I tried:

 

<apex:page standardController="Visit__c">

  {!Visit__c.Name}

  {!Visit__c.Guest__c}

This is okay. I see the Name and the key from the related record.

</apex:page>

 

But if I try accessing the values from the related records with

{!Visit__c.Guest__c.Name} or

{!Visit__c.Guest__c.AddressId__c}     (which is another field in custom object ‘Address’)

I get an error

Error: Unknown property 'String.AddressId__c'

 

So it seems for me that there is only the key for the related record provided as a string and not the record itself.

 

Same is working for the relation between ‘Accounts’ and ’Contacts’ which are standard objects in Salesforce.

<apex:page standardController="contact" >

  {!contact.Name}

  {!contact.Account}

  {!contact.Account.Name}

</apex:page>

 

Any idea if this is a known limitation for custom objects and how to get this working?

 

  • January 27, 2011
  • Like
  • 0

During a batch apex job I have noticed the number of Total Batches is changing, lowering. It starts high and then as the job progresses the number starts to lower. It would also appear that the batch apex job is missing some of the records that should have been originally queried and are never being processed by the batch apex class.

 

Here are some images showing the drop as the batch job progresses:

1670 Total Batches

 

1623 Total Batches

 

1527 Total Batches after complete

 

The difference is 143 batches or 29,000 records which is exactly how many records are not being processed.

 

This is bizarre. Any ideas?

 

Thanks,

Jason

Hi everybody,

I have a problem with updating Opportunity Products. User can change the Discount, the Quantity and the Sales Price (in special cases only). The Total Price shall be calculated by the system and displayed at the VF page. In some cases Discount can be set to 100%. If so, I detected the issue that  the Sales Price (OpportunityLineItem.UnitPrice, so I call it UnitPrice in the following description) is set to null by the system during the Update.

In Forum Threads and in the Documentation of the OpportunityLineItem Object I read that UnitPrice and TotalPrice must not be set both during an Update. That’s why I force the TotalPrice to be null before I update a record which is selected from the database before. Indead, this solves the problem. The UnitPrice is stored into the database as expected and TotalPrice is calculated to 0.0 which is correct. Unfortunately the next update in exactly the same manner is failing. I get an exception that the TotalPrice must not be null…

 

I narrowed down the behavior with a simple test class in a developer edition. There are no custom fields, no triggers and no validation rules for the object OpportunityLineItem.

 

Here is the code of my test class mixed with the corresponding Debug information picked out from Apex Test Runner window in the IDE (Eclipse).

 

    static testMethod void myUnitTest() {
        // insert a dummy Product with PricebookEntries then check that they were created
        Product2 pr1 = new Product2(Name='Unit Test Product PR1 Dummy');
        insert pr1;
 
 	//Get the PriceBook
 	PriceBook2 pb=[Select Name, IsStandard, IsActive, Id From Pricebook2 Where IsStandard=true Limit 1];
 	PricebookEntry pe1 = New PriceBookEntry(Product2Id=pr1.Id,PriceBook2Id=pb.Id,unitPrice=444.0,isactive=true);
 	insert pe1; 
        
     
        Account ac1 = new Account(Name='Unit Test Parent');
        insert ac1;
        
        Opportunity op1 = new Opportunity(Name = 'Unit Test Parent', StageName='Prospecting', 
        CloseDate=System.today().addDays(1), AccountId=ac1.Id);
        insert op1;
        Opportunity op1s = [SELECT ID FROM Opportunity WHERE Id=:op1.Id];
 
        //check calculation Prices
        OpportunityLineItem ol1 = new OpportunityLineItem(OpportunityId=op1.Id, 
            UnitPrice=123.00, Quantity=1,Description=null, Discount=100, PricebookEntryId=pe1.Id);

        System.debug(LoggingLevel.INFO, '**********Before Insert Id=null ListPrice= '
        +ol1.ListPrice+' UnitPrice=' + ol1.UnitPrice+' Discount='+ol1.Discount+' TotalPrice='+ol1.TotalPrice);

 

 

14:17:14.598 (1598203000)|USER_DEBUG|[27]|INFO|**********Before Insert Id=null ListPrice= null UnitPrice=123.00 Discount=100 TotalPrice=null

        insert ol1;

       OpportunityLineItem ol2=[Select  o.UnitPrice, o.TotalPrice,
       o.Quantity, o.PricebookEntryId, o.ListPrice,
       o.Id, o.Discount From OpportunityLineItem o where o.id=:ol1.Id];
        
        System.debug(LoggingLevel.INFO, '**********After Insert Id='+ol2.Id+
        ' ListPrice= '+ol2.ListPrice+' UnitPrice=' + ol2.UnitPrice+
        ' Discount='+ol2.Discount+' TotalPrice='+ol2.TotalPrice);

 

14:17:14.688 (1688622000)|USER_DEBUG|[34]|INFO|**********After Insert Id=00kG000000HBCU9IAP ListPrice= 444.00 UnitPrice=123.00 Discount=100.00 TotalPrice=0.00

 

OKAY

 

 		Update ol2;
 		
 
        OpportunityLineItem  ol3=[Select  o.UnitPrice, o.TotalPrice,
        o.Quantity, o.PricebookEntryId, o.ListPrice, o.Id,
        o.Discount From OpportunityLineItem o where o.id=:ol2.Id];
 
        System.debug(LoggingLevel.INFO, '**********After Update '
        +ol3.Id+'ListPrice= '+ol3.ListPrice+ ' UnitPrice=' 
        + ol3.UnitPrice+' Discount='+ol3.Discount+' TotalPrice='
        +ol3.TotalPrice);

 

14:17:14.739 (1739783000)|USER_DEBUG|[42]|INFO|**********After Update 00kG000000HBCU9IAPListPrice= 444.00 UnitPrice=null Discount=100.00 TotalPrice=0.00

 

Problem: UnitPrice is set to null. Trying to hide this by setting TotalPrice to null:

 

	//Try to set TotalPrice to null  because it's 0.0 after update
 	ol2.TotalPrice=null;
  	Update ol2;
 		
 	ol3=[Select  o.UnitPrice, o.TotalPrice, o.Quantity, 
          o.PricebookEntryId, o.ListPrice,o.Id, o.Discount 
          From OpportunityLineItem o where o.id=:ol2.Id];
        
        System.debug(LoggingLevel.INFO,
        '**********After Update with TotalPrice set to null '
         +ol3.Id+'ListPrice= '+ol3.ListPrice+ ' UnitPrice=' 
         + ol3.UnitPrice+' Discount='+ol3.Discount+' TotalPrice='
         +ol3.TotalPrice);

 

14:17:14.790 (1790286000)|USER_DEBUG|[50]|INFO|**********After Update with TotalPrice set to null 00kG000000HBCU9IAPListPrice= 444.00 UnitPrice=123.00 Discount=100.00 TotalPrice=0.00

 

OKAY! But what if user updates a second time:

 

 	//Try to set TotalPrice to null again because it's 0.0 after update
  	ol2.TotalPrice=null;
  	Update ol2;

	ol3=[Select  o.UnitPrice, o.TotalPrice, o.Quantity, 
          o.PricebookEntryId, o.ListPrice,o.Id, o.Discount 
          From OpportunityLineItem o where o.id=:ol2.Id];
 
         System.debug(LoggingLevel.INFO, 
        '**********After 2. Update with TotalPrice set to null '
        +ol3.Id+'ListPrice= '+ol3.ListPrice+ ' UnitPrice=' 
        + ol3.UnitPrice+' Discount='+ol3.Discount+' TotalPrice='
        +ol3.TotalPrice);
 
    }
}

 

14:17:15.099 (2099067000)|FATAL_ERROR|System.DmlException: Update failed. First exception on row 0 with id 00kG000000HBCU9IAP; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: TotalPrice (total price must be specified): [TotalPrice]

 

Why can't I update the same record twice with TotalPrice set to null? Maybe I'm wrong with anything...

 

Any explainings for this behavior? I urgently need an idea how to solve this trouble. Seems to be the same problem in Winter’12 and Spring ’12.

 

Thanks in advance,

Elke

  • February 02, 2012
  • Like
  • 0

Hi all,

 

does anybody know a way to upload photos to user profiles by batch? We want to upload images and set the FullPhotoURL attribute of our users programmatically so that all of them have a photo if we roll out chatter. I'm not sure if this is possible at all. Any other ideas for solving this problem would be helpful, too.

Thanks,

Elke

  • April 27, 2011
  • Like
  • 0

We want to override the VF page for adding products to an opportunity.

We added 3 custom fields to our Product2 object for choosing the products. These are picklist fields with field dependencies in order to filter our list of products. The content of “Product Sub-Group” depends on a selection of “Product Group” whereby “Product Group” depends on the selection of “Main Article Group”.

This is very simple to develop if we use a variable p of type Product2 which is declared in the controller extension and accessed in the VF Page with <apex:inputField..> .  See this little code:

public without sharing class yAddProducts { public Product2 p {get;set;} public yAddProducts(ApexPages.StandardController controller) { p=new Product2(); } } <apex:page standardcontroller="Opportunity" extensions="yAddProducts"> <apex:Form > <apex:PageBlock > <apex:outputText value="{!$ObjectType.Product2.Fields.yMainArticleGroup__c.Label}"/><BR/> <apex:Inputfield value="{!p.yMainArticleGroup__c}"/><BR/> <apex:outputText value="{!$ObjectType.Product2.Fields.yProductGroup__c.Label}"/><BR/> <apex:inputField value="{!p.yProductGroup__c}"/><BR/> <apex:outputText value="{!$ObjectType.Product2.Fields.yProductSubGroup__c.Label}"/><BR/> <apex:Inputfield value="{!p.yProductSubGroup__c}"/><BR/> </apex:pageBlock> </apex:Form> </apex:page>

It’s possible to select values from the picklist with dependencies. Everything works as expected if we are logged in as system administrator.  But our users have only read permissions for the Product2 Object.  These users don’t see any listbox for the picklists at the VF page. The problem exists because of the permissions, but our users shall not be allowed to create, update or delete products. Note: we don’t want to save the product in variable p, we only need this as a "template" for the comfortable input with dependencies of the list boxes to use it as a filter. Of course, we could develop the dependencies of the picklist values with string arrays or whatever, but this is lot of work, especially if values in the picklist fields and their dependencies will change some day. Any idea how I can use <apex:inputField..> for an SObject independent of the given CRUD permissions for the logged in user?

Thanks,

Elke

  • April 13, 2011
  • Like
  • 0

Hi,

 

based on this helpful article

http://blog.jeffdouglas.com/2010/07/13/building-a-dynamic-search-page-in-visualforce/

I try to develop a VF page with a custom controller extension to prepare a dynamic search for a name string.

I’m using a custom object named “ySkill__c” which has a relation to the SF User object (1:1).

Everything works as expected. I see a table of all my records, I can type in a search string. If I type in any letter in the input text field of my search the “onkeyup” event occurs. I get into the method runSearch() and at least into the method runQuery(). But the table is not filtered with the new query, I see the same set of records. Maybe the page is not refreshed?? If I press “Enter” the query is executed the records are filtered on the page. But it should also work with “KeyUp”, not only if I hit “Enter”.

Can anybody please help me to find my mistake? Attached is the code of my VF page and the Apex custom controller.

 

Thanks a lot,

Elke

<apex:page standardController="ySkill__c" recordSetvar="employees" extensions="TestListExt">
  <apex:form >
    <apex:pageMessages id="errors" />
    
    <apex:pageBlock title="Find Employees" mode="edit">
    <table width="100%" border="0">
        <tr>
            <td width="200" valign="top">
            <apex:pageBlock title="Search for:" mode="edit" id="criteria">
            
            <script type="text/javascript">
            function doSearch () {
               alert(document.getElementById("firstName").value);
               searchServer( document.getElementById("firstName").value);
            }
            </script>
            
            <apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug, errors">
                <apex:param name="firstName" value="" />
            </apex:actionFunction>
            <table cellpadding="2" cellspacing="2">
                <tr>
                    <td style="font-weight:bold;">Name<br/>
                    <input type="text" id="firstName" onkeyup="doSearch();"/>
                    </td>
                </tr>
            </table>
            </apex:pageBlock>
            </td>   
            <td valign="top">
            <apex:pageBlockTable value="{!employees}" var="e">
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Name" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="Name" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!e.Name}"/>
            </apex:column>
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Alias Name" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="yUserName__r.Alias" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!e.yUserName__r.Alias}"/>
            </apex:column>
            
         </apex:pageBlockTable>
     </td>
  </tr>
  </table>

 </apex:pageBlock>
 
  <apex:pageBlock title="Debug - SOQL" id="debug">
      <apex:outputText value="{!debugSoql}" />           
  </apex:pageBlock>    
 
  </apex:form>

</apex:page>

 

public with sharing class TestListExt {


    public TestListExt(ApexPages.StandardSetController controller) {
        soql = 'SELECT id, name, yUserName__r.name, yUserName__r.Alias FROM ySkill__c, ySkill__c.yUserName__r ';
        runQuery();


    }


  // the soql without the order and limit
  private String soql {get;set;}
  // the collection of employees based on custom onject ySkill__c to display
  public List<ySkill__c> employees {get;set;}
 
   // the current sort direction. defaults to asc
  public String sortDir {
    get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
    set;
  }
 
  // the current field to sort by. defaults to last name
  public String sortField {
    get  { if (sortField == null) {sortField = 'Name'; } return sortField;  }
    set;
  }
 
 
   // format the soql for display on the visualforce page
  public String debugSoql {
    get { return soql + ' order by ' + sortField + ' ' + sortDir ; }
    set;
  }
 
    // toggles the sorting of query from asc<-->desc
  public void toggleSort() {
    // simply toggle the direction
    sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
    // run the query again
    runQuery();
  }
 public void runQuery() {
  //for test only
       ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, soql));

    try {
      employees = Database.query(soql + ' order by ' + sortField + ' ' + sortDir);
    } catch (Exception e) {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Wrong SQL!'));
    }
 
  }
    // runs the search with parameters passed via Javascript
  public PageReference runSearch() {
     String theName = Apexpages.currentPage().getParameters().get('firstName');
        soql = 'SELECT id, name, yUserName__r.name, yUserName__r.Alias FROM ySkill__c, ySkill__c.yUserName__r ';
   if (!theName.equals(''))
      soql += ' where name LIKE \''+String.escapeSingleQuotes(theName)+'%\'';
   
   runQuery();
 
    return null;
  }
  
}

 

  • March 07, 2011
  • Like
  • 0

I’ve created 2 custom objects. One of them (‘Visit’) has got a field (‘Guest’) with data type 'Lookup Relationship'  to the other object (‘Address’)

 

I want to access data from the record in the custom object ‘Visit’ and the related object ‘Address’ to add it to a Visualforce Page.

 

As  read in the Visualforce Developer Guide it should be possible to use the merge field syntax to retrieve data from related records if using standard controllers for the objects. Here is what I tried:

 

<apex:page standardController="Visit__c">

  {!Visit__c.Name}

  {!Visit__c.Guest__c}

This is okay. I see the Name and the key from the related record.

</apex:page>

 

But if I try accessing the values from the related records with

{!Visit__c.Guest__c.Name} or

{!Visit__c.Guest__c.AddressId__c}     (which is another field in custom object ‘Address’)

I get an error

Error: Unknown property 'String.AddressId__c'

 

So it seems for me that there is only the key for the related record provided as a string and not the record itself.

 

Same is working for the relation between ‘Accounts’ and ’Contacts’ which are standard objects in Salesforce.

<apex:page standardController="contact" >

  {!contact.Name}

  {!contact.Account}

  {!contact.Account.Name}

</apex:page>

 

Any idea if this is a known limitation for custom objects and how to get this working?

 

  • January 27, 2011
  • Like
  • 0
Is it possible to replace the ui/opportunity/SelectSearch with a visualforce page ?
 
any idea ?
 
 
  • July 23, 2008
  • Like
  • 0