• MissaJ
  • NEWBIE
  • 25 Points
  • Member since 2009

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 5
    Replies

I am trying to write a trigger to auto join a group with a trigger.  Can Groups be joined/followed via a trigger yet?

Hi Guys,

 

I haven't been on the boards in a while but thought I would stop in and ask for help with my latest issue.  It is driving me quite batty. 

 

The code that is having issues is not firing as it should.  When the record is inserted, it should create a task if the status is not complete and the participation status is not the same as the old version.  The code isn't firing on insert.  It is firing as it should or should not after you edit the record.

 

There is another trigger on another object that creates the records in question.  What am I missing.  Why is it not creating the task on insert?

 

 

trigger CreateMCPCTask on Provider_Carrier__c (before update) {

    
        List <Task> ActRecords = new List <Task>();
        List <Provider_Carrier__c> updatePC = new List <Provider_Carrier__c> ();
        List <Provider_Carrier__c> PCwTask = new List <Provider_Carrier__c> ();
        
     
       
        Integer count = 0;
        
        for (Provider_Carrier__c newPC : Trigger.new)
    {
        Provider_Carrier__c beforeUpdate = System.Trigger.oldMap.get(newPC.Id); 

            
            if( (newPC.Provider_Enrollment_Status__c != 'Complete') &&
                
                (beforeUpdate.Participation_Status__c != newPC.Participation_Status__c  ))
                
                 
                 {
                
                Provider_Carrier__c pfaAccount = null;
                try {
                    pfaAccount = [
                        SELECT
                            Provider_Facility_Association__r.Hospital__c
                        FROM
                            Provider_Carrier__c
                        WHERE
                            id = :newPC.id
                    ];               
                }
                catch (System.QueryException e) {}
                if (pfaAccount == null) {
                    newPC.addError('Task could not be created. There is no PFA Associated with this Provider Carrier.');
                }
                else {
                    
                    
                    AccountTeamMember cpecSpecialist = null;
                    try {
                        cpecSpecialist = [
                            SELECT 
                                UserId
                            FROM
                                AccountTeamMember
                            WHERE
                                account.id = :pfaAccount.Provider_Facility_Association__r.Hospital__c AND
                                teamMemberRole = 'CPEC Specialist'
                            LIMIT 1
                        ];
                    }
                    catch (System.QueryException e) {}
                    if (cpecSpecialist == null) {
                        newPC.addError('Task could not be created. There is no CPEC Specialist assigned to the account team for this Account.');
                    }
                    else {    
                        Task newACT = new Task();
                                newACT.RecordTypeID = '01240000000DYXb';
                                newACT.OwnerID = cpecSpecialist.UserId;
                                newACT.Subject = 'Process MC/CPEC Enrollment';
                                newACT.WhatID = newPC.Id;
                                newACT.Status = 'Not Started';
                                newACT.ActivityDate = System.Today();
                                newACT.Priority = 'Normal';
                                ACTRecords.add(newACT);

                    }                
                }
            }                
        }
    
        insert ACTRecords;
        
      
        
   }

 

Any help is appreciated. 

 

First Question : I have a field called Drivers License State that when filled in, should render the other two fields.  The rerendering works fine.  THe issue is the Drivers License State field formatting. Originally, the Drivers License state field was in a PageBlockSectionItem.  However, it won't let me save it as it says it can only have two pieces to it.  So i Put it in a page Block Section.  however, I need the value of the field to display with the an overridden question not the actual field label.  It puts the label twice.  Any help is greatly appreciated. 

 

                <apex:pageBlockSection >     
                    <apex:outputLabel value="Drivers License State" for="{!contactProxy.Drivers_License_State__c}"/>                                          
                    <apex:inputField value="{!ContactProxy.Drivers_License_State__c}">
                    
                       <apex:actionSupport event="onchange" rerender="Comps"
                                                      status="preference"/>
                                                   
                                                      
                </apex:inputfield>
                <apex:actionStatus startText="applying value..." id="preference"/>
                </apex:pageBlockSection>

 

