• Michael Bos 3
  • NEWBIE
  • 10 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
Hello developers,

I need to extend a validation rule on a temporary address with validation check on zipcode and street + housenumber. 

The existing validation rule:

AND( Is_Temporary_Address__c = TRUE, 
     OR( 
     ISBLANK( Temporary_OrderStreet__c ), 
     ISBLANK( Temporary_OrderCity__c ),
     ISBLANK( Temporary_OrderZip__c ),
     ISBLANK( Temporary_OrderCountry__c ) 
     ) 
)

(fields cannot be empty. rather simple check)

The Zipcode validation check:

AND( 
OR( Temporary_OrderCountry__c = "Nederland", Temporary_OrderCountry__c = "Netherlands", Temporary_OrderCountry__c = "NL"),
OR (ISBLANK( Temporary_OrderZip__c), 
NOT(REGEX(Temporary_OrderZip__c , "^([0-9]{4}[\\s]{1}[a-z|A-Z]{2})?$|^[0-9]{4}[a-z|A-Z]{2}+$")
 ) ))
  • Checks the country, and if the zipcode is written as 1234AB or 1234 AB and contains four numbers and 2 letters.
  • This one is not in use.

The Street + Housenumber validation:

This is where it gets tricky.
This is a combined field for street and housenumber.
Some adresses start with a number, but also have a housenumber.
Housenumbers can be just a number (1,25,650,1110) or have a extension (A, 2 hoog).
Should I split these fields?
If so, how?

My questions are:
- How do I combine everything in one validation?
- Is this even possible or desirable?
- How to split fields if this is more desirable?

Thanks for reading and I'm really looking forward for answers from validation wizards :-)
Hi,

Trying to deply a small change set from UAT to Production.
Controller "MyProfilePageControllerTest" works fine in UAT, but gives error in Production.
This controller is not affected in the Change Set. 

What is going on in this controller?
What can I change to pass the validation?

Error:
  • Class Name - MyProfilePageControllerTest
  • Method Name - testSave
  • Error message - System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATES_DETECTED, Use one of these records?: []
    Stack Trace: Class.MyProfilePageControllerTest.testSave: line 40, column 1

Code:

/**
 * An apex class that keeps updates of a portal user in sync with its corresponding contact.
   Guest users are never able to access this page.
 */
@IsTest public with sharing class MyProfilePageControllerTest {
    @IsTest(SeeAllData=true) static void testSetContactFields() {
        User u = [select title, firstname, lastname, email, phone, mobilephone, fax, street, city, state, postalcode, country
                           FROM User WHERE id =: UserInfo.getUserId()];

        Contact c = new Contact();

        MyProfilePageController.setContactFields(c, u);
        System.assertEquals(c.firstname, u.firstname, 'firstname should have been set as the firstname of the user for the contact');
        System.assertEquals(c.lastname, u.lastname, 'lastname should have been set as the lastname of the user for the contact');
    }

    @IsTest(SeeAllData=true) static void testSave() {
        // Modify the test to query for a portal user that exists in your org
        List<User> existingPortalUsers = [SELECT id, profileId, userRoleId FROM User WHERE UserRoleId <> null AND UserType='CustomerSuccess'];

        if (existingPortalUsers.isEmpty()) {
            User currentUser = [select id, title, firstname, lastname, email, phone, mobilephone, fax, street, city, state, postalcode, country
                                FROM User WHERE id =: UserInfo.getUserId()];
            MyProfilePageController controller = new MyProfilePageController();
            System.assertEquals(currentUser.Id, controller.getUser().Id, 'Did not successfully load the current user');
            System.assert(controller.getIsEdit() == false, 'isEdit should default to false');
            controller.edit();
            System.assert(controller.getIsEdit() == true);
            controller.cancel();
            System.assert(controller.getIsEdit() == false);

            Contact c = new Contact();
            MyProfilePageController.setContactFields(c, currentUser);
            c.LastName = 'TestContact';
            // START Company specific values...
            c.Company_Code__c = 'AAA';
            String rand = '00000000' + String.valueOf(Math.round(Math.random()*100000000));
            c.Personnel_Number__c = rand.subString(rand.length() - 8, rand.length());
            // END Company specific values...
            insert c;

            c.title = currentUser.title;
            c.firstname = currentUser.firstname;
            c.lastname = currentUser.lastname;
            c.email = currentUser.email;
            c.phone = currentUser.phone;
            c.mobilephone = currentUser.mobilephone;
            c.fax = currentUser.fax;
            c.mailingstreet = currentUser.street;
            c.mailingcity = currentUser.city;
            c.mailingstate = currentUser.state;
            c.mailingpostalcode = currentUser.postalcode;
            c.mailingcountry = currentUser.country;
            controller.save();
            System.assert(Page.ChangePassword.getUrl().equals(controller.changePassword().getUrl()));
            
        } else {
            User existingPortalUser = existingPortalUsers[0];
            String randFax = Math.rint(Math.random() * 1000) + '5551234';

            System.runAs(existingPortalUser) {
                MyProfilePageController controller = new MyProfilePageController();
                System.assertEquals(existingPortalUser.Id, controller.getUser().Id, 'Did not successfully load the current user');
                System.assert(controller.getIsEdit() == false, 'isEdit should default to false');
                controller.edit();
                System.assert(controller.getIsEdit() == true);

                controller.cancel();
                System.assert(controller.getIsEdit() == false);

                controller.getUser().Fax = randFax;
                controller.save();
                System.assert(controller.getIsEdit() == false);
            }

            // verify that the user and contact were updated
            existingPortalUser = [Select id, fax, Contact.Fax from User where id =: existingPortalUser.Id];
            System.assert(existingPortalUser.fax == randFax);
            System.assert(existingPortalUser.Contact.fax == randFax);
        }
    }
}
Hello developers,

