• WillN
  • NEWBIE
  • 75 Points
  • Member since 2009

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 15
    Replies

Looking to display a list of records within an unrelated object. We are making an employee review object, and would like to display all the accounts that user owns on the review object. We will be able to grab the user's ID on that review object - they aren't the owner, but are in a lookup field. I'm invisioning a bit of Visualforce, but I'm not sure how to get there. Any help is appreciated!

Hi Everyone,

 

I hope that someone out there might be able to provide me with a little help with some of my code. I am currently trying to modify the Sites self-registration page to work like the Customer Portal page. This modification would allow for a portal user to be created if the contact card has the "Self-Register in Portal" checkbox selected and they enter their email on the SiteRegister page.

 

I will provide both the VF page and APEX:

 

1. SiteRegister (VF)

<apex:page id="loginPage" showHeader="true" controller="SiteRegisterController" title="{!$Label.site.register}">
  <apex:composition template="{!$Site.Template}">
    <apex:define name="body">  
       <style>
.tabNavigation {display:none;}
</style>
 <style>

.sidebarCell {display:none;}
</style>
  <style>.sidebarDiv {display:none;}
</style><center>
        <apex:panelGrid bgcolor="004f8c" columns="1"> 
          <br/>
          <br/>
          <apex:panelGrid width="758" cellpadding="0" cellspacing="0" bgcolor="white" columns="1" styleClass="topPanelContainer"> 
            <br/>
            <apex:outputPanel layout="block" styleClass="topPanel">
              <apex:panelGrid width="758" cellpadding="0" cellspacing="0" bgcolor="white" columns="2"> 
                <apex:image url="https://c.na8.content.force.com/servlet/servlet.ImageServer?id=015C0000001MSFY&oid=00D80000000bQYx&lastMod=1304543302000"/>
                <apex:panelGroup >
                  <br/>
                  <apex:outputText styleClass="title" value="{!$Label.site.user_registration}"/>
                  <br/>
                  <apex:form id="theForm" forceSSL="true">
                    <apex:pageMessages id="error"/>
                    <apex:panelGrid columns="2" style="margin-top:1em;">
                      
                      <apex:outputLabel value="{!$Label.site.email}" for="email1"/>
                      <apex:inputText required="true" id="email1" value="{!email1}"/>
                      
                      
                      <apex:commandButton action="{!registerUser}" value="{!$Label.site.submit}" id="submit"/>
                    </apex:panelGrid> 
                    </apex:form>                  
                  <br/>
                </apex:panelGroup>
              </apex:panelGrid> 
             </apex:outputPanel>
            <c:SitePoweredBy />
          </apex:panelGrid> 
       </apex:panelGrid>
      </center>
      <br/>
    </apex:define>
  </apex:composition>  <site:googleAnalyticsTracking />
</apex:page>

 2. SiteRegisterController (APEX)

/**
 * An apex class that creates a portal user
 */
