• Anton | De Ondernemer
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 3
    Replies
Scenario:
I want to work with custom made UUID's instead of the default case sensitive Id's.
The Contact object for example has a field: UUID__c which contains a 36 char long unique, case-insensitive text string, set as External ID.

I'm able to get data in REST by using a GET request to /sobjects/Contact/UUID__c/af0407b7-eb9f-22f2-1648-fe66ccb4a516 (for example).
See also: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/using_resources_retrieve_with_externalid.htm

Now I want to use the same technique on Visualforce pages using controllers.
According to documentation the default route is to put the record id in the URL.
/apex/myPage?id=001x000xxx3Jsxb (for example)
See also: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_std_actions.htm

My challenge:
I want to be able to use the External ID too.
somehow /apex/myPage?UUID__c=af0407b7-eb9f-22f2-1648-fe66ccb4a516 (for example) doesn't seem to work.

- Do I need to switch some settings in order to be able to use it?
- Do I need to create an extension to the standard Contact controller in order to catch the External ID?
- Do I need to write a custom controller and lose the standard controller actions (and write everything from the ground up)?


 
So I want to write better test classes and started doing the trailhead. I've just completed the following trailhead step:
https://trailhead.salesforce.com/trails/force_com_dev_beginner/modules/apex_testing/units/apex_testing_triggers

Somehow I successfully completed the step with the testclass below.
Both "block"-methods keep failing when running all tests. It fails because of the error thrown, but isnt that exactly what I'm testing for so the tests should pass? (I expect an error and I got it).

TLDR: 
is a failed test "good" when testing errors or should I write my test methods differently so it passes?
@isTest
private class TestRestrictContactByName {

    @isTest static void allowContactInsert() {
        Contact contact = new Contact(LastName='LastName');
                
        Test.startTest();
        Database.UpsertResult result = Database.upsert(contact);
        Test.stopTest();
        
        System.assert(result.isSuccess());
    }
    
    @isTest static void blockContactInsert() {
        Contact contact = new Contact(LastName='INVALIDNAME');
        
        Test.startTest();
        Database.UpsertResult result = Database.upsert(contact);
        Test.stopTest();
        
        System.assert(!result.isSuccess());
        System.assert(result.getErrors().size() > 0);
        System.assertEquals('The Last Name '+contact.LastName+' is not allowed for DML',
                             result.getErrors()[0].getMessage());
     }
    
    @isTest static void allowContactUpdate() {
        Contact contact = new Contact(LastName='LastName');
        insert contact;
        contact.LastName = 'AdjustedLastName';
        
        Test.startTest();
        Database.upsertResult result = Database.upsert(contact);
        Test.stopTest();
        
        System.assert(result.isSuccess());
    }
    
    @isTest static void blockContactUpdate() {
        Contact contact = new Contact(LastName='LastName');
        insert contact;
        contact.LastName = 'INVALIDNAME';
        
        Test.startTest();
        Database.UpsertResult result = Database.upsert(contact);
        Test.stopTest();
        
        System.assert(!result.isSuccess());
        System.assert(result.getErrors().size() > 0);
        System.assertEquals('The Last Name '+contact.LastName+' is not allowed for DML',
                             result.getErrors()[0].getMessage());
    }

}



 
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_System_Json.htm

according to the above link, since the summer '16 release it should be possible to suppress null values:
serialize(objectToSerialize, suppressApexObjectNulls)
 
String customJSONBody = JSON.serialize(myObject, true);

If I do the following code and debug the string, it still shows the null values.
Is it bugged? anybody knows a workaround?
so I got this thing with the Crypto class. 
sample code I will be using: 
trigger EncryptEmail on Contact (before insert, before update) {
    Contact[] contacts = new Contact[] {};
    
    for (Contact contact: Trigger.new) {
        Blob key = Blob.valueOf('privatekey');
        Blob iv = Blob.valueOf('customIV');
        Blob data = Blob.valueOf(contact.Email);
        Blob encrypted = Crypto.encrypt('AES128', key, iv, data);
        String encodedEmail = EncodingUtil.base64Encode(encrypted);

        Blob decrypted = Crypto.decrypt('AES128', key, iv, encrypted);
        String decodedEmail = decrypted.toString();
        
        System.debug(encodedEmail);
        System.debug(decodedEmail);
    }

    update contacts;
}

I need to create encrypted emails in order to be able to share them.
another program needs to decrypt it, but I noticed different results.
According to the Apex Docs:
These are all industry standard Advanced Encryption Standard (AES) algorithms with different size keys. They use cipher block chaining (CBC) and PKCS5 padding.

Is it possible to change CBC to CFB?
Hey there,

so I created a form (example: https://db.deondernemer.nl/adviesgesprekfinancieren/?id=a0uw0000007kOjeAAE)
everything works, the input values are read from the picklists in Salesforce.
however, submitting the form redirects to a strange errorpage.

intended submit:
insert custom object (with values from form)
page redirect to a custom url

it works in my sandbox environment, but apparently not on live.
I've checked the guest profile permissions and they match, so thats not it.
where am I going wrong?
Scenario:
I want to work with custom made UUID's instead of the default case sensitive Id's.
The Contact object for example has a field: UUID__c which contains a 36 char long unique, case-insensitive text string, set as External ID.

I'm able to get data in REST by using a GET request to /sobjects/Contact/UUID__c/af0407b7-eb9f-22f2-1648-fe66ccb4a516 (for example).
See also: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/using_resources_retrieve_with_externalid.htm

Now I want to use the same technique on Visualforce pages using controllers.
According to documentation the default route is to put the record id in the URL.
/apex/myPage?id=001x000xxx3Jsxb (for example)
See also: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_std_actions.htm

My challenge:
I want to be able to use the External ID too.
somehow /apex/myPage?UUID__c=af0407b7-eb9f-22f2-1648-fe66ccb4a516 (for example) doesn't seem to work.

- Do I need to switch some settings in order to be able to use it?
- Do I need to create an extension to the standard Contact controller in order to catch the External ID?
- Do I need to write a custom controller and lose the standard controller actions (and write everything from the ground up)?


 
Scenario:
I want to work with custom made UUID's instead of the default case sensitive Id's.
The Contact object for example has a field: UUID__c which contains a 36 char long unique, case-insensitive text string, set as External ID.

I'm able to get data in REST by using a GET request to /sobjects/Contact/UUID__c/af0407b7-eb9f-22f2-1648-fe66ccb4a516 (for example).
See also: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/using_resources_retrieve_with_externalid.htm

Now I want to use the same technique on Visualforce pages using controllers.
According to documentation the default route is to put the record id in the URL.
/apex/myPage?id=001x000xxx3Jsxb (for example)
See also: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_std_actions.htm

My challenge:
I want to be able to use the External ID too.
somehow /apex/myPage?UUID__c=af0407b7-eb9f-22f2-1648-fe66ccb4a516 (for example) doesn't seem to work.

- Do I need to switch some settings in order to be able to use it?
- Do I need to create an extension to the standard Contact controller in order to catch the External ID?
- Do I need to write a custom controller and lose the standard controller actions (and write everything from the ground up)?


 
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_System_Json.htm

according to the above link, since the summer '16 release it should be possible to suppress null values:
serialize(objectToSerialize, suppressApexObjectNulls)
 
String customJSONBody = JSON.serialize(myObject, true);

If I do the following code and debug the string, it still shows the null values.
Is it bugged? anybody knows a workaround?