• doubleminus
  • NEWBIE
  • 25 Points
  • Member since 2008

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 17
    Questions
  • 59
    Replies

So, I'm one of many unable to get rerender functionality working successfully. The actual update to the boolean istrue works successfully but the rerender refuses to work. Very simple use case here.

 

I'm using Apex to perform some basic XML parsing. I'm having no luck getting to any of the actual XML node names. The getLocalName()  method within the XmlStreamReader class always returns null for all nodes as I loop through them.

 

TEST CLASS:

@isTest
private class BPTCalloutTest {
private static final String XML_STR = '<document>' +
'<result>success</result>' +
'<resultcode>000000</resultcode>' +
'<note></note>' +
                                        '<item>' +
      '<quantity>1</quantity>' +
  '<fname>Bob</fname>' +
  '<lname>Tungsten</lname>' +
  '<address>23232 Fleet Street</address>' +
  '<city>Santa Clara</city>' +
  '<state>CA</state>' +
  '<zip>94105</zip>' +
  '<country>United States</country>' +
  '<email>blahblahblah@blahblahblah.com</email>' +
  '<phone>4155555555</phone>' +
    '</item>' +
  '</document>';
 
    static testMethod void xmlStreamReaderTest() {
        XmlStreamReader reader = new XmlStreamReader(XML_STR);
        Opportunity[] opptyList = BPTCallout.parseXML(reader);
        System.assert(opptyList != null);
        System.assert(!opptyList.isEmpty());
    }
}

 

MAIN CLASS:

public with sharing class BPTCallout {
    public BPTCallout() {}

    public static Opportunity[] parseXML(XmlStreamReader reader) {
        Opportunity[] oppList = new List<Opportunity>();

        if (reader != null) {
            while (reader.hasNext()) {
            	System.debug('$$$ reader.getEventType(): ' + reader.getEventType());
                if (reader.getEventType() == XmlTag.END_DOCUMENT) {
                    break;
                }
                else if (reader.getEventType() == XmlTag.CHARACTERS) {
                	System.debug('$$$ reader.getLocalName(): ' + reader.getLocalName());
                	System.debug('$$$ reader.getText(): ' + reader.getText());
                	System.debug('$$$ reader.getNamespace(): ' + reader.getNamespace());
                	System.debug('$$$ reader.getlocation(): ' + reader.getlocation());
                	System.debug('$$$ reader.getprefix(): ' + reader.getprefix());
                	
                	if (/*reader.getLocalName() == 'lname'*/ reader.getAttributeCount() == 4 && reader.getText() != null) {
	                    oppList.add(new Opportunity(Name = reader.getText()));
                	}
                }
                reader.next();
            }
        }
        System.debug('$$$ oppList: ' + oppList);
        return oppList;
    }
}

 

Very basic functionality at this point. If you run this, you will see that reader.getLocalName() always returns null and so do all accompanying methods (getNameSpace, getLocation, getPrefix).

 

Thanks in advance.

 

Hello everyone,

 

We are trying to use the new API Salesforce made available during Winter '13: Test.setMock.

We followed the documentation, but encountered the following issue that we were unable to resolve: a System.CalloutException, complaining that we had "uncommitted work pending".

 

Of course we do, our testmethod starts by setting up some Test Data that's necessary for the test to work, and that includes inserting and updating data.

In an actual execution, there would be no data creation, as the data would already be present. Actually doing the callout doesn't raise the Uncomitted work pending exception, so the Test Data really is at fault.

 

We did use Test.startTest() and Test.stopTest() to differentiate Test Data creation from Test Execution but this (as expected) didn't work.