public with sharing class SiteRegisterController {

	public String email1 {get; set;}
    
    public SiteRegisterController () {
    }

    
    
    public PageReference registerUser() 
    {
        List<User> alreadyExists = [Select Id from User WHERE username =:email1 AND IsActive = true LIMIT 1];
        if (alreadyExists.size() > 0) 
        {
            PageReference page = System.Page.SiteLogin;
            page.setRedirect(true);
            return page;
        }
        else 
        {
            List<Contact> c = [Select Id, AccountId, FirstName, LastName, Email FROM Contact WHERE CanAllowPortalSelfReg = true AND Email =:email1];
            
            if (!c.isEmpty()) 
            {
            	Profile profile = [select Id, name from Profile where Name=:'Customer Portal Manager 1'];
				System.debug('***** ContactID1--> ' + c[0].id);
            	SiteRegisterController.createUser(c[0].id, c[0].email, c[0].firstname, c[0].lastname, profile.id);
	        	
	        	ApexPages.Message myMsg1 = new ApexPages.Message(ApexPages.Severity.INFO, 'Successfully registered your Account. Please await for an email containing futher instructions');
	        	ApexPages.addMessage(myMsg1);
	        	//PageReference page = System.Page.SiteRegisterConfirm;
				//page.setRedirect(true);
				//return page;
				return null;
            }
            else
            {
	            ApexPages.Message myMsg2 = new ApexPages.Message(ApexPages.Severity.ERROR, 'This is currently an invitation only system. Please contact the system administrator to gain access.' + ' ' + c.size());
		        ApexPages.addMessage(myMsg2);
		        //PageReference page = System.Page.Exception;
				//page.setRedirect(true);
				//return page; 
				return null;
            }
		}
    }
    
    public static void createUser(String contactid, String email, String firstname, String lastname, String profileid)
    {
    	Database.DMLOptions dmo = new Database.DMLOptions();
		dmo.EmailHeader.triggerUserEmail = true;
		
    	User u = new User();
        u.ContactId = contactid;
	    u.Username = email;
	    u.Alias = u.Username.split('@').get(0);
	    u.Email = email;
	    u.Firstname = firstname;
	    u.Lastname = lastname;
	    u.ProfileID = profileid;
	    u.communityNickname = u.Username.split('@').get(0);
	    //u.PortalRole = 'Test Customer Account Customer User';
	    u.LanguageLocaleKey = 'en_US';
	    u.LocaleSidKey = 'en_CA';
	    u.TimeZoneSidKey = 'America/Los_Angeles';
	    u.EmailEncodingKey='UTF-8';
	            
	    System.debug('***** Username--> ' + u.Username);
	    System.debug('***** ContactId--> ' + u.ContactId);
	    System.debug('***** Email--> ' + u.Email);
	    System.debug('***** Firstname--> ' + u.Firstname);
	    System.debug('***** Lastname--> ' + u.Lastname);
	    System.debug('***** ProfileID--> ' + u.ProfileID);
	    System.debug('***** PortalRole--> ' + u.PortalRole);
	    System.debug('***** Alias--> ' + u.Alias);

	    u.setOptions(dmo);
	    insert u;	        	
	    System.Debug('***** UserId-->' + u.Id);    	
    }
    
    // Test method to bring this class's test coverage over the required 75%
    @IsTest(SeeAllData=true) static void testRegistration() {
        SiteRegisterController controller = new SiteRegisterController();
        controller.email1 = 'tmowbrey@belmar.ca';
        controller.registerUser();
        // registerUser will always return null when the page isn't accessed as a guest user
        //System.assert(controller.registerUser() == null);    
        controller.email1 = 'idonotexist@domain.com';
        controller.registerUser();
        
        Contact c = new Contact(firstName='TestFirstName', lastName='TestLastName', email='iamauser@domain.com', accountid='001U0000006KtbB');
        insert c;
        System.debug('***** ContactIDTest--> ' + c.id);
        Profile profile = [select Id, name from Profile where Name=:'Customer Portal Manager 1'];
        SiteRegisterController.createUser(c.id, c.email, c.firstname, c.lastname, profile.id);
        controller.email1 = 'iamauser@domain.com';
        controller.registerUser();
    }
    
}

 The tests are correctly creating a portal user for tmowbrey@belmar.ca as this contact exists (has no portal user created) and has the Self-Register checkbox selected.

 

The issue occurs when actually deploying and using the code in actuallity. Everytime I put in tmowbrey@belmar.ca I receive "'This is currently an invitation only system. Please contact the system administrator to gain access." with a c.size() of 0. I can not figure out why.

 

Please let me know if I can provide more information.

 

Regards,

Tyler Mowbrey

I added folders and the group for the files and links but can't seem to add/ connect the files themselves.

This app has great potential, once I can understand how to make it work.

Yes, I turned of dev mode. Thank you for the help.

Looking to display a list of records within an unrelated object. We are making an employee review object, and would like to display all the accounts that user owns on the review object. We will be able to grab the user's ID on that review object - they aren't the owner, but are in a lookup field. I'm invisioning a bit of Visualforce, but I'm not sure how to get there. Any help is appreciated!

Hi Everyone,

 

I hope that someone out there might be able to provide me with a little help with some of my code. I am currently trying to modify the Sites self-registration page to work like the Customer Portal page. This modification would allow for a portal user to be created if the contact card has the "Self-Register in Portal" checkbox selected and they enter their email on the SiteRegister page.

 

I will provide both the VF page and APEX:

 

1. SiteRegister (VF)

<apex:page id="loginPage" showHeader="true" controller="SiteRegisterController" title="{!$Label.site.register}">
  <apex:composition template="{!$Site.Template}">
    <apex:define name="body">  
       <style>
.tabNavigation {display:none;}
</style>
 <style>

.sidebarCell {display:none;}
</style>
  <style>.sidebarDiv {display:none;}
