• shiva1236
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 1
    Replies
/**
 * An apex page controller that supports self registration of users in communities that allow self registration
 */
public class CommunitiesSelfRegController {

    public String firstName {get; set;}
    public String lastName {get; set;}
    public String email {get; set;}
    public String password {get; set {password = value == null ? value : value.trim(); } }
    public String confirmPassword {get; set { confirmPassword = value == null ? value : value.trim(); } }
    public String communityNickname {get; set { communityNickname = value == null ? value : value.trim(); } }
    
    public CommunitiesSelfRegController() {}
    
    private boolean isValidPassword() {
        return password == confirmPassword;
    }

    public PageReference registerUser() {
    
           // it's okay if password is null - we'll send the user a random password in that case
        if (!isValidPassword()) {
            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, Label.site.passwords_dont_match);
            ApexPages.addMessage(msg);
            return null;
        }    

        String profileId = null; // To be filled in by customer.
        String roleEnum = null; // To be filled in by customer.
        String accountId = ''; // To be filled in by customer.
        
        String userName = email;

        User u = new User();
        u.Username = userName;
        u.Email = email;
        u.FirstName = firstName;
        u.LastName = lastName;
        u.CommunityNickname = communityNickname;
		u.ProfileId = profileId;
		
        String userId;

        try {
            userId = Site.createExternalUser(u, accountId, password);
        } catch(Site.ExternalUserCreateException ex) {
            List<String> errors = ex.getDisplayMessages();
            for (String error : errors)  {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, error));
            }
            
            // This message is used for debugging. Do not display this in the UI to the end user.
            // It has the information around why the user creation failed.
            System.debug(ex.getMessage());
        }
        
        if (userId != null) { 
            if (password != null && password.length() > 1) {
                return Site.login(userName, password, ApexPages.currentPage().getParameters().get('startURL'));
            }
            else {
                PageReference page = System.Page.CommunitiesSelfRegConfirm;
                page.setRedirect(true);
                return page;
            }
        }
        return null;
    }
}

/*Test Class*/
@IsTest public with sharing class CommunitiesSelfRegControllerTest {
    @IsTest(SeeAllData=true) 
    public static void testCommunitiesSelfRegController() {
        CommunitiesSelfRegController controller = new CommunitiesSelfRegController();
        controller.firstName = 'FirstName';
        controller.lastName = 'LastName';
        controller.email = 'test@force.com';
        controller.communityNickname = 'test';
        
        // registerUser will always return null when the page isn't accessed as a guest user
        System.assert(controller.registerUser() == null);    
        
        controller.password = 'abcd1234';
        controller.confirmPassword = 'abcd123';
        System.assert(controller.registerUser() == null);  
    }    
static testMethod void TestProfileType2(){
        test.startTest();
        CommunitiesSelfRegController controller = new CommunitiesSelfRegController();
        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
        User u1 = new User(username='testsfsdfsd@test.com',
                                IsActive=TRUE,
                                FirstName='test',
                                Alias = 'standt1',Country='United Kingdom',Email='demo1@randomdemodomain.com',
                           EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
                           LocaleSidKey='en_US',ProfileId = p.Id,TimeZoneSidKey='America/Los_Angeles');
        insert u1;
        // now insert your test data
       System.runAs(u1){
           
           controller.registerUser();  
            // you test for your controller
            test.startTest();
        }
}

 
hi can anyone help me with my requirement i.e,
how to send an email with the count of number of records in a Standard Object
Global class TmsEmailDemo 
{
public static void sendEmail() 
{
 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
 
// Who you are sending the email to
   List<String> sendTo = new List<String>();
    sendTo.add('xyz@gmail.com');
    sendTo.add('abc@gmail.com');
	mail.setToAddresses(sendTo);
    System.debug(sendTo);

  mail.setTargetObjectId('0037F00000FWFGo');

   // The email template ID used for the email
   mail.setTemplateId('00X7F000000pTjc');
    				   
   //mail.setWhatId(candidate);    
   mail.setBccSender(false);
   mail.setUseSignature(false);
   mail.setReplyTo('cvb@gmail.com');
   mail.setSenderDisplayName('Ajay');
   mail.setSaveAsActivity(false);  
 
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

    }  
}
HI can anyone help me on how to Automate Email So that every day at 10 AM the email should be delivered.
Thanks in advance
 
how to send an email template to multiple Contacts.
Global class TmsEmailDemo 
{
public static void sendEmail() 
{
 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
 
// Who you are sending the email to
   List<String> sendTo = new List<String>();
    sendTo.add('xyz@gmail.com');
    sendTo.add('abc@gmail.com');
	mail.setToAddresses(sendTo);
    System.debug(sendTo);

  mail.setTargetObjectId('0037F00000FWFGo');

   // The email template ID used for the email
   mail.setTemplateId('00X7F000000pTjc');
    				   
   //mail.setWhatId(candidate);    
   mail.setBccSender(false);
   mail.setUseSignature(false);
   mail.setReplyTo('cvb@gmail.com');
   mail.setSenderDisplayName('Ajay');
   mail.setSaveAsActivity(false);  
 
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

    }  
}
HI can anyone help me on how to Automate Email So that every day at 10 AM the email should be delivered.
Thanks in advance