• DaveGraupner
  • NEWBIE
  • 0 Points
  • Member since 2008

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

I have a validation rule as follows:

 

Account.RecordTypeName__c <> $RecordType.Name

 

From the debug log below we can see the values of the 2 fields are not the same (France and OEM1). So why does this validation rule pass? The formula is true so the validation rule should fail and display an error message.

 

13:47:4.552|EXECUTION_STARTED
13:47:4.552|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Contact:003S000000Ex9XU
13:47:4.552|VALIDATION_RULE|03d700000004K66|AccountEqualsContact
13:47:4.552|VALIDATION_FORMULA|Account.RecordTypeName__c <> $RecordType.Name|$RecordType.Name=France , Account.RecordTypeName__c=OEM1
13:47:4.552|VALIDATION_PASS

 

Account.RecordTypeName is a formula field set to $RecordType.Name.

 

I am very certain that this rule (which has been place for several months) was working and then  has stopped working. Same rule in both sandbox and production and same failure in both orgs. An interesting note is if I change the formula to be Account.RecordTypeName__c = $RecordType.Name then the validation rule always fails and displays the error message regardless of whether the fields are the same or different.

 

Can anyone explain this strange behavior?

 

Thanks

 

Dave

 

 

Is there any way to do a Count() query without hitting governor limits and without using batch apex when the number of records to be counted is greater than the governor limit?

 

 

Integer affected = [SELECT COUNT() FROM Account WHERE CustomField__c = 'TestValue'];

 This code runs in a trigger so will fail if there are more than 100 records in the count (assuming a batch size of 1).

 

 

Thanks

 

Dave

I am getting some strange results with test methods. I have a class that contains several test methods. If I run the test for that class only, some of my System.Assert statements fail. All the failures have to do with a custom picklist field. However if I take just one of the test methods and run it in its own class then the same statements that failed before now pass the System.Assert. I was under the impression that each test method in a class runs independently of all other test methods. My results don't seem to agree with this?

 

Upon further investigation the problem only happens when I set a custom picklist field to a value not in the picklist. The field is not a restricted picklist. I can see from the debug log that the value I have set in the field (Owner_Assigned__c = Hardware1) is present immediately before the validation rules fire (last line of the insert trigger is a system.debug statement). One of the validation rules references this field and the log shows that this has been set to another value (Owner_Assigned__c=12). This value of 12 is not a real value because in the code that follows the case insert in the test method the system.Assert that fails shows the value as null. Also if I create a validation rule to fire when the value of this field is 12 it never fails.

 

If I add the test value for this field that I am using to the picklist, all the tests run fine. Note that the test methods are never returning any DML or other exception errors. It is only the system.assert statements that are catching something.

 

Is there something I am doing incorrectly in my testing that would explain all of this?

 

Thanks

 

Dave

In a previous post Doug Chasman wrote:
 
... and sometimes you want to combine the 2 concepts, leverage the cool automagic apex:inputField picklist (or date picker is another common request) behavior when you don't have an Sobject. For that you just create a surrogate or proxy, in memory only, SObject instance that you can bind to - basically using the SObject purely as a data transfer object.
 
How do I create a surrogate in memory only Sobject? I've looked through the Apex and VF documentation but can't see anything realted to this. I would think I need to define an object with the relavent fields I want to use in the VF page but I don't see how to associate the object as a SObject or specify the various field attributes (like required).
 
Thanks
 
Dave
HI,
 
I have the following code as part of some javascript in an S-Control. The javascript is using version 12 of the API

function SearchAccounts() {
var sstr = "FIND {ABCDEF} IN NAME FIELDS RETURNING Account((Id, Name, OwnerId)";
var sr = sforce.connection.search(sstr);
alert(sr.className);
alert(sr.length);
return sr.GetArray("searchRecords");
}

There is an account existing with the name ABCDEF. Both alerts display undefined. I've checked the docs and the syntax is correct. The sforce.connection objects works as I have used it in other calls before this function executes.

What do I need to do to get search to return the results properly?

Thanks

Dave

I have a validation rule as follows:

 

Account.RecordTypeName__c <> $RecordType.Name

 

From the debug log below we can see the values of the 2 fields are not the same (France and OEM1). So why does this validation rule pass? The formula is true so the validation rule should fail and display an error message.

 

13:47:4.552|EXECUTION_STARTED
13:47:4.552|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Contact:003S000000Ex9XU
13:47:4.552|VALIDATION_RULE|03d700000004K66|AccountEqualsContact
13:47:4.552|VALIDATION_FORMULA|Account.RecordTypeName__c <> $RecordType.Name|$RecordType.Name=France , Account.RecordTypeName__c=OEM1
13:47:4.552|VALIDATION_PASS

 

Account.RecordTypeName is a formula field set to $RecordType.Name.

 

I am very certain that this rule (which has been place for several months) was working and then  has stopped working. Same rule in both sandbox and production and same failure in both orgs. An interesting note is if I change the formula to be Account.RecordTypeName__c = $RecordType.Name then the validation rule always fails and displays the error message regardless of whether the fields are the same or different.

 