</style><center>
        <apex:panelGrid bgcolor="004f8c" columns="1"> 
          <br/>
          <br/>
          <apex:panelGrid width="758" cellpadding="0" cellspacing="0" bgcolor="white" columns="1" styleClass="topPanelContainer"> 
            <br/>
            <apex:outputPanel layout="block" styleClass="topPanel">
              <apex:panelGrid width="758" cellpadding="0" cellspacing="0" bgcolor="white" columns="2"> 
                <apex:image url="https://c.na8.content.force.com/servlet/servlet.ImageServer?id=015C0000001MSFY&oid=00D80000000bQYx&lastMod=1304543302000"/>
                <apex:panelGroup >
                  <br/>
                  <apex:outputText styleClass="title" value="{!$Label.site.user_registration}"/>
                  <br/>
                  <apex:form id="theForm" forceSSL="true">
                    <apex:pageMessages id="error"/>
                    <apex:panelGrid columns="2" style="margin-top:1em;">
                      
                      <apex:outputLabel value="{!$Label.site.email}" for="email1"/>
                      <apex:inputText required="true" id="email1" value="{!email1}"/>
                      
                      
                      <apex:commandButton action="{!registerUser}" value="{!$Label.site.submit}" id="submit"/>
                    </apex:panelGrid> 
                    </apex:form>                  
                  <br/>
                </apex:panelGroup>
              </apex:panelGrid> 
             </apex:outputPanel>
            <c:SitePoweredBy />
          </apex:panelGrid> 
       </apex:panelGrid>
      </center>
      <br/>
    </apex:define>
  </apex:composition>  <site:googleAnalyticsTracking />
</apex:page>

 2. SiteRegisterController (APEX)

/**
 * An apex class that creates a portal user
 */
public with sharing class SiteRegisterController {

	public String email1 {get; set;}
    
    public SiteRegisterController () {
    }

    
    
    public PageReference registerUser() 
    {
        List<User> alreadyExists = [Select Id from User WHERE username =:email1 AND IsActive = true LIMIT 1];
        if (alreadyExists.size() > 0) 
        {
            PageReference page = System.Page.SiteLogin;
            page.setRedirect(true);
            return page;
        }
        else 
        {
            List<Contact> c = [Select Id, AccountId, FirstName, LastName, Email FROM Contact WHERE CanAllowPortalSelfReg = true AND Email =:email1];
            
            if (!c.isEmpty()) 
            {
            	Profile profile = [select Id, name from Profile where Name=:'Customer Portal Manager 1'];
				System.debug('***** ContactID1--> ' + c[0].id);
            	SiteRegisterController.createUser(c[0].id, c[0].email, c[0].firstname, c[0].lastname, profile.id);
	        	
	        	ApexPages.Message myMsg1 = new ApexPages.Message(ApexPages.Severity.INFO, 'Successfully registered your Account. Please await for an email containing futher instructions');
	        	ApexPages.addMessage(myMsg1);
	        	//PageReference page = System.Page.SiteRegisterConfirm;
				//page.setRedirect(true);
				//return page;
				return null;
            }
            else
            {
	            ApexPages.Message myMsg2 = new ApexPages.Message(ApexPages.Severity.ERROR, 'This is currently an invitation only system. Please contact the system administrator to gain access.' + ' ' + c.size());
		        ApexPages.addMessage(myMsg2);
		        //PageReference page = System.Page.Exception;
				//page.setRedirect(true);
				//return page; 
				return null;
            }
		}
    }
    
    public static void createUser(String contactid, String email, String firstname, String lastname, String profileid)
    {
    	Database.DMLOptions dmo = new Database.DMLOptions();
		dmo.EmailHeader.triggerUserEmail = true;
		
    	User u = new User();
        u.ContactId = contactid;
	    u.Username = email;
	    u.Alias = u.Username.split('@').get(0);
	    u.Email = email;
	    u.Firstname = firstname;
	    u.Lastname = lastname;
	    u.ProfileID = profileid;
	    u.communityNickname = u.Username.split('@').get(0);
	    //u.PortalRole = 'Test Customer Account Customer User';
	    u.LanguageLocaleKey = 'en_US';
	    u.LocaleSidKey = 'en_CA';
	    u.TimeZoneSidKey = 'America/Los_Angeles';
	    u.EmailEncodingKey='UTF-8';
	            
	    System.debug('***** Username--> ' + u.Username);
	    System.debug('***** ContactId--> ' + u.ContactId);
	    System.debug('***** Email--> ' + u.Email);
	    System.debug('***** Firstname--> ' + u.Firstname);
	    System.debug('***** Lastname--> ' + u.Lastname);
	    System.debug('***** ProfileID--> ' + u.ProfileID);
	    System.debug('***** PortalRole--> ' + u.PortalRole);
	    System.debug('***** Alias--> ' + u.Alias);

	    u.setOptions(dmo);
	    insert u;	        	
	    System.Debug('***** UserId-->' + u.Id);    	
    }
    
    // Test method to bring this class's test coverage over the required 75%
    @IsTest(SeeAllData=true) static void testRegistration() {
        SiteRegisterController controller = new SiteRegisterController();
        controller.email1 = 'tmowbrey@belmar.ca';
        controller.registerUser();
        // registerUser will always return null when the page isn't accessed as a guest user
        //System.assert(controller.registerUser() == null);    
        controller.email1 = 'idonotexist@domain.com';
        controller.registerUser();
        
        Contact c = new Contact(firstName='TestFirstName', lastName='TestLastName', email='iamauser@domain.com', accountid='001U0000006KtbB');
        insert c;
        System.debug('***** ContactIDTest--> ' + c.id);
        Profile profile = [select Id, name from Profile where Name=:'Customer Portal Manager 1'];
        SiteRegisterController.createUser(c.id, c.email, c.firstname, c.lastname, profile.id);
        controller.email1 = 'iamauser@domain.com';
        controller.registerUser();
    }
    
}

 The tests are correctly creating a portal user for tmowbrey@belmar.ca as this contact exists (has no portal user created) and has the Self-Register checkbox selected.

 