I need to extend a validation rule on a temporary address with validation check on zipcode and street + housenumber. 

The existing validation rule:

AND( Is_Temporary_Address__c = TRUE, 
     OR( 
     ISBLANK( Temporary_OrderStreet__c ), 
     ISBLANK( Temporary_OrderCity__c ),
     ISBLANK( Temporary_OrderZip__c ),
     ISBLANK( Temporary_OrderCountry__c ) 
     ) 
)

(fields cannot be empty. rather simple check)

The Zipcode validation check:

AND( 
OR( Temporary_OrderCountry__c = "Nederland", Temporary_OrderCountry__c = "Netherlands", Temporary_OrderCountry__c = "NL"),
OR (ISBLANK( Temporary_OrderZip__c), 
NOT(REGEX(Temporary_OrderZip__c , "^([0-9]{4}[\\s]{1}[a-z|A-Z]{2})?$|^[0-9]{4}[a-z|A-Z]{2}+$")
 ) ))
  • Checks the country, and if the zipcode is written as 1234AB or 1234 AB and contains four numbers and 2 letters.
  • This one is not in use.

The Street + Housenumber validation:

This is where it gets tricky.
This is a combined field for street and housenumber.
Some adresses start with a number, but also have a housenumber.
Housenumbers can be just a number (1,25,650,1110) or have a extension (A, 2 hoog).
Should I split these fields?
If so, how?

My questions are:
- How do I combine everything in one validation?
- Is this even possible or desirable?
- How to split fields if this is more desirable?

Thanks for reading and I'm really looking forward for answers from validation wizards :-)
Hi,

Trying to deply a small change set from UAT to Production.
Controller "MyProfilePageControllerTest" works fine in UAT, but gives error in Production.
This controller is not affected in the Change Set. 

What is going on in this controller?
What can I change to pass the validation?

Error:
  • Class Name - MyProfilePageControllerTest
  • Method Name - testSave
  • Error message - System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATES_DETECTED, Use one of these records?: []
    Stack Trace: Class.MyProfilePageControllerTest.testSave: line 40, column 1

Code:

/**
 * An apex class that keeps updates of a portal user in sync with its corresponding contact.
   Guest users are never able to access this page.
 */