Can anyone explain this strange behavior?

 

Thanks

 

Dave

 

 

Is there any way to do a Count() query without hitting governor limits and without using batch apex when the number of records to be counted is greater than the governor limit?

 

 

Integer affected = [SELECT COUNT() FROM Account WHERE CustomField__c = 'TestValue'];

 This code runs in a trigger so will fail if there are more than 100 records in the count (assuming a batch size of 1).

 

 

Thanks

 

Dave

I am getting some strange results with test methods. I have a class that contains several test methods. If I run the test for that class only, some of my System.Assert statements fail. All the failures have to do with a custom picklist field. However if I take just one of the test methods and run it in its own class then the same statements that failed before now pass the System.Assert. I was under the impression that each test method in a class runs independently of all other test methods. My results don't seem to agree with this?

 

Upon further investigation the problem only happens when I set a custom picklist field to a value not in the picklist. The field is not a restricted picklist. I can see from the debug log that the value I have set in the field (Owner_Assigned__c = Hardware1) is present immediately before the validation rules fire (last line of the insert trigger is a system.debug statement). One of the validation rules references this field and the log shows that this has been set to another value (Owner_Assigned__c=12). This value of 12 is not a real value because in the code that follows the case insert in the test method the system.Assert that fails shows the value as null. Also if I create a validation rule to fire when the value of this field is 12 it never fails.

 

If I add the test value for this field that I am using to the picklist, all the tests run fine. Note that the test methods are never returning any DML or other exception errors. It is only the system.assert statements that are catching something.

 

Is there something I am doing incorrectly in my testing that would explain all of this?

 

Thanks

 

Dave

I have a visual force page that was created in Summer 10 in my FCS to update cases.

 

The page allowed the user to change the case status and also create an entry into a customer object and create a case comment all from the same page.

 

It was working perfect in until today.  the only change was my Sandbox was updated to Spring 10.

 

Now whenever I try to update the case from the Visual Force Page I get the following error:

 

System.DmlException: Update failed. First exception on row 0 with id 50030000005o8ETAAY; first error: FIELD_INTEGRITY_EXCEPTION, No selected contact: [ContactId]

 

If I edit the case from GUI I do not get the error.  If I select a contact (Which is not a required field) and then execute the visual force page ot works fine.

 

What has chnaged in Spring 10 that is causing this to happen.

 

Any help is apprciated.

 

 

Here is the page:

 

 

<apex:page Controller="newEnhancemnetController" tabStyle="Case" id="thePage"> <script> function confirmCancel() { var isCancel = confirm("Are you sure you wish to cancel?"); if (isCancel) return true; return false; } </script> <apex:sectionHeader title="New Enhancemnet Approval" subtitle="for change board Case"/> <apex:form > <apex:pageBlock mode="edit"> <apex:pageMessages ></apex:pageMessages> <apex:pageBlockButtons > <apex:commandButton action="{!Save}" value="Save"/> <apex:commandButton action="{!Cancel}" value="Cancel" onclick="return confirmCancel()" immediate="true"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Change Current Case Status" columns="1"> <apex:outputField value="{!Case.id}"/> <apex:outputField value="{!Case.subject}"/> <apex:outputField value="{!Case.description}"/> <apex:pageBlockSectionItem > <apex:outputLabel value="{!$ObjectType.Case.fields.Status.label}" for="casestatus" style="font-weight:bold"/> <apex:outputPanel styleClass="requiredInput" layout="block"> <apex:outputPanel styleClass="requiredBlock" layout="block"/> <apex:selectList value="{!casestatus}" id="casestatus" size="1" title="Status" required="true"> <apex:selectOptions value="{!items}"/> </apex:selectList> </apex:outputPanel> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:pageBlockSection title="Add Enhancement Approval Information" columns="2"> <apex:inputField id="eaAprovedFor" value="{!EnhancementApproval.Approved_For__c}" required="true"/> <apex:inputField id="eaEnvironment" value="{!EnhancementApproval.Environment__c}" required="true"/> <apex:inputField id="eaValidFrom" value="{!EnhancementApproval.Valid_From__c}" required="true"/> <apex:inputField id="eaOtherQCS" value="{!EnhancementApproval.Other_QCS__c}" required="False"/> <apex:inputField id="eaValidTo" value="{!EnhancementApproval.Valid_To__c}" required="true"/> </apex:pageBlockSection> <apex:pageBlockSection title="Add a Case Comment"> <apex:inputField id="caseComment" value="{!CaseComment.CommentBody}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

 

 Here is the controller:

 

 