The issue occurs when actually deploying and using the code in actuallity. Everytime I put in tmowbrey@belmar.ca I receive "'This is currently an invitation only system. Please contact the system administrator to gain access." with a c.size() of 0. I can not figure out why.

 

Please let me know if I can provide more information.

 

Regards,

Tyler Mowbrey

I've got a workflow that runs when a boolean field is set to true. The workflow sends an outbound message and does a field update to the boolean to false.

 

I've got a trigger that updates that boolean field to true. My problem is that when I write the test, it fails in the assertion because the boolean has been reset to false by the workflow. How can I do an assertion here? I'm good on code coverage and I know that the trigger is working, but I really want someway to do the assertion. Does anybody have any ideas?

Using Apex code and Visual Force pages, I have been able to limit what fields on an account, contact, or opportunity that a user can see based on his role and the role of the owner of the record.

 

There is a loophole in that the users can create custom views, and then they can see the fields I am hiding from them on the Account,Contact, and Opportunity pages by including those fields in a custom view.

 

Is there a way to limit the fields displayed in a search result based on SF configuration, Apex code, or some combination of the two?

 

 

Is there a formula out there that will display the last day of the current year? (12/31/2011)

 

I'm trying to calculate the number of weekd days there are between a date and the end of the year.

 

I've found the formula that will automatically calculate the amount of business days there are between a start and end date, so if I could reference the end date as the formala field that displays the last day of the year, I would meet my requirement.

 

Thanks!

Dashboard other user cant see using force.com-free licence. 

HI All

 

How can i transfer the data from PosTgre SQL to MySQL by using the java. Can u Pls help me

 

 

Thanks &Regards

Sahasra.

 

 

HI,

I have 3 custom objects.

Object1:- It contains fields as Name (Auto), FieldName__c (Text), ObjectName__c(Text).

Name     FieldName__c            ObjectName__c

1 Item__c(lookup) object2

2             Color__c(Text)              object2

3             Size__c(Text)                 object2

like this i entered records.

Object3: It Contains fields as Name(auto), Item__c(Text), Required__c(Text).

Name         Item__c           Required__c

1 AC Color

2 FAN SIZE

 

With "object1" i constructed a new VF page dynamically using Wrapper class Functionality.

Initially all the fields on DVF is not required. This page Contains Item__c (lookup), color__c, Size__c fields and save button.

Now select Item__c value (AC) from the lookup then save.

Per Item "AC" Color is required. Here Color value is null.

So, i need to make that color field as required field with Red (Just like standard salesforce functionality).

Like this i need to perform the validation on my Dynamic VF page.

 

 

Please suggest me.

 

 

 

 

I added folders and the group for the files and links but can't seem to add/ connect the files themselves.

This app has great potential, once I can understand how to make it work.

Yes, I turned of dev mode. Thank you for the help.

I noticed that once i enable the Customer Portal, if I edit a custom object to make available to the portal, the checkboxes under the portal profile do not update to reflect the read/write/create/delete rights.

 

But if i create a new custom object, and check "make available for portal" upon creation those checkboxes are updated.

 

Is this just a GUI glitch??. or does this mean that the only way to make a custom object available to the portal is at the time of it's creation ??

Message Edited by FadiShami on 02-02-2009 01:14 PM