Second Question:  I have a field referenced in a section header.  however the question that it is pulling from the controller is a very long question (link application type questions) and I need it to wrap.  how the heck do I get it to wrap. 

 

<apex:SectionHeader title="{!questionreference.Question__c}"/>

 

 

  • October 01, 2010
  • Like
  • 0

I have take this code from a blog here on the boards.  However this code creates an account, contact, and portal user from a VF page.  My contact is already created and tied to an account.  I want to use the @Future method to automatically create the portal user that was just created.  Can someone help me tweak it.  http://wiki.developerforce.com/index.php/ExampleApexCustomerPortalUser

 

public class customerPortalCls {
 
       public Account a {get;set;}
 	   public Contact c {get;set;}
       public User u {get;set;}
       public User newUser {get;set;}
       public String selectedProfileId {get;set;}
       public Boolean isDisabled {get;set;}
       public Boolean isNewUserFound {get;set;}
       public Boolean clickedButton {get;set;}
       
       //Constructor
       public customerPortalCls() {
        	a = new Account();
        	c = new Contact();
        	u = new User();
        	newUser= new User();
        	isDisabled=false;	
        	System.debug('inside constructor');
        	isNewUserFound=false;
        	clickedButton = false;
    	}
    	
       public PageReference checkForNewUser(){
       	try{
       		System.debug('isNewUserFound: ' + isNewUserFound);
          if(isNewUserFound==true)
           	return null;
       	  
       	  System.debug('checking for new user with username:' + u.username);
       	  User usr = [select id, name, username from User where username= :u.username LIMIT 1];
       	  if(usr!=null && usr.username == u.username){
       	     newUser = usr;
       	     isNewUserFound = true;
       	     System.debug('great news - found user with userId: ' + newUser.id);
       	     System.debug('isNewUserFound: ' + isNewUserFound);
       	  }
       	  return null;
       	}catch(Exception ex){
       		System.debug('...didnt find user yet...');
       		return null;
       	}
       }	
       
