• tendonstrength
  • NEWBIE
  • 50 Points
  • Member since 2009

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies
Page 39 of Force.com_workbook v2. provides code for testing the class created in Tutorial 5.

No surprisingly, this test code itself is wrong, and running it fails.

How do I correct the code so that these two asserts will work correctly?

System.assert(e.getMessage().contains('Insert failed. First exception on row 0; '+
'first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, '+
'Mileage request exceeds daily limit(500): [Miles__c]'),
e.getMessage());

System.assertEquals(Mileage__c.Miles__c, e.getDmlFields(0)[0]);

I've already discovered that I can get the first assertion to work correctly if change "...daily limit(500): [Miles__c]')," to "daily limit: 500: []')," ... but I imagine that "Miles__c" should have some value that isn't being added in MileageUtil, but should?

And the second assertion, I have no idea how to fix....

-Brian.

Hello,

 

I have a visualforce page with a selectlist and I'm trying to get the user's selection to bind with a variable in the controller. When values are entered in the input fields of the page, they bind to the variables in the controller just fine, but selecting something in the list seems to have no effect on the variable that (I think) I have associated with it.

 

   Here is the code for the VF page:

 

 

<apex:page controller="ItemWizardController" tabStyle="Opportunity" >
<apex:pageMessages />

<apex:form >


<apex:pageBlock >

<apex:pageBlockSection columns="2" id="mainBlock">

<apex:pageBlockSectionItem >
<apex:outputLabel value="* Pick a Supplier: " for="supplierName"/>
<apex:inputField id="supplierName" value="{!newItem.Account__c}"/>
</apex:pageBlockSectionItem><br></br>

<!-- This is the list. I'm expecting the selection to bind with the variable itemType in the controller-->
<apex:pageBlockSectionItem id="itemtypelist">
<apex:outputLabel value="* Item Type: " for="itemType"/>
<apex:selectList id="itemType" size="1" value="{!itemType}">
<apex:selectOptions value="{!itemTypes}"/>
</apex:selectList>
</apex:pageBlockSectionItem><br></br>

<apex:pageBlockSectionItem >
<apex:outputLabel value="Logo Name: " for="logoName"/>
<apex:inputField id="logoName" value="{!newItem.Logo_Name__c}"/>
</apex:pageBlockSectionItem><br></br>

<apex:pageBlockSectionItem >
<apex:outputLabel value="Logo Placement: " for="logoPlacement"/>
<apex:inputField id="logoPlacement" value="{!newItem.Logo_Placement__c}"/>
</apex:pageBlockSectionItem>

</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!quit}" value="Cancel" styleClass="btn"/>
<apex:commandButton action="{!goToPage2}" value="Next" styleClass="btn"/>
</apex:pageBlockButtons><br></br>
</apex:pageBlock>

</apex:form>

</apex:page>

 And here is the code for the controller:

 

 

public class ItemWizardController {
	
	
	private Item_WIP_MWA__c newItem;
	private String itemType;
	private List<SelectOption> itemTypes;
	private String oppId;

	
    public ItemWizardController() {
    	Item_WIP_MWA__c item = new Item_WIP_MWA__c();
		this.newItem = item;
		this.oppId = ApexPages.currentPage().getParameters().get('oppId');
    }        

	
	public Item_WIP_MWA__c getNewItem(){
		return this.newItem;
	}
	

	public String getItemType(){
		return this.itemType;
	}
	
	public void setItemType(String itemType){
		this.itemType = itemType;
	}

    public List<SelectOption> getItemTypes(){
    	List<SelectOption> optionList = new List<SelectOption>();
    	optionList.add(new SelectOption('', '-None-'));
    	optionList.add(new SelectOption('', 'Apparel'));
    	optionList.add(new SelectOption('', 'Other'));
    	return optionList;
    }

	public String getOppId(){
		return this.oppId;
	}
	
	public void setOppId(String oppId){
		this.oppId = oppId;
	}
	
	
    public PageReference quit(){
    	PageReference oppPage = new PageReference('/' + oppId);
    	return oppPage;
    }
    
    public PageReference goToPage2(){  	 	
    	return Page.itemStep2;		
    }  
   
    

}

 

 

One thing to keep in mind is that the value in the select list doesn't bind to a field in an SObject. This is going to be a wizard interface of sorts and the value there is just used so that the controller knows what page it needs to go to next.

 

Thanks in advance.

 

Hello,

 

I have a visualforce page with a selectlist and I'm trying to get the user's selection to bind with a variable in the controller. When values are entered in the input fields of the page, they bind to the variables in the controller just fine, but selecting something in the list seems to have no effect on the variable that (I think) I have associated with it.

 

   Here is the code for the VF page:

 

 

<apex:page controller="ItemWizardController" tabStyle="Opportunity" >
<apex:pageMessages />

<apex:form >


<apex:pageBlock >

<apex:pageBlockSection columns="2" id="mainBlock">

<apex:pageBlockSectionItem >
<apex:outputLabel value="* Pick a Supplier: " for="supplierName"/>
<apex:inputField id="supplierName" value="{!newItem.Account__c}"/>
</apex:pageBlockSectionItem><br></br>