@IsTest public with sharing class MyProfilePageControllerTest {
    @IsTest(SeeAllData=true) static void testSetContactFields() {
        User u = [select title, firstname, lastname, email, phone, mobilephone, fax, street, city, state, postalcode, country
                           FROM User WHERE id =: UserInfo.getUserId()];

        Contact c = new Contact();

        MyProfilePageController.setContactFields(c, u);
        System.assertEquals(c.firstname, u.firstname, 'firstname should have been set as the firstname of the user for the contact');
        System.assertEquals(c.lastname, u.lastname, 'lastname should have been set as the lastname of the user for the contact');
    }

    @IsTest(SeeAllData=true) static void testSave() {
        // Modify the test to query for a portal user that exists in your org
        List<User> existingPortalUsers = [SELECT id, profileId, userRoleId FROM User WHERE UserRoleId <> null AND UserType='CustomerSuccess'];

        if (existingPortalUsers.isEmpty()) {
            User currentUser = [select id, title, firstname, lastname, email, phone, mobilephone, fax, street, city, state, postalcode, country
                                FROM User WHERE id =: UserInfo.getUserId()];
            MyProfilePageController controller = new MyProfilePageController();
            System.assertEquals(currentUser.Id, controller.getUser().Id, 'Did not successfully load the current user');
            System.assert(controller.getIsEdit() == false, 'isEdit should default to false');
            controller.edit();
            System.assert(controller.getIsEdit() == true);
            controller.cancel();
            System.assert(controller.getIsEdit() == false);

            Contact c = new Contact();
            MyProfilePageController.setContactFields(c, currentUser);
            c.LastName = 'TestContact';
            // START Company specific values...
            c.Company_Code__c = 'AAA';
            String rand = '00000000' + String.valueOf(Math.round(Math.random()*100000000));
            c.Personnel_Number__c = rand.subString(rand.length() - 8, rand.length());
            // END Company specific values...
            insert c;

            c.title = currentUser.title;
            c.firstname = currentUser.firstname;
            c.lastname = currentUser.lastname;
            c.email = currentUser.email;
            c.phone = currentUser.phone;
            c.mobilephone = currentUser.mobilephone;
            c.fax = currentUser.fax;
            c.mailingstreet = currentUser.street;
            c.mailingcity = currentUser.city;
            c.mailingstate = currentUser.state;
            c.mailingpostalcode = currentUser.postalcode;
            c.mailingcountry = currentUser.country;
            controller.save();
            System.assert(Page.ChangePassword.getUrl().equals(controller.changePassword().getUrl()));
            
        } else {
            User existingPortalUser = existingPortalUsers[0];
            String randFax = Math.rint(Math.random() * 1000) + '5551234';

            System.runAs(existingPortalUser) {
                MyProfilePageController controller = new MyProfilePageController();
                System.assertEquals(existingPortalUser.Id, controller.getUser().Id, 'Did not successfully load the current user');
                System.assert(controller.getIsEdit() == false, 'isEdit should default to false');
                controller.edit();
                System.assert(controller.getIsEdit() == true);

                controller.cancel();
                System.assert(controller.getIsEdit() == false);

                controller.getUser().Fax = randFax;
                controller.save();
                System.assert(controller.getIsEdit() == false);
            }

            // verify that the user and contact were updated
            existingPortalUser = [Select id, fax, Contact.Fax from User where id =: existingPortalUser.Id];
            System.assert(existingPortalUser.fax == randFax);
            System.assert(existingPortalUser.Contact.fax == randFax);
        }
    }
}

Hi,

 

I would like to know how can I show a custom label value into a message displayed by an onclick event in a Command Link button.

 

In example

<apex:commandLink value="{!$Label.MyLabel1}" onclick="return confirm('Are you sure?')" action="{!removeItem}">
   <apex:param name="removeItemId" value="{!item.objId}" assignTo="{!selectedItemId}" />
</apex:commandLink>

 

I would like to replace the hard coded 'Are you sure?' message by a custom Label value, but everytime I try, the related button doesn't  work properly. Any kind of suggestion?

 

Regards,

 

Wilmer

 

 

  • February 22, 2013
  • Like
  • 0