We also tried some hacks, including the System.runAs(new User( Id = UserInfo.getUserId()){} that had, in the past, allowed us to circumvent "Mixed DML operations". This didn't work either.

 

We considered using the Test.loadData method, but we're inserting related objects and couldn't figure out a clean enough way to make it work (maybe we should try using ExternalID's?).

 

 

For the moment, our workaround is to modify the class generated from the WSDL, adding a if (Test.isRunningTest()) {} else {}, but that means we have to modify the autogenerated code, which is suboptimal.

 

 

Did anyone try to use this new API and run into the same issue? How did you solve it?

I'm trying to enter a new pricebookentry into the standard price book (which is inactive), but I can't get any results querying for the Standard Price Book (planning on setting inactive to false) through the test class.  Here's the error I get:

 

System.QueryException: List has no rows for assignment to SObject

 

And here is the query:

PriceBook2 pbStd = [SELECT Id, IsActive FROM PriceBook2 WHERE Name = 'Standard Price Book'];

 

When I run the same query in the Force IDE I get the record.

 

Any thoughts?  


I've seen some other threads around this subject, but the had a variety of issues being discussed and I'm hoping this one is more focused.

 

Am I missing something obvious? Here is my code:

 

@isTest
private class TestClassForIssue {
    public static Account testAccount1, testAccount2;

	static {
            testAccount1 = new Account(Name='testAccount1', NumberOfEmployees=10);
            insert testAccount1;
            System.assertNotEquals(testAccount1.Id, null);
	}

    static testMethod void test1() {
        System.assertNotEquals(testAccount1.Id, null);
}

 

The test1 testMethod assertion fails, saying that testAccount1.Id is null. Why is this? I'm sure I'm just missing something really obvious, but I'm not finding it...

To test a visualforce page, we pass the record id to the page, as in,

 

https://c.na9.visual.force.com/apex/pages/AccountRecord?id=a00E0000002RzBR

 

I want to dynamically pass the record id so I created a class, however it's giving an error, can someone please help me correct my code. 

 

Visualforce Page

<apex:page standardController="Position__c" showHeader="false" >

<apex:form>
<apex:pageBlock >
    <apex:pageBlockSection >
    
    <apex:sectionHeader title="New Position Details" /> 
    </apex:pageBlockSection > <br/>
    
    <b>  &nbsp;&nbsp;
         <apex:OutputLabel value="Your approval has been requested for the following New Position."> 
         </apex:OutputLabel>
    </b>
      
   <br/> <br/>
    &nbsp;&nbsp;
    Position Record: {!Position__c.Name} <br/><br/>
   
    &nbsp;&nbsp;
    Status: {!Position__c.Status__c} <br/><br/>
   
    &nbsp;&nbsp;
    Location: {!Position__c.Location__c}<br/><br/>
    
    &nbsp;&nbsp;
    Functional Area: {!Position__c.Functional_Area__c}<br/><br/>
    
    &nbsp;&nbsp;
    Job Level: {!Position__c.Job_Level__c}<br/><br/>
    
    &nbsp;&nbsp;
    Minimum Salary: {!Position__c.Min_Pay__c}
    Maximum Salary: {!Position__c.Max_Pay__c}
    
    <br/><br/><br/><br/><br/><br/>
    
    &nbsp;&nbsp;&nbsp;
    
    <apex:OutputLabel value="Please Click the appropriate button below to approve or reject the request."> 
    </apex:OutputLabel> <br/><br/>
    
    &nbsp;&nbsp;&nbsp;
           
    <apex:commandButton action="{!saveAndReject}" styleClass="buttonStyle" style="vertical-align:left;width:80px;height:20px;background:green;" value="Approve" />        
    
    <apex:commandButton action="{!saveAndReject}" styleClass="buttonStyle" style="vertical-align:left;width:80px;height:20px;background:red;" value="Reject" />
              
    <br/><br/> 
   
</apex:pageBlock>
</apex:form>
</apex:page>

 extension controller

public class JobApp {

public Id posId       {get;set;}
private final Position__c pos;
public JobApp(ApexPages.StandardController controller)

{

 posId = controller.getRecord().Id;  
 
}
public PageReference saveAndReject() {

PageReference requestPage = Page.AccountRecord;
requestPage.getParameters().put(posId, Position__c.Id);
requestPage.setRedirect(true);
return requestPage;

}

}

 The above class gives an error -

 

 Error: Compile Error: Incompatible value type Schema.SObjectField for MAP<String,String> at line 15 column 29

Does anyone have any code that takes a custom user lookup field and changes the owner of the record to match and vice versa (changing owner updates user lookup field)?

 

I have a use case where I need to force the user to identify the owner of the record during the creation of the record and not rely on their memory to change the owner after the fact.

Hello,

     I have VF page where it displays the related cases upon selecting the case owner on top , the case owner drop down appears on left hand side of screen now i want to add the todays date on the right hand side? is it possible to add the date ?

 

This is what i have for case owner drop down now how to add date to the below?

 

<apex:pageBlockSection >
 <apex:inputField id="own" value="{!case.Case_Owner__c}"  onChange="getSelectedId('{!$Component.own}');"/>
 </apex:pageBlockSection>

 

 

TIA!

Hi,

 

I can easily dragged the text area field. How can i restrict user from dragging or stretching textarea??

 

Cheers,

Devendra S

 

<script type="text/javascript">

   function enable()
   {
    if (document.getElementById("input").value.length > 0)
      document.getElementById("button").disabled = false;
    else
      document.getElementById("button").disabled = true;
   }
</script>


           <apex:inputField value="{!foo.bar__c}" id="input" onchange="enable()"/>

           <apex:commandButton action="{!save}" value="View" status="save" id="button" disabled="true"/>

 

That doesn't work at all. Any ideas? Seems like it should be super simple, so I may be missing something.

 

It seems like the val attribute of the pageblocktable tag only works with sobjects. I'm passing it a string array populated by an apex class, with 12 items, and no dice. The table won't populate.

 

Any suggestions?

 

Code looks like this:

                       <apex:pageBlockTable value="{!strings}" var="st">
                            <apex:column value="{!st}"/>
                       </apex:pageBlockTable>

I have a very simple Batch class and I am trying to write a unit test to cover it but the execute method in this batch class is never executing. I'm stumped.

 

Batch Class:

global class ideaCleanBatch implements Database.Batchable<sObject>{

global Database.QueryLocator start(Database.BatchableContext bc){
//We want to process all Ideas
return Database.getQueryLocator('select Id from Idea');
}

global void execute(Database.BatchableContext bc, List<sObject> objects){
Set<Id> ideaIds = new Set<Id>();
for(sObject s : objects){
Idea i = (Idea)s;
ideaIds.add(i.Id);
}
//Send ideas to ideaClean for processing
ideaClean.recalcNumbers(ideaIds);
}

global void finish(Database.BatchableContext bc){
system.debug('All done.');
}
}

Test Method:

static testMethod void ideaBatchTest(){
List<Idea> ideas = new List<Idea>();
Id communityId = [select Id from Community limit 1].Id;
for(Integer i = 0; i < 200; i++){
ideas.add(new Idea(Title = 'myIdea' + i, CommunityId = communityId));
}
insert ideas;

Test.startTest();
ideaCleanBatch job = new ideaCleanBatch();
ID batchprocessid = Database.executeBatch(job);
Test.stopTest();
}

Coverage:

 

Thanks,

Jason