• Lynn Shaw
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Is there a way to use the Crypto.signWithCertificate() method using SHA-512?  We need to be able to sign a string using SHA-512, not any of the lower algorithms.

Several of the other Crypto methods support SHA-512, but the documentation (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_crypto.htm) does not list 512, nor will it work when we tried it in our code:

Blob signedSecret = Crypto.signWithCertificate('SHA-512', blobSecret, certificateName);

Suggestions?
 
Is there a way to use the Crypto.signWithCertificate() method using SHA-512?  We need to be able to sign a string using SHA-512, not any of the lower algorithms.

Several of the other Crypto methods support SHA-512, but the documentation (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_crypto.htm) does not list 512, nor will it work when we tried it in our code:

Blob signedSecret = Crypto.signWithCertificate('SHA-512', blobSecret, certificateName);

Suggestions?
 
I had previously converted a VF Community to Napili.  During the transition, I had inadvertently removed all the User Profiles from the Membership page.  When I added the Profiles back, all the Reputation points were gone.  I realize now that was a big mistake.  Now I am trying to recover the points.
1) I am experienced with tools like Data Loader, dataloader.io.
2) I understand that the Reputation Points are stored in the NetworkMembers object in the ReputationPoints field.  If I have a value for each Member, I can update this field.
3) The challenge is recalculating the total reputation points for each Network Member.  I am assuming I would need to find each type of Reputation event (Likes, Posts, Comments, Shares, etc.) and multiply by configured Reputation Points for each type of event.  I think I can do this, but it sounds extremely tedious.
4) Is there an easier way?  Is there a way to have Salesforce force a recalculation perhaps through the API?
5) Are there any Apps out there that could help me?
6) Any other suggestions are appreciated!
I have nearly completed a registration handler for our community that uses person accounts, but need a little help finishing up.  Below you can see my registration handler class, along with the corresponding test.  
  • Since this is for a community, do I have to specify the Salesforce License type of Customer Community Login user when creating the user?
  • I tried to create a person account, then capture the ContactId to use when creating the user, does that look complete?
Also, both the class and test save, and when the test runs, it says that it covers 100% of the class code, but it fails.  I get the following error:

System.DmlException: Update failed. First exception on row 0 with id 0054C000000M2VbQAK; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): User, original object: Account: []
Class.FamilySearchRegHandler.updateUser: line 52, column 1
Class.FamilySearchRegHandler_Test.testCreateAndUpdateUser: line 20, column 1

I found this suggestion, but I am not quite sure how to implement it.

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

Any suggestions?
 
global class FamilySearchRegHandler implements Auth.RegistrationHandler{

global User createUser(Id portalId, Auth.UserData data){

    RecordType personAccountRecordType =  [SELECT Id FROM RecordType WHERE Name = 'Person Account' and SObjectType = 'Account'];
    Account newPersonAccount = new Account();
        // for person accounts we can not update the Name field instead we have to update the FirstName and LastName individually
        newPersonAccount.FirstName = data.firstName;
        newPersonAccount.LastName =  data.lastName;
        newPersonAccount.RecordType = personAccountRecordType;
        insert newPersonAccount;
    	
    	Contact c = [SELECT AccountId,Id FROM Contact WHERE AccountId = :newPersonAccount.Id];   
    
        //TODO: Customize the username and profile. Also check that the username doesn't already exist and
        //possibly ensure there are enough org licenses to create a user. Must be 80 characters or less.
        User u = new User();
        Profile p = [SELECT Id FROM profile WHERE name='Community - FS - Public'];
        u.username = data.username + '.fscommunity';
        u.email = data.email;
        u.lastName = data.lastName;
        u.firstName = data.firstName;
        String alias = data.username;
        //Alias must be 8 characters or less
        if(alias.length() > 8) {
            alias = alias.substring(0, 8);
        }
        u.alias = alias;
        u.languagelocalekey = UserInfo.getLocale();
        u.localesidkey = UserInfo.getLocale();
        u.emailEncodingKey = 'UTF-8';
        u.timeZoneSidKey = 'America/Denver';
        u.profileId = p.Id;
        u.contactId = c.Id;
        return u;
    } 


global void updateUser(Id userId, Id portalId, Auth.UserData data){
    User u = new User(id=userId);
    //TODO: Customize the username. Must be 80 characters or less.
    //u.username = data.username + '.fscommunity';
    u.email = data.email;
    u.lastName = data.lastName;
    u.firstName = data.firstName;
    //String alias = data.username;
    //Alias must be 8 characters or less
    //if(alias.length() > 8) {
        //alias = alias.substring(0, 8);
    //}
    //u.alias = alias;
    update(u);
}
}
 
@isTest
private class FamilySearchRegHandler_Test {
static testMethod void testCreateAndUpdateUser() {
    FamilySearchRegHandler handler = new FamilySearchRegHandler();
    Auth.UserData sampleData = new Auth.UserData('testId', 'testFirst', 'testLast',
        'testFirst testLast', 'testuser@example.org', null, 'testuserlong@fs.org', 'en_US', 'facebook',
        null, new Map<String, String>{'language' => 'en_US'});
    User u = handler.createUser(null, sampleData);
    System.assertEquals('testuserlong@fs.org.fscommunity', u.userName);
    System.assertEquals('testuser@example.org', u.email);
    System.assertEquals('testLast', u.lastName);
    System.assertEquals('testFirst', u.firstName);
    System.assertEquals('testuser', u.alias);
    insert(u);
    String uid = u.id;
    
    sampleData = new Auth.UserData('testNewId', 'testNewFirst', 'testNewLast',
        'testNewFirst testNewLast', 'testnewuser@example.org', null, 'testnewuserlong', 'en_US', 'facebook',
        null, new Map<String, String>{});
    handler.updateUser(uid, null, sampleData);
    
    User updatedUser = [SELECT userName, email, firstName, lastName, alias FROM user WHERE id=:uid];
    System.assertEquals('testnewuserlong@salesforce.com', updatedUser.userName);
    System.assertEquals('testnewuser@example.org', updatedUser.email);
    System.assertEquals('testNewLast', updatedUser.lastName);
    System.assertEquals('testNewFirst', updatedUser.firstName);
    System.assertEquals('testnewu', updatedUser.alias);
}
}