       //Controller method invoked from the VF page button
       public PageReference createPortaluser(){
        try{
        	clickedButton = true;
        	//Create the Account
        	Id accountId = createAccount();
        	System.debug('successfully created account');
        	
        	//Create the Contact associated to the previously created Contact
	        Id contactId = createContact(accountId);
	        
	        //Since the user is created asynchronously, we want to do some data validation to ensure the proper fields are populated
	        if(selectedProfileId == null || u.username==null){
	        	if(selectedProfileId==null){
	        		ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Profile is required: Please select a profile to associate new user');
					ApexPages.addMessage(myMsg);
	        	}
	        	if(u.username==null){
	        	   ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Username is required: Please a username for the new user');
				   ApexPages.addMessage(myMsg);
	        	}
	        	return null;
	        }
        	
        	//Create the User
	        //NOTE - Must invoke a @future method to be able to create Account, Contacts, and Users in the same Apex Transaction
	        customerPortalCls.createUser((String)contactId, c.Email, c.FirstName, c.lastname,u.Username,selectedProfileId);
	        
	        //Display success message to VF page
	        ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO, 'Successfully created Portal Contact & User records.');
			ApexPages.addMessage(myMsg);
			 isDisabled=true;
	        return null;
        }catch(Exception ex){
        	//Display error message to VF page
        	ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, ex.getMessage());
			ApexPages.addMessage(myMsg);
   	  	    return null;
        }
       }
       
    //Method to create the Account 
    public Id createAccount(){
         insert a;
         System.debug('successfully created test account with Id:' + a.id);
         return a.id;
    }
    
    //Method to create the Contact
    public Id createContact(Id acctId){
    	c.accountid=acctId;
		insert c;
		System.debug('successfully created test contact with Id:' + c.id);
		return c.id;
    }
    
    //Async method, using @future, to create the User record and associate it to the previously created Contact
    //This uses @future because you can not have mixed DML operations for standard objects (Account, Contact) and Setup objects(User)
    @future static void createUser(String contactId, String email, String firstName, String lastName, String userName, String profileId) {
        Database.DMLOptions dmo = new Database.DMLOptions();
		dmo.EmailHeader.triggerUserEmail = true;
    	User u = new User(alias = 'standt', email=email, 
            emailencodingkey='UTF-8', lastname=lastname, languagelocalekey='en_US', 
            localesidkey='en_US', profileid = profileId, contactId=contactId,
            timezonesidkey='America/Los_Angeles', username=username);
        
        u.setOptions(dmo);
        insert u;
    }

    public List<SelectOption> getCustomerPortalProfiles() {
    	//Execute query to get all profiles associated to Customer Portal
        Profile[] profiles = [Select p.name, p.id From Profile p where p.UserLicense.Name like '%Customer Portal%'];
   	 	List<SelectOption> options = new List<SelectOption>();
   	 	for(Profile p: profiles)
   	 		  options.add(new SelectOption(p.id,p.name));
   	 	return options;
    }
    
    public PageReference reset(){
        PageReference newpage = new PageReference('/apex/createPortaluser');
        newpage.getParameters().clear();
        newpage.setRedirect(true);
        return newpage;
    }
    
    /* REQUIRED TEST METHODS */
    static testMethod void createCustomerPortalUserTest() {
        customerPortalCls cpTest = new customerPortalCls();
        List<SelectOption> profileOptions = cpTest.getCustomerPortalProfiles();
        cpTest.a= new Account(name='TestMethod Account Name');
        cpTest.c = new Contact(firstName='TestFirstName', lastName='TestLastName', email='test@testorg.com');
        cpTest.u = new User(username='testusername@abc.com');
        Profile[] profiles = [Select p.name, p.id From Profile p where p.UserLicense.Name like '%Customer Portal%'];
		cpTest.selectedProfileId = profiles[0].id;
        
        Test.startTest();
        	cpTest.checkForNewUser();
        	PageReference testPageRef= cpTest.createPortaluser();
        	
	    Test.stopTest();
	    PageReference testPageRef2 = cpTest.reset();
	    cpTest.checkForNewUser();
	    
    }
    
    static testMethod void createCustomerPortalUserTestProfileIdError() {
        Boolean errorFound = false;
        customerPortalCls cpTest = new customerPortalCls();
        cpTest.a= new Account(name='TestMethod Account Name');
        cpTest.c = new Contact(firstName='TestFirstName', lastName='TestLastName', email='test@testorg.com');
        cpTest.u = new User(username='testusername@abc.com');
        Profile[] profiles = [Select p.name, p.id From Profile p where p.UserLicense.Name like '%Customer Portal%'];
		cpTest.selectedProfileId = null;
        
        Test.startTest();
        	PageReference testPageRef= cpTest.createPortaluser();
	    Test.stopTest();
	    
	    ApexPages.Message[] mssgs = ApexPages.getMessages();
	    for(ApexPages.Message m : mssgs){
	       if(m.getDetail()=='Profile is required: Please select a profile to associate new user')
	          errorFound=true;
	    }
	    System.assert(errorFound==true);
    }
    
     static testMethod void createCustomerPortalUserTestNullUsernameError() {
        Boolean errorFound = false;
        customerPortalCls cpTest = new customerPortalCls();
        cpTest.a= new Account(name='TestMethod Account Name');
        cpTest.c = new Contact(firstName='TestFirstName', lastName='TestLastName', email='test@testorg.com');
        cpTest.u = new User();
        Profile[] profiles = [Select p.name, p.id From Profile p where p.UserLicense.Name like '%Customer Portal%'];
		cpTest.selectedProfileId = profiles[0].id;
        
        Test.startTest();
        	
        	PageReference testPageRef= cpTest.createPortaluser();
        	 	
	    Test.stopTest();
	    ApexPages.Message[] mssgs = ApexPages.getMessages();
	    for(ApexPages.Message m : mssgs){
	       if(m.getDetail()=='Username is required: Please a username for the new user')
	          errorFound=true;
	    }
	    System.assert(errorFound==true);
    }
    
     static testMethod void createCustomerPortalUserRequiredFieldErrors() {
        Boolean errorFound = false;
        customerPortalCls cpTest = new customerPortalCls();
        cpTest.a= new Account();
        cpTest.c = new Contact(firstName='TestFirstName', lastName='TestLastName', email='test@testorg.com');
        cpTest.u = new User();
        Profile[] profiles = [Select p.name, p.id From Profile p where p.UserLicense.Name like '%Customer Portal%'];
		cpTest.selectedProfileId = profiles[0].id;
        
        Test.startTest();
        	PageReference testPageRef= cpTest.createPortaluser();
	    Test.stopTest();
    }
}
  • September 20, 2010
  • Like
  • 0