<!-- This is the list. I'm expecting the selection to bind with the variable itemType in the controller-->
<apex:pageBlockSectionItem id="itemtypelist">
<apex:outputLabel value="* Item Type: " for="itemType"/>
<apex:selectList id="itemType" size="1" value="{!itemType}">
<apex:selectOptions value="{!itemTypes}"/>
</apex:selectList>
</apex:pageBlockSectionItem><br></br>

<apex:pageBlockSectionItem >
<apex:outputLabel value="Logo Name: " for="logoName"/>
<apex:inputField id="logoName" value="{!newItem.Logo_Name__c}"/>
</apex:pageBlockSectionItem><br></br>

<apex:pageBlockSectionItem >
<apex:outputLabel value="Logo Placement: " for="logoPlacement"/>
<apex:inputField id="logoPlacement" value="{!newItem.Logo_Placement__c}"/>
</apex:pageBlockSectionItem>

</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!quit}" value="Cancel" styleClass="btn"/>
<apex:commandButton action="{!goToPage2}" value="Next" styleClass="btn"/>
</apex:pageBlockButtons><br></br>
</apex:pageBlock>

</apex:form>

</apex:page>

 And here is the code for the controller:

 

 

public class ItemWizardController {
	
	
	private Item_WIP_MWA__c newItem;
	private String itemType;
	private List<SelectOption> itemTypes;
	private String oppId;

	
    public ItemWizardController() {
    	Item_WIP_MWA__c item = new Item_WIP_MWA__c();
		this.newItem = item;
		this.oppId = ApexPages.currentPage().getParameters().get('oppId');
    }        

	
	public Item_WIP_MWA__c getNewItem(){
		return this.newItem;
	}
	

	public String getItemType(){
		return this.itemType;
	}
	
	public void setItemType(String itemType){
		this.itemType = itemType;
	}

    public List<SelectOption> getItemTypes(){
    	List<SelectOption> optionList = new List<SelectOption>();
    	optionList.add(new SelectOption('', '-None-'));
    	optionList.add(new SelectOption('', 'Apparel'));
    	optionList.add(new SelectOption('', 'Other'));
    	return optionList;
    }

	public String getOppId(){
		return this.oppId;
	}
	
	public void setOppId(String oppId){
		this.oppId = oppId;
	}
	
	
    public PageReference quit(){
    	PageReference oppPage = new PageReference('/' + oppId);
    	return oppPage;
    }
    
    public PageReference goToPage2(){  	 	
    	return Page.itemStep2;		
    }  
   
    

}

 

 

One thing to keep in mind is that the value in the select list doesn't bind to a field in an SObject. This is going to be a wizard interface of sorts and the value there is just used so that the controller knows what page it needs to go to next.

 

Thanks in advance.

 

Page 39 of Force.com_workbook v2. provides code for testing the class created in Tutorial 5.

No surprisingly, this test code itself is wrong, and running it fails.

How do I correct the code so that these two asserts will work correctly?

System.assert(e.getMessage().contains('Insert failed. First exception on row 0; '+
'first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, '+
'Mileage request exceeds daily limit(500): [Miles__c]'),
e.getMessage());

System.assertEquals(Mileage__c.Miles__c, e.getDmlFields(0)[0]);

I've already discovered that I can get the first assertion to work correctly if change "...daily limit(500): [Miles__c]')," to "daily limit: 500: []')," ... but I imagine that "Miles__c" should have some value that isn't being added in MileageUtil, but should?

And the second assertion, I have no idea how to fix....

-Brian.

It feels that this should be something very basic, but I simply cannot get it to work.

 

 

 

vf code:

 

<apex:page Controller="IndividualAccreditationFormController" >

  <apex:form >

              <apex:selectList value="{!value}" size="1">
                <apex:selectOptions value="{!USPersonAnswers}" />
              </apex:selectList>      
              <apex:commandButton value="Ugh this blows" action="{!signAndRegister}"></apex:commandButton>   
         </apex:form>
   
</apex:page>

 

 

in the controller, I have a very simple:

 

    public String value {get;set;}

 

and the method signAndRegister() simply tries to use the value string and assign it to an object's custom field:

 

public void signAndRegister() {

 System.debug('Before sign and register: '+value);
        
        if (this.value==null) {
            this.value = 'was null';
        }
        
            form.USPersonText__c = this.value;
                   insert form;
           }

 

Anyway, value is never getting set. Any ideas would be much appreciated.

 

David

Hello everybody,

I'm trying to set a record's field to blank using the function sforce.connection.update().
Here is my code:

Code:
newObject = new sforce.SObject("DocumentLink");
newObject.set("Id", linkedDocs[i]["Id"]);
newObject.set("Bookmark__c", bookmark);

// update Document Link object var result = sforce.connection.update([newObject]); for (var k=0; i<result.length ;k++ ){ if (result[k].getBoolean("success")){ } else { alert("Failed to store the bookmark changes! \n"+result[k]); } }

That works absolutly fine as long as bookmark is not empty.
But I want to be able to set the Bookmark__c field to be blank as well. How can a do that?
I tryed something link: bookmark=null and bookmark="". But non of them worked.

Seems like the method simply ignors the field if it is set to null or "".
Has anybody an idea??

Thanks,
Matthias