• dwright01
  • NEWBIE
  • 5 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 8
    Replies
I set up a duplicate record rule that says Allow duplicate records.  I have a custom controller extension that calls the Standard Controller as follows when the user hits the Save button:
PageReference pRef = baseController.save();
return pRef;
The pRef is "null" when the record I'm trying to save is a duplicate, according to my rule.  When the page is displayed the error says "Error: There is already a contact in this account with the same email. But you may create this new one anyway."  (This is my text for the duplicate alert message).

But every time baseController.save() gets called it returns this error.  How can I implement the functionality that the second time you click Save it will create the new record anyway?
I wrote some apex and would like to write a test for it, but am stumped as to how to do it!

The code to be tested is an apex "after update" trigger that schedules some apex code to run in 2 seconds, and this code in turn starts a batch job.  The job runs execute() and finish(), and I want my test code to verify that the execute() and finish() did the right the right things.

The test code is like this:
<create records>
Test.startTest();
update acct;
Test.stopTest();
<asserts that the execute and finish code did the right things>

But, through use of logging, I see that the scheduled apex code ran fine, and started the batch job, but the execute() and finish() code happens after my asserts and the test routine finishes!   This is not at all what I expected would happen from reading the documentation.  It is good (for coverage) that the code runs, but m test is not able to assert that the code worked.

I cannot figure out how to write the test to verify that the actions the trigger did, including running the batch job, worked correctly. 

The only thing I can think of is to write a separate test simulating the scheduled apex code itself.

Anyone else have any ideas?

Thanks, Dave

Does anyone know a way for my Apex code to determine the difference in being logged in as a standard Salesforce user, versus an Admin user that logged in and in their admin session logged in as that user?

 

Thanks,

David Wright, Gerson Lehrman Group

 

My Salesforce profile called 'Sales'  has no CRUD access to a custom object called Global_Opportunity__c.  But when I run the following test code:

 

@isTest
2 private class TestGlobalOpportunityTrigger {

3     static testMethod void salesPersonCantCreateGlobalOpportunity() {

4         User salesUser = [SELECT id FROM User where Profile.Name = 'Sales' AND IsActive=true LIMIT 1];

5         Global_Opportunity__c go = new Global_Opportunity__c(Amount__c = 120000);
6         try {
7           System.runAs(salesUser) {
8           insert go;
9           System.assert(false, 'Sales user was unexpectedly able to create Global_Opportunity id=' + go.Id);

10       }
11    }
12   catch(DmlException excep) {
13       System.debug('got expected excep: ' + excep.getMessage());
14    }

15  }

16 }

 

Instead of failing the insert as expected and exeecuting line 13, the system executes line 9.

I tried setting the sharing mode to Public Read-only access but this did not solve the problem.

Any ideas?

 

Thanks,

David Wright

 

The following works:

<apex:column headerValue="Opportunity Id">{!CASESAFEID(op.Id)}</apex:column>

 

But if I replace the above with the one-liner below, where I specify the value in the value= field of the apex:column, it fails to save with the error:

Syntax error: Missing ')'


<apex:column headerValue="Opportunity Id" value="{!CASESAFEID(op.Id)}" />

 

That seems wierd, there is no missing or mismatched paren there.  I cannot seem to modify the line to get it to save.  I can also reproduce the error with other formula expressions, it is not specific to CASESAFEID.   Is this a bug?


I'm in a sandbox and trying to create a Detail Page Button on the Account page that opens my new VisualForce page.  I've created the page in Developer Mode by navigating to "/apex/newpagename" and clicking "Create the page".  It is the default page created by doing this  ("Congratulations  This is your new Page: newpagename").  

 

Then I went to Customize / Accounts / Buttons and Links and clicked the New button to create a new Custom button, and selected Content source = VisualSource page.  According to the instructions in the VisualForce workbook I should then be able to choose my page in the "Content" dropdown.  But, the dropdown is empty.

 

What am I missing?

 

Thanks, Dave

I've tried to use the migration tool to copy metadata from one sandbox to another, but I'm getting an error:

"No more than 10 columns may be specified in searchResultsFields" when it tries to deploy a custom object.

 

I have exactly 10 fields in <customTabListAdditionalFields> and 10 in <<searchResultsAdditionalFields>.

When I deleted one of each I get past the error.

 

Why is there a limit of 10 columns when migrating?  Can I get around the limit?

 

Thanks,

Dave

 

 

I have a developer sandbox where I've created a custom tab, and want to deploy it to a corporate sandbox that includes all our production customizations. I tried doing this using the ANT-based migration tool. The custom tab is defined there after the deployment, but it is not showing up on the "All tabs" menu and I also want it to appear in all applications in the target sandbox as it does in the source sandbox, but I can't figure out how to do that. Is there a way for the deployment itself to cause this to happen?

Thanks, David Wright, Gerson Lehrman Group

I wrote some apex and would like to write a test for it, but am stumped as to how to do it!

The code to be tested is an apex "after update" trigger that schedules some apex code to run in 2 seconds, and this code in turn starts a batch job.  The job runs execute() and finish(), and I want my test code to verify that the execute() and finish() did the right the right things.

The test code is like this:
<create records>
Test.startTest();
update acct;
Test.stopTest();
<asserts that the execute and finish code did the right things>

But, through use of logging, I see that the scheduled apex code ran fine, and started the batch job, but the execute() and finish() code happens after my asserts and the test routine finishes!   This is not at all what I expected would happen from reading the documentation.  It is good (for coverage) that the code runs, but m test is not able to assert that the code worked.

I cannot figure out how to write the test to verify that the actions the trigger did, including running the batch job, worked correctly. 

The only thing I can think of is to write a separate test simulating the scheduled apex code itself.

Anyone else have any ideas?

Thanks, Dave

The following works:

<apex:column headerValue="Opportunity Id">{!CASESAFEID(op.Id)}</apex:column>

 

But if I replace the above with the one-liner below, where I specify the value in the value= field of the apex:column, it fails to save with the error:

Syntax error: Missing ')'


<apex:column headerValue="Opportunity Id" value="{!CASESAFEID(op.Id)}" />

 

That seems wierd, there is no missing or mismatched paren there.  I cannot seem to modify the line to get it to save.  I can also reproduce the error with other formula expressions, it is not specific to CASESAFEID.   Is this a bug?


I'm in a sandbox and trying to create a Detail Page Button on the Account page that opens my new VisualForce page.  I've created the page in Developer Mode by navigating to "/apex/newpagename" and clicking "Create the page".  It is the default page created by doing this  ("Congratulations  This is your new Page: newpagename").  

 

Then I went to Customize / Accounts / Buttons and Links and clicked the New button to create a new Custom button, and selected Content source = VisualSource page.  According to the instructions in the VisualForce workbook I should then be able to choose my page in the "Content" dropdown.  But, the dropdown is empty.

 

What am I missing?

 

Thanks, Dave