I have a object that a user needs to enter some data in a table format.  Then they may want to add another record.  They need to pull the ID that is being used to on the first row to the new row.  I can't get the Add/clone to work.  Any help is appreciated.

 

public with sharing class FacilityPayChangeController {
 


public Facility_Payrate_Change__c newPayChange {get; set;}



public FacilityPayChangeController()

{
    
ID dlRequestId = ApexPages.currentPage().getParameters().get('dlRequestId');
        newPayChange = new Facility_Payrate_Change__c(DL_Request__c=DLRequestID);
        

 
    }
    
public PageReference copyFPC() {
    String dlRequestID = ApexPages.currentPage().getParameters().get('dlRef');
    
    if (dlRequestID != null)
    { newPayChange = new Facility_Payrate_Change__c(DL_Request__c=DLRequestID);
      
      
    
    }
    return null;      
    }
    
    public PageReference save(){
        insert newPayChange;
        PageReference home = new PageReference('/home/home.jsp');
        home.setRedirect(true);
        return home;
    }  


       
     


}

VF Page

<apex:page Controller="FacilityPayChangeController" showHeader="False">
    <apex:form >
        <apex:PageBlock >
        
<apex:pageBlockButtons >
                <apex:commandButton value="Submit" action="{!save}" rerender="error"/>
                <apex:commandButton action="{!copyFPC}" value="Add another"/>
            </apex:pageBlockButtons>
            
        

            
            <apex:pageBlockTable value="{!newPayChange}" var="newPayChange" id="table">
            <apex:commandLink action="{!copyFPC}" value="Add another"/>


                
                    <apex:column headerValue="DL Request #">
                        <apex:inputField value="{!newPayChange.DL_Request__c}"/>
                    </apex:column>                

                    <apex:column headerValue="Shift Type">
                        <apex:inputField value="{!newPayChange.Shift_Type__c}"/>
                    </apex:column>

                    <apex:column headerValue="Coverage Type">
                        <apex:inputField value="{!newPayChange.Coverage_Type__c}"/>
                    </apex:column>

                    <apex:column headerValue="New Start Day">
                        <apex:inputField value="{!newPayChange.New_Shift_Start_Day_of_Week__c}"/>
                    </apex:column>
                    
                    <apex:column headerValue="New Start Time">
                        <apex:inputField value="{!newPayChange.New_Shift_Start_Time__c}"/>
                    </apex:column>

                    <apex:column headerValue="Requested Rate">
                        <apex:inputField value="{!newPayChange.Requested_Rate_Per_Hour__c}"/>
                    </apex:column>
                    
                    <apex:column headerValue="Hours Impacted">
                        <apex:inputField value="{!newPayChange.Hours_Impacted__c}"/>
                    </apex:column>   
                                      
                    <apex:column headerValue="Effective Date">
                        <apex:inputField value="{!newPayChange.Effective_Date__c}"/>
                    </apex:column>

            
            
            
            </apex:PageBlockTable>
        
        </apex:PageBlock>
    </apex:form>




</apex:page>
  • September 02, 2010
  • Like
  • 0

I am new to Visualforce and have learned quite a bit over the last few weeks.  

 

I am having an issue with rerendering a section based on values.  The page is using a customer controller.  I think the controller may be the issue but I am not sure.

 

What I want is this: 

 

When triggering field is changed from Value 1 to Value 2 - render :field B"  When triggering field is changed back to none render the triggering field only.  

 

What I get is this:

 

When triggering field  is changed from Value 1 to Value 2 nothing happens unless I hit the back button and then go forward again, then I get Field 2...So it's working when page is refreshed but upon change it is not automatically happening. 

 

 

Sample Code