public class newEnhancemnetController { String casestatus; Case oCase; Enhancement_Approval__c oEnahncemnetApproval; Contact contact; CaseComment casecomment; Map<String,String> mCaseStatus = new Map<String,String>(); public Case getCase() { oCase = [select id, subject, status, description from Case where id = :ApexPages.currentPage().getParameters().get('id')]; if(oCase== null) oCase= new Case(); return oCase; } public Contact getContact() { if(contact== null) contact= new Contact(); return contact; } public String getCaseStatus() { if(casestatus==null){casestatus=oCase.Status;} return casestatus ; } public void setCaseStatus(String casestatus ) { this.casestatus = casestatus ; } public List<SelectOption> getItems() { mCaseStatus.Put('New','New'); mCaseStatus.Put('Approved for Analysis & Design','Approved for Analysis & Design'); mCaseStatus.Put('Reqmts/A&D In Progress','Reqmts/A&D In Progress'); mCaseStatus.Put('Reqmts/A&D Completed','Reqmts/A&D Completed'); mCaseStatus.Put('Approved for Sandbox Build/Config/Test','Approved for Sandbox Build/Config/Test'); mCaseStatus.Put('Sandbox Build In Progress','Sandbox Build In Progress'); mCaseStatus.Put('Sandbox Testing Failed','Sandbox Testing Failed'); mCaseStatus.Put('Sandbox Testing Passed','Sandbox Testing Passed'); mCaseStatus.Put('Waiting for Production Release Date','Waiting for Production Release Date'); mCaseStatus.Put('Release Date Assigned/Approved for Prod','Release Date Assigned/Approved for Prod'); mCaseStatus.Put('Production Testing Failed','Production Testing Failed'); mCaseStatus.Put('Production Testing Passed','Production Testing Passed'); mCaseStatus.Put('On Hold / No Activity','On Hold / No Activity'); mCaseStatus.Put('On Hold / Lack of Funding','On Hold / Lack of Funding'); //mCaseStatus.Put('',''); List<SelectOption> options = new List<SelectOption>(); Schema.DescribeFieldResult fieldResult = Schema.sObjectType.Case.Fields.Status; fieldResult = fieldResult.getSObjectField().getDescribe(); List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues(); for( Schema.PicklistEntry f : ple) { if (mCaseStatus.containskey(f.getValue())) options.add(new SelectOption(f.getLabel(), f.getValue())); //options.add(new SelectOption(f.getLabel(), f.getValue())); } return options; } //public List<SelectOption> getItems() { // List<SelectOption> options = new List<SelectOption>(); // for (CaseStatus cs : [Select MasterLabel from CaseStatus order by sortorder]){ // options.add(new SelectOption(cs.MasterLabel,cs.MasterLabel)); // } // return options; //} public CaseComment getCaseComment () { if(casecomment== null) casecomment= new CaseComment(); return casecomment; } public Enhancement_Approval__c getEnhancementApproval() { if(oEnahncemnetApproval== null) oEnahncemnetApproval= new Enhancement_Approval__c(); return oEnahncemnetApproval; } public PageReference cancel() { PageReference casePage = new ApexPages.StandardController(oCase).view(); casePage .setRedirect(true); return casePage ; } public PageReference Save() { if (oEnahncemnetApproval.Environment__c == 'QCS - Other' && oEnahncemnetApproval.Other_QCS__c ==Null ){ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Other QCS is Required when Environment is equal to "QCS - Other"'); ApexPages.addMessage(myMsg); return null; } oCase.Status=this.casestatus; update oCase; Enhancement_Approval__c oEA; oEA = new Enhancement_Approval__c(); oEA.Approved_For__c = oEnahncemnetApproval.Approved_For__c; oEA.Case__c = ApexPages.currentPage().getParameters().get('id'); oEA.Environment__c = oEnahncemnetApproval.Environment__c; oEA.Valid_From__c = oEnahncemnetApproval.Valid_From__c; oEA.Valid_To__c = oEnahncemnetApproval.Valid_To__c; oEA.Other_QCS__c = oEnahncemnetApproval.Other_QCS__c; insert oEA; if (casecomment.CommentBody != null){ casecomment.ParentId = ApexPages.currentPage().getParameters().get('id'); insert casecomment; } PageReference casePage = new ApexPages.StandardController(oCase).view(); casePage.setRedirect(true); return casePage ; } //*************************************************************************** //** Test Method //** //*************************************************************************** public static testMethod void testChangeBoardApproval() { pageReference p = Page.ChangeBoardApproval; p.getParameters().put('id', [select id from Case limit 1].id); test.setCurrentPage(p); newEnhancemnetController enhancmenetController = new newEnhancemnetController(); //enhancemnetController.cancel(); enhancmenetController.getCase(); enhancmenetController.getitems(); enhancmenetController.getcasestatus(); enhancmenetController.getEnhancementApproval(); enhancmenetController.getContact(); enhancmenetController.getCaseComment(); enhancmenetController.save(); } }

 

 

 

 

 

  • January 25, 2010
  • Like
  • 0
HI,
 
I have the following code as part of some javascript in an S-Control. The javascript is using version 12 of the API

function SearchAccounts() {
var sstr = "FIND {ABCDEF} IN NAME FIELDS RETURNING Account((Id, Name, OwnerId)";
var sr = sforce.connection.search(sstr);
alert(sr.className);
alert(sr.length);
return sr.GetArray("searchRecords");
}

There is an account existing with the name ABCDEF. Both alerts display undefined. I've checked the docs and the syntax is correct. The sforce.connection objects works as I have used it in other calls before this function executes.

What do I need to do to get search to return the results properly?

Thanks

Dave