<apex:page controller="CustomlController" showHeader="false">



 <apex:actionRegion>
        <apex:pageBlockSection showHeader="true" title="section1"  id="section1ID" columns="2">
            <apex:outputPanel>
            <apex:inputField value="{!object.triggeringfield__c}">
                <apex:actionSupport event="onchange" rerender="section1ID"
                                                      status="section1"/>
                </apex:inputfield>
                <apex:actionStatus startText="applying value..." id="preference"/>
                </apex:outputPanel>
            
            </apex:pageBlockSection>
 
     </apex:actionRegion>
        
        <apex:pageBlockSection title="section2" columns="2"
                                                 rendered="{obkect.triggeringfield__c =='value1'}">
            <apex:inputField value="{object.displayfield1__c}"/>
           
        </apex:pageBlockSection>
        
        <apex:pageBlockSection title="section3 " columns="2"
                                                 rendered="{object.triggeringfiel__c =='value2'}">
            <apex:inputField value="{object.displayfield2__c}"/>   
                    
        </apex:pageBlockSection>

 Do I need to add something into my custom controller.  Any help is greatly appreciated. 

 

 

 

I need to be able to to have certain profiles have the ability to add attachments in customer portal on either the contact or on a custom object.  I have been told by one premier support rep that this is not possible.  Yet I have seen references to it being done but I just can't figure out how. 

 

Greatly appreciate any help I can get on this one.

 

Thanks,

 

Melissa Elliott

  • April 13, 2010
  • Like
  • 0

I'm having an issue with my detail visual force page.  I have the apex:outputfield pulling the name of the field and the subsequent data.  I want to customize the "label".  The standard field labels in SF are limited in their length and I need to this to be larger or is there a way to hide the label if I can't customize the display.

 

The other question I have is below: 

 

I have a custom detail page with a edit button.  How can I make the edit button open up a custom edit page (i made a page that looks like the detail page but in edit mode).  So DetailPage needs to Edit and Open the EditPage

 

 

 

  • August 13, 2009
  • Like
  • 0

I have a visualforce page that I want to put on my customer portal.  When a person logs into the portal I want the contact page to only pull up that person's contact info.  I am probably missing something simple as it's late.  Any help is appreciated.

  • August 13, 2009
  • Like
  • 0

I am trying to write a trigger to auto join a group with a trigger.  Can Groups be joined/followed via a trigger yet?

Hi Guys,

 

I haven't been on the boards in a while but thought I would stop in and ask for help with my latest issue.  It is driving me quite batty. 

 

The code that is having issues is not firing as it should.  When the record is inserted, it should create a task if the status is not complete and the participation status is not the same as the old version.  The code isn't firing on insert.  It is firing as it should or should not after you edit the record.

 

There is another trigger on another object that creates the records in question.  What am I missing.  Why is it not creating the task on insert?

 

 

trigger CreateMCPCTask on Provider_Carrier__c (before update) {

    
        List <Task> ActRecords = new List <Task>();
        List <Provider_Carrier__c> updatePC = new List <Provider_Carrier__c> ();
        List <Provider_Carrier__c> PCwTask = new List <Provider_Carrier__c> ();
        
     
       
        Integer count = 0;
        
        for (Provider_Carrier__c newPC : Trigger.new)
    {
        Provider_Carrier__c beforeUpdate = System.Trigger.oldMap.get(newPC.Id); 

            
            if( (newPC.Provider_Enrollment_Status__c != 'Complete') &&
                
                (beforeUpdate.Participation_Status__c != newPC.Participation_Status__c  ))
                
                 
                 {
                
                Provider_Carrier__c pfaAccount = null;
                try {
                    pfaAccount = [
                        SELECT
                            Provider_Facility_Association__r.Hospital__c
                        FROM
                            Provider_Carrier__c
                        WHERE
                            id = :newPC.id
                    ];               
                }
                catch (System.QueryException e) {}
                if (pfaAccount == null) {
                    newPC.addError('Task could not be created. There is no PFA Associated with this Provider Carrier.');
                }
                else {
                    
                    
                    AccountTeamMember cpecSpecialist = null;
                    try {
                        cpecSpecialist = [
                            SELECT 
                                UserId
                            FROM
                                AccountTeamMember
                            WHERE
                                account.id = :pfaAccount.Provider_Facility_Association__r.Hospital__c AND
                                teamMemberRole = 'CPEC Specialist'
                            LIMIT 1
                        ];
                    }
                    catch (System.QueryException e) {}
                    if (cpecSpecialist == null) {
                        newPC.addError('Task could not be created. There is no CPEC Specialist assigned to the account team for this Account.');
                    }
                    else {    
                        Task newACT = new Task();
                                newACT.RecordTypeID = '01240000000DYXb';
                                newACT.OwnerID = cpecSpecialist.UserId;
                                newACT.Subject = 'Process MC/CPEC Enrollment';
                                newACT.WhatID = newPC.Id;
                                newACT.Status = 'Not Started';
                                newACT.ActivityDate = System.Today();
                                newACT.Priority = 'Normal';
                                ACTRecords.add(newACT);

                    }                
                }
            }                
        }
    
        insert ACTRecords;
        
      
        
   }

 

Any help is appreciated. 

 

I am new to Visualforce and have learned quite a bit over the last few weeks.  

 

I am having an issue with rerendering a section based on values.  The page is using a customer controller.  I think the controller may be the issue but I am not sure.

 

What I want is this: 

 

When triggering field is changed from Value 1 to Value 2 - render :field B"  When triggering field is changed back to none render the triggering field only.  

 

What I get is this:

 

When triggering field  is changed from Value 1 to Value 2 nothing happens unless I hit the back button and then go forward again, then I get Field 2...So it's working when page is refreshed but upon change it is not automatically happening. 

 

 

Sample Code

<apex:page controller="CustomlController" showHeader="false">



 <apex:actionRegion>
        <apex:pageBlockSection showHeader="true" title="section1"  id="section1ID" columns="2">
            <apex:outputPanel>
            <apex:inputField value="{!object.triggeringfield__c}">
                <apex:actionSupport event="onchange" rerender="section1ID"
                                                      status="section1"/>
                </apex:inputfield>
                <apex:actionStatus startText="applying value..." id="preference"/>
                </apex:outputPanel>
            
            </apex:pageBlockSection>
 
     </apex:actionRegion>
        
        <apex:pageBlockSection title="section2" columns="2"
                                                 rendered="{obkect.triggeringfield__c =='value1'}">
            <apex:inputField value="{object.displayfield1__c}"/>
           
        </apex:pageBlockSection>
        
        <apex:pageBlockSection title="section3 " columns="2"
                                                 rendered="{object.triggeringfiel__c =='value2'}">
            <apex:inputField value="{object.displayfield2__c}"/>   
                    
        </apex:pageBlockSection>

 Do I need to add something into my custom controller.  Any help is greatly appreciated. 

 

 

 

We currently have set up our org wide defaults for cases to Public/Read?Write. Everyone should be able to access the cases. These cases were opportunity specific. I am now creating cases that are internal only and do not relate to an opportunity. This new record type is for IT requests for our users. These IT requests I would like just the owner of the record and Admin to be able to view the issue. How can I set up my cases where the regular cases can be viewed by everyone but the IT requests only by the owner? 

 

I have tried the following:

 

I called SF basic support and they said you can not set up sharing rules based on record types. 

 

I tried adding the sharing button and tried to "unshare" users. I found that you can only add and not remove sharing settings.

 

What else can I do? Any suggestions?

 

Thank you in advance.

  • December 28, 2010
  • Like
  • 0

I'm having an issue with my detail visual force page.  I have the apex:outputfield pulling the name of the field and the subsequent data.  I want to customize the "label".  The standard field labels in SF are limited in their length and I need to this to be larger or is there a way to hide the label if I can't customize the display.

 

The other question I have is below: 

 

I have a custom detail page with a edit button.  How can I make the edit button open up a custom edit page (i made a page that looks like the detail page but in edit mode).  So DetailPage needs to Edit and Open the EditPage

 

 

 

  • August 13, 2009
  • Like
  • 0