• Markey1
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 20
    Questions
  • 23
    Replies

Hi, I'm fairly new to Triggers and am hoping someone can give me a bit of direction.

 

I want a custom field "Record_Mode__c" on Child Object B to be updated to value "Edit" when Parent Object A's custom field "Status__c" is updated to "Open". Basically, any time the parent record's status changes, I want the child record's Record Mode field to be updated accordingly.

 

The Record Mode change will then drive workflow that will flip record types and page layouts. I prefer to use out of the box solutions, but I cannot use cross object workflows as there is no master detail relationship between Parent Object A and Child Object B.

 

Any assistance with code or alternate solutions are much appreciated! 

Sites Explanation:

We have a sites project which is public. The public access settings allow our end-users to login via a guest license and enter their information (no authentication).

 

Sites URL Setup:

Default URL: http://something.force.com/xyzenrollment

Secure URL: https://something.secure.force.com/xyzenrollment

Custom Web Address: http://enroll.something.com

 

The Issue:

The Site is not secure. All information entered via the Site by our end-users needs to be secure (i.e. currently http, needs to be https).

 

Question:

How do I point the users to the Secure URL vs. the Default URL while still keeping the Custom Web Address masking? I changed the Administration Setup > Security Controls > Session Settings > Require secure connections (HTTPS) to checked, but this does not seem to do the trick.

How do you test messages? I'm getting no coverage for the lines highlighted in red. Any help with how to write a test condition for the below code is much appreciated.

 

public PageReference save() {
  try {
    if(skTest.Submission_Type__c == 'New Submission' && (attachment.name == '' || attachment.description == '' || attachment.body == null)) {
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'All upload fields are required.'));
    return null;
  }

 

Anyone know how to test Catch blocks. I've looked around for creating Catch test conditions but have been unsuccessful so far.

 

Code Snippet:

            insert skEnroll;
        } 
        catch (DMLException e) {            
            ApexPages.addMessages(e);            
            return null;
        }
        return page.aeskenrollconfirm; 
    }        
}

 

This code was created by another developer and I need to achieve higher coverage to deploy an unrelated project. My test class (psuControllerTest) is receiving a test failure. It looks like it does not like the last part of the code where the "Status" is set. Any help with correcting the test code is much appreciated.

 

Method Name:

psuControllerTest.testPsuIdRequest

 

Message:

System.DmlException: Update failed. First exception on row 0 with id a0HP0000001ivPOMAY; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []

 

Stack Trace:

Class.psuIdRequestController.setStatus: line 88, column 13 Class.psuIdRequestController.Approve: line 45, column 9 Class.psuControllerTest.testPsuIdRequest: line 176, column 9 External entry point

 

 

Test class snippet:

     static testMethod void hierarchyControllerTest() {
        Id profileid = [Select id from Profile where name = 'Customer Portal Manager Custom'].id;
        Account account = new Account(Name = 'Test Account'); 
        
        insert account; 
        Contact businessContact = new Contact(AccountID = account.id, FirstName = 'Test', LastName = 'BusinessUser', email = 'bustest@test.com' ); 
        Contact technicalContact = new Contact(AccountID = account.id, FirstName = 'Test', LastName = 'TechnicalUser', email = 'tectest@test.com' ); 
        Contact financeContact = new Contact(AccountID = account.id, FirstName = 'Test', LastName = 'FinanceUser', email = 'fintest@test.com' );
        Contact treasuryContact = new Contact(AccountID = account.id, FirstName = 'Test', LastName = 'TreasuryUser', email = 'tretest@test.com' ); 
        Contact[] contacts = new Contact[]{businessContact,technicalContact,financeContact,treasuryContact};
        insert contacts;

        User BusinessUser = new User(email='business@test.com', 
                                     contactid = businessContact.id, 
                                     profileid = profileid, 
                                     UserName='business@test.com', 
                                     alias='bususer', CommunityNickName='bususer',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test', 
                                     LastName = 'BusinessUser');
        User TechnicalUser = new User(email='technical@test.com', 
                                     contactid = technicalContact.id, 
                                     profileid = profileid, 
                                     UserName='technical@test.com', 
                                     alias='tecuser', CommunityNickName='tecuser',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test', 
                                     LastName = 'TechnicalUser');
        User FinanceUser = new User(email='finance@test.com', 
                                     contactid = financeContact.id, 
                                     profileid = profileid, 
                                     UserName='finance@test.com', 
                                     alias='finuser', CommunityNickName='finuser',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test', 
                                     LastName = 'FinanceUser');
        User InvalidUser = new User(email='treasury@test.com', 
                                     contactid = treasuryContact.id, 
                                     profileid = profileid, 
                                     UserName='treasury@test.com', 
                                     alias='treuser', CommunityNickName='treuser',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test', 
                                     LastName = 'TreasuryUser');
        User[] users = new User[]{businessUser,technicalUser,financeUser,InvalidUser};
        insert users;    
        //Create a Request
        Participant_ID_Request__c request = new Participant_ID_Request__c(
        Name='New Hierarchy Test',
        Business_Approver__c = BusinessUser.ContactId, 
        Techincal_Approver__c  = TechnicalUser.ContactId, 
        Finance_Approver__c = FinanceUser.ContactId,  
        Treasury_Hierarchy_Approver__c = InvalidUser.ContactId
        );
        insert request;
        
        //Create a Hierarchy
        Participant_Hierarchy__c hierarchy = new Participant_Hierarchy__c(
        Name='Hierarchy Test',
        Business_Approver__c = BusinessUser.ContactId, 
        Technical_Approver__c  = TechnicalUser.ContactId,  
        Finance_Approver__c = FinanceUser.ContactId,
        Treasury_Hierarchy_Approver__c = InvalidUser.ContactId,
        Business_Approval__c = 'Pending', 
        Technical_Approval__c = 'Pending', 
        Finance_Approval__c = 'Pending',
        Treasury_Approval__c = 'Pending',
        Treasury_Comments__c = 'Test',
        Business_Comments__c = 'Test', 
        Technical_Comments__c= 'Test', 
        Finance_Comments__c= 'Test',
        New_Participant__c = request.Id
        );
        insert hierarchy;
    
                
        // Test class Complete_Requirements_Status methods 
        ApexPages.standardController hierarchyCntl = new ApexPages.standardController(hierarchy);
        Test.setCurrentPageReference(new PageReference('Page.hierarchyreview')); 
        System.currentPageReference().getParameters().put('requestid', request.Id);
        psuHierarchyController reviewController = new psuHierarchyController(hierarchyCntl);
        Participant_Hierarchy__c objHierarchy = reviewController.gethierarchy();
            
         //Test as Portal User
        String strStatus; 
        
        System.RunAs(BusinessUser)
        {
            String strApprover = reviewController.getApprover();
            String strComment = reviewController.getComment();
            reviewController.setComment(strComment);
            strStatus = reviewController.getStatus();
        } //end RunAs

        System.RunAs(TechnicalUser)
        {
            String strApprover = reviewController.getApprover();
            String strComment = reviewController.getComment();
            reviewController.setComment(strComment);
            strStatus = reviewController.getStatus();
        } //end RunAs
        System.RunAs(FinanceUser)
        {
            String strApprover = reviewController.getApprover();
            String strComment = reviewController.getComment();
            reviewController.setComment(strComment);
            strStatus = reviewController.getStatus();
        } //end RunAs
        System.RunAs(InvalidUser)
        {
            String strApprover = reviewController.getApprover();
            String strComment = reviewController.getComment();
            reviewController.setComment(strComment);
            strStatus = reviewController.getStatus();
        } //end RunAs

        reviewController.approve();
            
        reviewController.reject();

        reviewController.setStatus(strStatus);
        
        String hn = reviewController.getHierarchyName();
        String approver = reviewController.getApprover();
        Attachment attachment = reviewController.attachment;
        Attachment[] attachments = reviewController.attachments;
        
    }

 

I can't seem to get the 75% test coverage required to deploy. Any help with the test code is much appreciated. Also, any links to assist with reading the debug logs (i.e. how to) would be helpful as well.

 

Code for controller with 51% coverage (psuIdRequestController):

public class psuIdRequestController {
 private String requestid;
    public Participant_ID_Request__c participantmgr;
    public String strStatus;
    public User user;
    public Contact contactBusiness;
    public Contact contactTechnical;
    public Contact contactFinance;
    public Contact contactTreasury;
    public String comment;
    public String approver;
    public Date approvalDate;
    
    
    public psuIdRequestController(ApexPages.StandardController stdController) {
        requestid = ApexPages.currentPage().getparameters().get('requestid');

        //Fetch participant for Participant ID Request record.
        participantmgr = [select Id, Name, DCF_Approval_Due_Date__c,
                        Business_DCF_Approver__c, Technical_DCF_Approver__c, Finance_DCF_Approver__c, Treasury_DCF_Approver__c,
                        Business_DCF_Approval__c, Technical_DCF_Approval__c, Finance_DCF_Approval__c, Treasury_DCF_Approval__c,
                        Business_DCF_Approval_Date__c, Technical_DCF_Approval_Date__c, Finance_DCF_Approval_Date__c, Treasury_DCF_Approval_Date__c,
                        Business_DCF_Comments__c, Technical_DCF_Comments__c, Finance_DCF_Comments__c, Treasury_DCF_Comments__c      
                        from Participant_ID_Request__c where Id =:requestid limit 1];

     try{
        contactBusiness = [select Id, Name from Contact where Id =: participantmgr.Business_DCF_Approver__c limit 1];
        contactTechnical = [select Id, Name from Contact where Id =: participantmgr.Technical_DCF_Approver__c limit 1];
        contactFinance = [select Id, Name from Contact where Id =: participantmgr.Finance_DCF_Approver__c limit 1];
        contactTreasury = [select Id, Name from Contact where Id =: participantmgr.Treasury_DCF_Approver__c limit 1];
        
        }
    catch(QueryException e){
     // System.assert(false,'You must be assigned as an approver for this participant.');    
        
        }
    
    }
  
    public Participant_ID_Request__c getparticipant(){
        return participantmgr;
    }
    
    public void Approve(){
        setStatus('Approved');      
    }
    public void Reject(){
        setStatus('Rejected');
    }
    public String getUserName(){
        return UserInfo.getName();
    }
    public String getStatus(){ 
        if(UserInfo.getName() == contactBusiness.Name ){
                return participantmgr.Business_DCF_Approval__c;
            }
            else if (UserInfo.getName() == contactTechnical.Name ){
                return participantmgr.Technical_DCF_Approval__c;
            }
            else if (UserInfo.getName() == contactFinance.Name ){
                return participantmgr.Finance_DCF_Approval__c;
            }
            else if (participantmgr.Treasury_DCF_Approver__c <> Null ){
                if (UserInfo.getName() == contactTreasury.Name ){
                    return participantmgr.Treasury_DCF_Approval__c;
                }
            }
        return strStatus;
    }
    public void setStatus(String status){
    
        if(UserInfo.getName() == contactBusiness.Name ){
            participantmgr.Business_DCF_Approval__c = status;
            participantmgr.Business_DCF_Comments__c = comment;
            participantmgr.Business_DCF_Approval_Date__c = approvalDate;
            update participantmgr;
        }
        else if (UserInfo.getName() == contactTechnical.Name ){
            participantmgr.Technical_DCF_Approval__c = status;
            participantmgr.Technical_DCF_Comments__c = comment;
            participantmgr.Technical_DCF_Approval_Date__c = approvalDate;
            update participantmgr;
        }
        else if (UserInfo.getName() == contactFinance.Name ){
            participantmgr.Finance_DCF_Approval__c = status;
            participantmgr.Finance_DCF_Comments__c = comment;
            participantmgr.Finance_DCF_Approval_Date__c = approvalDate;
            update participantmgr;
        }
        else if (participantmgr.Treasury_DCF_Approver__c <> Null ){
            if (UserInfo.getName() == contactTreasury.Name ){
            participantmgr.Treasury_DCF_Approval__c = status;
            participantmgr.Treasury_DCF_Comments__c = comment;
            participantmgr.Treasury_DCF_Approval_Date__c = approvalDate;
            update participantmgr;
            }
        }
    }
            
    public String getParticipantName() {
        return participantmgr.Name;       
    }
    
    public String getComment(){
    
            if(UserInfo.getName() == contactBusiness.Name ){
                return participantmgr.Business_DCF_Comments__c ;
            }
            else if (UserInfo.getName() == contactTechnical.Name ){
                return participantmgr.Technical_DCF_Comments__c;
            }
            else if (UserInfo.getName() == contactFinance.Name ){
                return participantmgr.Finance_DCF_Comments__c;
            }
            else if (participantmgr.Treasury_DCF_Approver__c <> Null ){
                if (UserInfo.getName() == contactTreasury.Name ){
                    return participantmgr.Treasury_DCF_Comments__c;
                }
                else{
                    comment = '';
                    return comment; 
                }
            }
            else{
                comment = '';
                return comment; 
            }
    }
    
    public void setComment(String value){
        comment = value;        
    }
    
    public Date getapprovalDate(){
    
            if(UserInfo.getName() == contactBusiness.Name ){
                return participantmgr.Business_DCF_Approval_Date__c;
            }
            else if (UserInfo.getName() == contactTechnical.Name ){
                return participantmgr.Technical_DCF_Approval_Date__c;
            }
            else if (UserInfo.getName() == contactFinance.Name ){
                return participantmgr.Finance_DCF_Approval_Date__c;
            }
            else if (participantmgr.Treasury_DCF_Approver__c <> Null ){
                if (UserInfo.getName() == contactTreasury.Name ){
                    return participantmgr.Treasury_DCF_Approval_Date__c;
                }
                else{
                    approvalDate = null;
                    return approvalDate; 
                }
            }
            else{
                approvalDate = null;
                return approvalDate;
            } 
    }
    
    public String getApprover(){
            if(UserInfo.getName() == contactBusiness.Name ){
                return contactBusiness.Name;
            }
            else if (UserInfo.getName() == contactTechnical.Name ){
                return contactTechnical.Name;
            }
            else if (UserInfo.getName() == contactFinance.Name ){
                return contactFinance.Name;
            }
            else if (participantmgr.Treasury_DCF_Approver__c <> Null ){
                if (UserInfo.getName() == contactTreasury.Name ){
                    return contactTreasury.Name;
                }
                else{
                approver = 'Not Eligilble to approve';
                return approver; 
                }
            }
            else{
                approver = 'Not Eligilble to approve';
                return approver; 
            }
    }

}

 Code for test class (psuControllerTest):

@isTest
private class psuControllerTest
{
static testmethod void testPsuIdRequest() {
        Id profileid = [Select id from Profile where name = 'Customer Portal Manager Custom'].id;
        Account account = new Account(Name = 'Test Account'); 
        
        insert account; 
        Contact businessContact = new Contact(AccountID = account.id, FirstName = 'Test', LastName = 'BusinessUser', email = 'bustest@test.com' ); 
        Contact technicalContact = new Contact(AccountID = account.id, FirstName = 'Test', LastName = 'TechnicalUser', email = 'tectest@test.com' ); 
        Contact financeContact = new Contact(AccountID = account.id, FirstName = 'Test', LastName = 'FinanceUser', email = 'fintest@test.com' );
        Contact treasuryContact = new Contact(AccountID = account.id, FirstName = 'Test', LastName = 'TreasuryUser', email = 'tretest@test.com' ); 
        Contact[] contacts = new Contact[]{businessContact,technicalContact,financeContact,treasuryContact};
        insert contacts;

        User BusinessUser = new User(email='business@test.com', 
                                     contactid = businessContact.id, 
                                     profileid = profileid, 
                                     UserName='business@test.com', 
                                     alias='bususer', CommunityNickName='bususer',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test', 
                                     LastName = 'BusinessUser');
        User TechnicalUser = new User(email='technical@test.com', 
                                     contactid = technicalContact.id, 
                                     profileid = profileid, 
                                     UserName='technical@test.com', 
                                     alias='tecuser', CommunityNickName='tecuser',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test', 
                                     LastName = 'TechnicalUser');
        User FinanceUser = new User(email='finance@test.com', 
                                     contactid = financeContact.id, 
                                     profileid = profileid, 
                                     UserName='finance@test.com', 
                                     alias='finuser', CommunityNickName='finuser',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test', 
                                     LastName = 'FinanceUser');
        User TreasuryUser = new User(email='treasury@test.com', 
                                     contactid = treasuryContact.id, 
                                     profileid = profileid, 
                                     UserName='treasury@test.com', 
                                     alias='treuser', CommunityNickName='treuser',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test', 
                                     LastName = 'TreasuryUser');
        User[] users = new User[]{businessUser,technicalUser,financeUser,treasuryUser};
        insert users; 
        
        RecordType recreq = [select ID,Name from RecordType where Name = 'ID REQUEST: Draft Approved' and SObjectType = 'Participant_ID_Request__c'];

        
        Participant_ID_Request__c participantmgr = new Participant_ID_Request__c(
        recordtypeid=recreq.Id,
        Name='Test Deal1',
        OwnerId = BusinessUser.Id,
        Business_DCF_Approver__c = BusinessUser.ContactId,
        Technical_DCF_Approver__c = TechnicalUser.ContactId,
        Finance_DCF_Approver__c = FinanceUser.ContactId,
        Treasury_DCF_Approver__c = TreasuryUser.ContactId);        
        insert participantmgr;
                
        PageReference testpage = Page.psudcfreview;
        testpage.getparameters().put('requestid', participantmgr.id);
        Test.setCurrentPage(testpage);
        

        // Custom Controller
        ApexPages.StandardController con = new ApexPages.StandardController(participantmgr);
        
        // extension
        psuIdRequestController pnid = new psuIdRequestController(con);
        
        System.RunAs(BusinessUser){
        pnid.getparticipant();
        pnid.getUserName();
        pnid.getStatus();
        pnid.getParticipantName();
        pnid.getComment();
        pnid.setComment('testing');
        pnid.getapprovalDate();
        pnid.getApprover();
        pnid.approve();
        System.assertEquals('Approved', pnid.getStatus());
        }
    }
}

 

On my SFDC Sites project, I am trying to create a simple download link (i.e. user clicks link and is able to download zip file). When the user clicks the link, they get the standard download box. However, the file extension is lost meaning the user will have to rename it etc. If you are logged into SFDC, the file downloads properly with the ".zip" extension. It is lost when you download it directly from the Site.

 

What am I missing?

 

Visualforce Link:

<apex:outputlink disabled="{!IF(ConfirmLogos == false,true,false)}" value="{!$Resource.Logos}">

 Static Resource Name, MIME Type, Cache Control:

Logos
application/x-zip-compressed
Public

 

I am trying to attach a file on Save. The code works if the Attachment fields are filled out prior to hitting save. If all of the Attachment fields are not filled out, the record will save but the attachment doesn't.

 

This is a Sites project in which the "guest" user only has create/read access to the "AESK_Test" custom object. If I allow edit rights to the object, everything works.

 

Is there a way to have the record perform the regular validation (i.e. error if form fields and Attachment fields are not filled out), save the record, and then attach the Attachment? If not, is there a way to perform validaiton on just the Attachment fields which would ensure all three fields are filled out prior to saving?

 

Snippet of my Visualforce Page:

          <apex:pageBlockSectionItem >
            <apex:outputLabel value="File Name" for="fileName"/>
            <apex:inputText value="{!attachment.name}" id="fileName" required="true"/>
          </apex:pageBlockSectionItem>
          
          
          <apex:pageBlockSectionItem >
            <apex:outputLabel value="Description" for="description"/>
            <apex:inputTextarea value="{!attachment.description}" id="description" required="true"/>
          </apex:pageBlockSectionItem>          
          
 
          <apex:pageBlockSectionItem >
            <apex:outputLabel value="File" for="file"/>
            <apex:inputFile value="{!attachment.body}" id="file" required="true"/>
          </apex:pageBlockSectionItem>

 

Full Controller:

public class AESK_Test {
 
    //Variables
    public SafeK_Certification__c skTest;
    public String test_us001vereq {get; set;}
    public String test_us001veres {get; set;}
    public String test_us001pareq {get; set;}
    public String test_us001pares {get; set;}    
    public String test_us002vereq {get; set;}
    public String test_us002veres {get; set;}  
    public String test_us002pareq {get; set;}
    public String test_us002pares {get; set;}    
    public String test_us003vereq {get; set;}
    public String test_us003veres {get; set;} 
    public String test_us003pareq {get; set;}
    public String test_us003pares {get; set;}     
    public String test_us005vereq {get; set;}
    public String test_us005veres {get; set;}  
    public String test_us005pareq {get; set;}
    public String test_us005pares {get; set;}   
    
    public String test_tc01crreq {get; set;} 
    public String test_tc01crres {get; set;}  
    public String test_tc02vereq {get; set;} 
    public String test_tc02veres {get; set;} 
    public String test_tc02pareq {get; set;} 
    public String test_tc02pares {get; set;} 
    public String test_tc04vereq {get; set;} 
    public String test_tc04veres {get; set;} 
    public String test_tc04pareq {get; set;} 
    public String test_tc04pares {get; set;}    
    public String test_tc05avereq {get; set;} 
    public String test_tc05averes {get; set;} 
    public String test_tc05apareq {get; set;} 
    public String test_tc05apares {get; set;}   
    public String test_tc08vereq {get; set;} 
    public String test_tc08veres {get; set;} 
    public String test_tc08pareq {get; set;} 
    public String test_tc08pares {get; set;}   
    public String test_tc09vereq {get; set;} 
    public String test_tc09veres {get; set;} 
    public String test_tc09pareq {get; set;} 
    public String test_tc09pares {get; set;} 
    public String test_tc11vereq {get; set;} 
    public String test_tc11veres {get; set;} 
    public String test_tc11pareq {get; set;} 
    public String test_tc11pares {get; set;}   
    public String test_tc13vereq {get; set;} 
    public String test_tc13veres {get; set;} 
    public String test_tc13pareq {get; set;} 
    public String test_tc13pares {get; set;}  
    public String test_tc15vereq {get; set;} 
    public String test_tc15veres {get; set;} 
    public String test_tc15pareq {get; set;} 
    public String test_tc15pares {get; set;}                     
                          
    //Controller
    public AESK_Test(ApexPages.StandardController con){
        skTest = (SafeK_Certification__c)con.getRecord();
    }  
    
    //Attachment
    public Attachment attachment {
    get {
        if (attachment == null)
          attachment = new Attachment();
        return attachment;
    }
    set;
    }              

    //Validate, save, and return page
    public PageReference save() {    

            //attachment
            attachment.ParentId = skTest.Id; //the record the file is attached to
            attachment.OwnerId = UserInfo.getUserId();
            attachment.IsPrivate = false;  

        try {

            String pagert = ApexPages.currentPage().getParameters().get('RecordTypeId');
            /*Issuer*/
            if(pagert == '012Q00000004SoO') {
                skTest.RecordTypeId = '012Q00000004SoO';        
            }
            /*Merchant*/
            else if(pagert == '012Q00000004SoT') {
                skTest.RecordTypeId = '012Q00000004SoT';        
            }     
            /*ACS Vendor*/             
            else if(pagert == '012Q00000004SoY') {
                skTest.RecordTypeId = '012Q00000004SoY';        
            }
            /*MPI Vendor*/        
            else if(pagert == '012Q00000004SoU') {
                skTest.RecordTypeId = '012Q00000004SoU';        
            }             
            /*else {
                return null;
            } */
        
            //set field values
            skTest.US001__c = 'Start: US001VEReq' + '\n' + test_us001vereq + '\n' + 'Stop: US001VEReq' + '\n\n' + 'Start: US001VERes' + '\n' + test_us001veres + '\n' + 'Stop: US001VERes' + '\n\n' +
                                'Start: US001PAReq' + '\n' + test_us001pareq + '\n' + 'Stop: US001PAReq' + '\n\n' + 'Start: US001PARes' + '\n' + test_us001pares + '\n' + 'Stop: US001PARes';
                        
            skTest.US002__c = 'Start: US002VEReq' + '\n' + test_us002vereq + '\n' + 'Stop: US002VEReq' + '\n\n' + 'Start: US002VERes' + '\n' + test_us002veres + '\n' + 'Stop: US002VERes' + '\n\n' +
                                'Start: US002PAReq' + '\n' + test_us002pareq + '\n' + 'Stop: US002PAReq' + '\n\n' + 'Start: US002PARes' + '\n' + test_us002pares + '\n' + 'Stop: US002PARes';
            
            skTest.US003__c = 'Start: US003VEReq' + '\n' + test_us003vereq + '\n' + 'Stop: US003VEReq' + '\n\n' + 'Start: US003VERes' + '\n' + test_us003veres + '\n' + 'Stop: US003VERes' + '\n\n' +
                                'Start: US003PAReq' + '\n' + test_us003pareq + '\n' + 'Stop: US003PAReq' + '\n\n' + 'Start: US003PARes' + '\n' + test_us003pares + '\n' + 'Stop: US003PARes';
            
            skTest.US005__c = 'Start: US005VEReq' + '\n' + test_us005vereq + '\n' + 'Stop: US005VEReq' + '\n\n' + 'Start: US005VERes' + '\n' + test_us005veres + '\n' + 'Stop: US005VERes' + '\n\n' + 
                                'Start: US005PAReq' + '\n' + test_us005pareq + '\n' + 'Stop: US005PAReq' + '\n\n' + 'Start: US005PARes' + '\n' + test_us005pares + '\n' + 'Stop: US005PARes';                        

            skTest.TC01__c = 'Start: TC01CRReq' + '\n' + test_tc01crreq + '\n' + 'Stop: TC01CRReq' + '\n\n' + 'Start: TC01CRRes' + '\n' + test_tc01crres + '\n' + 'Stop: TC01CRRes';

            skTest.TC02__c = 'Start: TC02VEReq' + '\n' + test_tc02vereq + '\n' + 'Stop: TC02VEReq' + '\n\n' + 'Start: TC02VERes' + '\n' + test_tc02veres + '\n' + 'Stop: TC02VERes' + '\n\n' + 
                                'Start: TC02PAReq' + '\n' + test_tc02pareq + '\n' + 'Stop: TC02PAReq' + '\n\n' + 'Start: TC02PARes' + '\n' + test_tc02pares + '\n' + 'Stop: TC02PARes';                        
                                  
            skTest.TC04__c = 'Start: TC04VEReq' + '\n' + test_tc04vereq + '\n' + 'Stop: TC04VEReq' + '\n\n' + 'Start: TC04VERes' + '\n' + test_tc04veres + '\n' + 'Stop: TC04VERes' + '\n\n' + 
                                'Start: TC04PAReq' + '\n' + test_tc04pareq + '\n' + 'Stop: TC04PAReq' + '\n\n' + 'Start: TC04PARes' + '\n' + test_tc04pares + '\n' + 'Stop: TC04PARes';    

            skTest.TC05A__c = 'Start: TC05AVEReq' + '\n' + test_tc05avereq + '\n' + 'Stop: TC05AVEReq' + '\n\n' + 'Start: TC05AVERes' + '\n' + test_tc05averes + '\n' + 'Stop: TC05AVERes' + '\n\n' + 
                                'Start: TC05APAReq' + '\n' + test_tc05apareq + '\n' + 'Stop: TC05APAReq' + '\n\n' + 'Start: TC05APARes' + '\n' + test_tc05apares + '\n' + 'Stop: TC05APARes';                

            skTest.TC08__c = 'Start: TC08VEReq' + '\n' + test_tc08vereq + '\n' + 'Stop: TC08VEReq' + '\n\n' + 'Start: TC08VERes' + '\n' + test_tc08veres + '\n' + 'Stop: TC08VERes' + '\n\n' + 
                                'Start: TC08PAReq' + '\n' + test_tc08pareq + '\n' + 'Stop: TC08PAReq' + '\n\n' + 'Start: TC08PARes' + '\n' + test_tc08pares + '\n' + 'Stop: TC08PARes';    

            skTest.TC09__c = 'Start: TC09VEReq' + '\n' + test_tc09vereq + '\n' + 'Stop: TC09VEReq' + '\n\n' + 'Start: TC09VERes' + '\n' + test_tc09veres + '\n' + 'Stop: TC09VERes' + '\n\n' + 
                                'Start: TC09PAReq' + '\n' + test_tc09pareq + '\n' + 'Stop: TC09PAReq' + '\n\n' + 'Start: TC09PARes' + '\n' + test_tc09pares + '\n' + 'Stop: TC09PARes';    
                                
            skTest.TC11__c = 'Start: TC11VEReq' + '\n' + test_tc11vereq + '\n' + 'Stop: TC11VEReq' + '\n\n' + 'Start: TC11VERes' + '\n' + test_tc11veres + '\n' + 'Stop: TC11VERes' + '\n\n' + 
                                'Start: TC11PAReq' + '\n' + test_tc11pareq + '\n' + 'Stop: TC11PAReq' + '\n\n' + 'Start: TC11PARes' + '\n' + test_tc11pares + '\n' + 'Stop: TC11PARes';                                                

            skTest.TC13__c = 'Start: TC13VEReq' + '\n' + test_tc13vereq + '\n' + 'Stop: TC13VEReq' + '\n\n' + 'Start: TC13VERes' + '\n' + test_tc13veres + '\n' + 'Stop: TC13VERes' + '\n\n' + 
                                'Start: TC13PAReq' + '\n' + test_tc13pareq + '\n' + 'Stop: TC13PAReq' + '\n\n' + 'Start: TC13PARes' + '\n' + test_tc13pares + '\n' + 'Stop: TC13PARes';     

            skTest.TC15__c = 'Start: TC15VEReq' + '\n' + test_tc15vereq + '\n' + 'Stop: TC15VEReq' + '\n\n' + 'Start: TC15VERes' + '\n' + test_tc15veres + '\n' + 'Stop: TC15VERes' + '\n\n' + 
                                'Start: TC15PAReq' + '\n' + test_tc15pareq + '\n' + 'Stop: TC15PAReq' + '\n\n' + 'Start: TC15PARes' + '\n' + test_tc15pares + '\n' + 'Stop: TC15PARes'; 
                                                                                                       
            insert skTest;                                                            
            insert attachment; 
        } 
        catch (DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }
        finally {
            attachment = new Attachment();
        }
    return page.aesktestconfirm; 
    } 
}

 

I am trying to attach a file on Save. The code works if the Attachment fields are filled out prior to hitting save. If all of the Attachment fields are not filled out, the record will save but the attachment doesn't.

 

This is a Sites project in which the "guest" user only has create/read access to the "AESK_Test" custom object. If I allow edit rights to the object, everything works.

 

Is there a way to have the record perform the regular validation (i.e. error if form fields and Attachment fields are not filled out), save the record, and then attach the Attachment? If not, is there a way to perform validaiton on just the Attachment fields which would ensure all three fields are filled out prior to saving?

 

Snippet of my Visualforce Page:

          <apex:pageBlockSectionItem >
            <apex:outputLabel value="File Name" for="fileName"/>
            <apex:inputText value="{!attachment.name}" id="fileName" required="true"/>
          </apex:pageBlockSectionItem>
          
          
          <apex:pageBlockSectionItem >
            <apex:outputLabel value="Description" for="description"/>
            <apex:inputTextarea value="{!attachment.description}" id="description" required="true"/>
          </apex:pageBlockSectionItem>          
          
 
          <apex:pageBlockSectionItem >
            <apex:outputLabel value="File" for="file"/>
            <apex:inputFile value="{!attachment.body}" id="file" required="true"/>
          </apex:pageBlockSectionItem>

 

Full Controller:

public class AESK_Test {
 
    //Variables
    public SafeK_Certification__c skTest;
    public String test_us001vereq {get; set;}
    public String test_us001veres {get; set;}
    public String test_us001pareq {get; set;}
    public String test_us001pares {get; set;}    
    public String test_us002vereq {get; set;}
    public String test_us002veres {get; set;}  
    public String test_us002pareq {get; set;}
    public String test_us002pares {get; set;}    
    public String test_us003vereq {get; set;}
    public String test_us003veres {get; set;} 
    public String test_us003pareq {get; set;}
    public String test_us003pares {get; set;}     
    public String test_us005vereq {get; set;}
    public String test_us005veres {get; set;}  
    public String test_us005pareq {get; set;}
    public String test_us005pares {get; set;}   
    
    public String test_tc01crreq {get; set;} 
    public String test_tc01crres {get; set;}  
    public String test_tc02vereq {get; set;} 
    public String test_tc02veres {get; set;} 
    public String test_tc02pareq {get; set;} 
    public String test_tc02pares {get; set;} 
    public String test_tc04vereq {get; set;} 
    public String test_tc04veres {get; set;} 
    public String test_tc04pareq {get; set;} 
    public String test_tc04pares {get; set;}    
    public String test_tc05avereq {get; set;} 
    public String test_tc05averes {get; set;} 
    public String test_tc05apareq {get; set;} 
    public String test_tc05apares {get; set;}   
    public String test_tc08vereq {get; set;} 
    public String test_tc08veres {get; set;} 
    public String test_tc08pareq {get; set;} 
    public String test_tc08pares {get; set;}   
    public String test_tc09vereq {get; set;} 
    public String test_tc09veres {get; set;} 
    public String test_tc09pareq {get; set;} 
    public String test_tc09pares {get; set;} 
    public String test_tc11vereq {get; set;} 
    public String test_tc11veres {get; set;} 
    public String test_tc11pareq {get; set;} 
    public String test_tc11pares {get; set;}   
    public String test_tc13vereq {get; set;} 
    public String test_tc13veres {get; set;} 
    public String test_tc13pareq {get; set;} 
    public String test_tc13pares {get; set;}  
    public String test_tc15vereq {get; set;} 
    public String test_tc15veres {get; set;} 
    public String test_tc15pareq {get; set;} 
    public String test_tc15pares {get; set;}                     
                          
    //Controller
    public AESK_Test(ApexPages.StandardController con){
        skTest = (SafeK_Certification__c)con.getRecord();
    }  
    
    //Attachment
    public Attachment attachment {
    get {
        if (attachment == null)
          attachment = new Attachment();
        return attachment;
    }
    set;
    }              

    //Validate, save, and return page
    public PageReference save() {    

            //attachment
            attachment.ParentId = skTest.Id; //the record the file is attached to
            attachment.OwnerId = UserInfo.getUserId();
            attachment.IsPrivate = false;  

        try {

            String pagert = ApexPages.currentPage().getParameters().get('RecordTypeId');
            /*Issuer*/
            if(pagert == '012Q00000004SoO') {
                skTest.RecordTypeId = '012Q00000004SoO';        
            }
            /*Merchant*/
            else if(pagert == '012Q00000004SoT') {
                skTest.RecordTypeId = '012Q00000004SoT';        
            }     
            /*ACS Vendor*/             
            else if(pagert == '012Q00000004SoY') {
                skTest.RecordTypeId = '012Q00000004SoY';        
            }
            /*MPI Vendor*/        
            else if(pagert == '012Q00000004SoU') {
                skTest.RecordTypeId = '012Q00000004SoU';        
            }             
            /*else {
                return null;
            } */
        
            //set field values
            skTest.US001__c = 'Start: US001VEReq' + '\n' + test_us001vereq + '\n' + 'Stop: US001VEReq' + '\n\n' + 'Start: US001VERes' + '\n' + test_us001veres + '\n' + 'Stop: US001VERes' + '\n\n' +
                                'Start: US001PAReq' + '\n' + test_us001pareq + '\n' + 'Stop: US001PAReq' + '\n\n' + 'Start: US001PARes' + '\n' + test_us001pares + '\n' + 'Stop: US001PARes';
                        
            skTest.US002__c = 'Start: US002VEReq' + '\n' + test_us002vereq + '\n' + 'Stop: US002VEReq' + '\n\n' + 'Start: US002VERes' + '\n' + test_us002veres + '\n' + 'Stop: US002VERes' + '\n\n' +
                                'Start: US002PAReq' + '\n' + test_us002pareq + '\n' + 'Stop: US002PAReq' + '\n\n' + 'Start: US002PARes' + '\n' + test_us002pares + '\n' + 'Stop: US002PARes';
            
            skTest.US003__c = 'Start: US003VEReq' + '\n' + test_us003vereq + '\n' + 'Stop: US003VEReq' + '\n\n' + 'Start: US003VERes' + '\n' + test_us003veres + '\n' + 'Stop: US003VERes' + '\n\n' +
                                'Start: US003PAReq' + '\n' + test_us003pareq + '\n' + 'Stop: US003PAReq' + '\n\n' + 'Start: US003PARes' + '\n' + test_us003pares + '\n' + 'Stop: US003PARes';
            
            skTest.US005__c = 'Start: US005VEReq' + '\n' + test_us005vereq + '\n' + 'Stop: US005VEReq' + '\n\n' + 'Start: US005VERes' + '\n' + test_us005veres + '\n' + 'Stop: US005VERes' + '\n\n' + 
                                'Start: US005PAReq' + '\n' + test_us005pareq + '\n' + 'Stop: US005PAReq' + '\n\n' + 'Start: US005PARes' + '\n' + test_us005pares + '\n' + 'Stop: US005PARes';                        

            skTest.TC01__c = 'Start: TC01CRReq' + '\n' + test_tc01crreq + '\n' + 'Stop: TC01CRReq' + '\n\n' + 'Start: TC01CRRes' + '\n' + test_tc01crres + '\n' + 'Stop: TC01CRRes';

            skTest.TC02__c = 'Start: TC02VEReq' + '\n' + test_tc02vereq + '\n' + 'Stop: TC02VEReq' + '\n\n' + 'Start: TC02VERes' + '\n' + test_tc02veres + '\n' + 'Stop: TC02VERes' + '\n\n' + 
                                'Start: TC02PAReq' + '\n' + test_tc02pareq + '\n' + 'Stop: TC02PAReq' + '\n\n' + 'Start: TC02PARes' + '\n' + test_tc02pares + '\n' + 'Stop: TC02PARes';                        
                                  
            skTest.TC04__c = 'Start: TC04VEReq' + '\n' + test_tc04vereq + '\n' + 'Stop: TC04VEReq' + '\n\n' + 'Start: TC04VERes' + '\n' + test_tc04veres + '\n' + 'Stop: TC04VERes' + '\n\n' + 
                                'Start: TC04PAReq' + '\n' + test_tc04pareq + '\n' + 'Stop: TC04PAReq' + '\n\n' + 'Start: TC04PARes' + '\n' + test_tc04pares + '\n' + 'Stop: TC04PARes';    

            skTest.TC05A__c = 'Start: TC05AVEReq' + '\n' + test_tc05avereq + '\n' + 'Stop: TC05AVEReq' + '\n\n' + 'Start: TC05AVERes' + '\n' + test_tc05averes + '\n' + 'Stop: TC05AVERes' + '\n\n' + 
                                'Start: TC05APAReq' + '\n' + test_tc05apareq + '\n' + 'Stop: TC05APAReq' + '\n\n' + 'Start: TC05APARes' + '\n' + test_tc05apares + '\n' + 'Stop: TC05APARes';                

            skTest.TC08__c = 'Start: TC08VEReq' + '\n' + test_tc08vereq + '\n' + 'Stop: TC08VEReq' + '\n\n' + 'Start: TC08VERes' + '\n' + test_tc08veres + '\n' + 'Stop: TC08VERes' + '\n\n' + 
                                'Start: TC08PAReq' + '\n' + test_tc08pareq + '\n' + 'Stop: TC08PAReq' + '\n\n' + 'Start: TC08PARes' + '\n' + test_tc08pares + '\n' + 'Stop: TC08PARes';    

            skTest.TC09__c = 'Start: TC09VEReq' + '\n' + test_tc09vereq + '\n' + 'Stop: TC09VEReq' + '\n\n' + 'Start: TC09VERes' + '\n' + test_tc09veres + '\n' + 'Stop: TC09VERes' + '\n\n' + 
                                'Start: TC09PAReq' + '\n' + test_tc09pareq + '\n' + 'Stop: TC09PAReq' + '\n\n' + 'Start: TC09PARes' + '\n' + test_tc09pares + '\n' + 'Stop: TC09PARes';    
                                
            skTest.TC11__c = 'Start: TC11VEReq' + '\n' + test_tc11vereq + '\n' + 'Stop: TC11VEReq' + '\n\n' + 'Start: TC11VERes' + '\n' + test_tc11veres + '\n' + 'Stop: TC11VERes' + '\n\n' + 
                                'Start: TC11PAReq' + '\n' + test_tc11pareq + '\n' + 'Stop: TC11PAReq' + '\n\n' + 'Start: TC11PARes' + '\n' + test_tc11pares + '\n' + 'Stop: TC11PARes';                                                

            skTest.TC13__c = 'Start: TC13VEReq' + '\n' + test_tc13vereq + '\n' + 'Stop: TC13VEReq' + '\n\n' + 'Start: TC13VERes' + '\n' + test_tc13veres + '\n' + 'Stop: TC13VERes' + '\n\n' + 
                                'Start: TC13PAReq' + '\n' + test_tc13pareq + '\n' + 'Stop: TC13PAReq' + '\n\n' + 'Start: TC13PARes' + '\n' + test_tc13pares + '\n' + 'Stop: TC13PARes';     

            skTest.TC15__c = 'Start: TC15VEReq' + '\n' + test_tc15vereq + '\n' + 'Stop: TC15VEReq' + '\n\n' + 'Start: TC15VERes' + '\n' + test_tc15veres + '\n' + 'Stop: TC15VERes' + '\n\n' + 
                                'Start: TC15PAReq' + '\n' + test_tc15pareq + '\n' + 'Stop: TC15PAReq' + '\n\n' + 'Start: TC15PARes' + '\n' + test_tc15pares + '\n' + 'Stop: TC15PARes'; 
                                                                                                       
            insert skTest;                                                            
            insert attachment; 
        } 
        catch (DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }
        finally {
            attachment = new Attachment();
        }
    return page.aesktestconfirm; 
    } 
}

 

I have a site with a sidebar which populates the URL using the Query String Parameter. The issue is when the validation rules fire, the "return null;" in the custom controller "refreshes" the page and the query string parameter values are lost. Without the query string parametrs, the validation prevents the record from being saved. I may not be using the query string parameter correctly. Any links, suggestions, code examples etc. is much appreciated.

 

Visualforce Page Code which populates Query String Parameter:

<apex:outputlink value="{!URLFOR($Page.aeskisenroll) + '?RecordTypeId=012Q00000004So4'}">Enrollment</apex:outputlink>

Which makes the site URL look like this:

http://testing.somesite.cs3.force.com/aeskseenroll?RecordTypeId=012Q00000004So4

 When a validation rule fires, the URL incorrectly removes the query string parameters and looks like this:

http://testing.somesite.cs3.force.com/aeskseenroll

My Controller:

 

public class AESK_Enroll {
  
    
    /*Variables*/
    public AESK_Enrollment__c skEnroll;
    
    /*Controller*/
    /*ApexPages.StandardController controller;*/
    public AESK_Enroll(ApexPages.StandardController con){
        ApexPages.StandardController controller;         
        controller = con;        
        skEnroll = (AESK_Enrollment__c)controller.getRecord();                         

    }           

    /*Validate, save, and return page*/
    public PageReference save() {
    String pagert = ApexPages.currentPage().getParameters().get('RecordTypeId'); 
            try {             
            /*Issuer*/
            if(pagert == '012Q00000004So4') {
                skEnroll.RecordTypeId = '012Q00000004So4';
                skEnroll.AESK_Account_Type__c = 'Issuer';        
            }
            /*Merchant*/
            else if(pagert == '012Q00000004So9') {
                skEnroll.RecordTypeId = '012Q00000004So9';
                skEnroll.AESK_Account_Type__c = 'Merchant';        
            }     
            /*ACS Vendor*/             
            else if(pagert == '012Q00000004SoE') {
                skEnroll.RecordTypeId = '012Q00000004SoE';
                skEnroll.AESK_Account_Type__c = 'ACS Vendor';        
            }
            /*MPI Vendor*/        
            else if(pagert == '012Q00000004SoJ') {
                skEnroll.RecordTypeId = '012Q00000004SoJ';
                skEnroll.AESK_Account_Type__c = 'MPI Vendor';        
            }             
            else {
                return null;
            }                
           
            insert skEnroll;
        } 
        catch (DMLException e) {            
            ApexPages.addMessages(e);            
            return null;            
        }
        return page.aeskenrollconfirm; 
    }        
}

 

 

I have a site with a sidebar which populates the URL using the Query String Parameter. This allows me to set the RecordType upon save etc. My issue is when the validation rules fire, the page refreshes and the Query String Parameter values are lost. The Query String Parameters are used for validation purposes which means the record can not save until I figure out how to resolve this issue.

 

Visualforce Page Code which populates Query String Parameter:

 

<apex:outputlink value="{!URLFOR($Page.aeskisenroll) + '?RecordTypeId=012Q00000004So4'}">Enrollment</apex:outputlink>

Which makes the site URL look like this:

 

 

http://testing.somesite.cs3.force.com/aeskseenroll?RecordTypeId=012Q00000004So4

 When a validation rule fires, the URL looks like this:

 

http://testing.somesite.cs3.force.com/aeskseenroll

 My Controller:

 

public class AESK_Enroll {
  
    
    /*Variables*/
    public AESK_Enrollment__c skEnroll;
    
    /*Controller*/
    /*ApexPages.StandardController controller;*/
    public AESK_Enroll(ApexPages.StandardController con){
        ApexPages.StandardController controller;         
        controller = con;        
        skEnroll = (AESK_Enrollment__c)controller.getRecord();                         

    }           

    /*Validate, save, and return page*/
    public PageReference save() {
    String pagert = ApexPages.currentPage().getParameters().get('RecordTypeId'); 
            try {             
            /*Issuer*/
            if(pagert == '012Q00000004So4') {
                skEnroll.RecordTypeId = '012Q00000004So4';
                skEnroll.AESK_Account_Type__c = 'Issuer';        
            }
            /*Merchant*/
            else if(pagert == '012Q00000004So9') {
                skEnroll.RecordTypeId = '012Q00000004So9';
                skEnroll.AESK_Account_Type__c = 'Merchant';        
            }     
            /*ACS Vendor*/             
            else if(pagert == '012Q00000004SoE') {
                skEnroll.RecordTypeId = '012Q00000004SoE';
                skEnroll.AESK_Account_Type__c = 'ACS Vendor';        
            }
            /*MPI Vendor*/        
            else if(pagert == '012Q00000004SoJ') {
                skEnroll.RecordTypeId = '012Q00000004SoJ';
                skEnroll.AESK_Account_Type__c = 'MPI Vendor';        
            }             
            else {
                return null;
            }                
           
            insert skEnroll;
        } 
        catch (DMLException e) {            
            ApexPages.addMessages(e);            
            return null;            
        }
        return page.aeskenrollconfirm; 
    }        
}

 

 

 

 

 

 

Hello,

 

How do I set the Record Type ID (value) based off which Visualforce Page a user is currently viewing?

 

This is a Sites project. When a user is on the "enrollment" page and submits their form, I want the custom controller extension (or ?) to reference the Page ID to set the Record Type to "Enrollment" (i.e. Record Type Name = Enrollment, Record Type ID = 012Q00000004So4).

 

My Code (could be completely off, mashed a few things together from other forums):

 

public rtt() {

if(System.currentPageReference().getParameters().get('id')= "enrollment") {
  RecordType.ID = "012Q00000004So4";
  } 
}

My Error:

 

Error: Compile Error: line 84:60 no viable alternative at character '"' at line 84 column 60

  • September 30, 2010
  • Like
  • 0

For my Site, I want the user to be able to click, for example, the Enrollment link which will take the user to the Enrollment Page... but, I also want to set the record type based off which link is clicked as well. How do I accomplish this?

 

<apex:component >
  <div id = "menu_container">
    <div id = "menu">
      <ul>
        <li class="menu_header">Some Name
          <ul>
            <li><a href="http://testing.somename.cs3.force.com/enroll">Enrollment</a></li>
            <li><a href="http://testing.somename.cs3.force.com/cert">Certification</a></li>
          </ul>
        </li>                            
      </ul>
    </div>
  </div>
</apex:component>

 

  • September 24, 2010
  • Like
  • 0

I have two questions that should be pretty simple although I have spent good time trying to find the solution.

 

First: On my site I have a component acting as my sidebar with a set of links. When one of the links is clicked, I want it to dynamically set the record type. For example, if the user clicks the enrollment link, it would take them to the enrollment page, but I also want the record type to be set to "enrollment". Via the UI you can set record type via the URL but I do not know how to accomplish this via Sites.

 

<apex:component >
  <div id = "menu_container">
    <div id = "menu">
      <ul>
        <li class="menu_header">Some Name
          <ul>
            <li><a href="http://testing.somename.cs3.force.com/enroll">Enrollment</a></li>
            <li><a href="http://testing.somename.cs3.force.com/cert">Certification</a></li>
          </ul>
        </li>                            
      </ul>
    </div>
  </div>
</apex:component>

 

Second: I'm sure there is a better way of linking to pages vs. the static example above. I want to avoid scanning through the site if I change the name of a Page. Is there a better way of referencing a Page via a link?

 

Any assistance with code, ideas, and/or examples is much appreciated.

  • September 24, 2010
  • Like
  • 0

I have a checkbox that when checked, the section which contains a save button should appear using ajax render/rerender. What is wrong with my code? Also, I'm using DIVs to control look and feel... is there a better way to do this using panels etc?

 

Class:

public String test2 {get; set;}

 

Page:

      <div id = "body_row">
        <apex:pageblock id="test">
          <apex:pageBlockSection>
            <apex:pageBlockSectionItem >             
              <apex:inputCheckbox value="{!test2}" />
               <apex:actionsupport event="onclick" rerender="termsandconditions" />
            </apex:pageBlockSectionItem>
          </apex:pageBlockSection>
        </apex:pageblock>
      </div>
      
      <div id = "body_row">
        <apex:pageblock id="termsandconditions">
          <apex:messages />
          <apex:pageblockButtons location="bottom" rendered="{IF({!test2} == true,true,false)}">
            <apex:commandButton action="{!Save}" value="Submit Enrollment" />
          </apex:pageblockButtons>
        </apex:pageblock>
      </div>

 

  • September 03, 2010
  • Like
  • 0

I am utilizing Sites and my Visualforce pages use a custom object as the standard controller with an extension for additional functionality. 

 

How do I reference fields directly on a Visualforce page? For example, I have two fields that only have id's and no input value.

 

Example:

<apex:pageBlockSectionItem >
  <apex:outputLabel value="US001_VEReq" for="test_us001vereq" />
  <apex:inputTextarea id="test_us001vereq"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
  <apex:outputLabel value="US001_VERes" for="test_us001veres" />
  <apex:inputTextarea id="test_us001veres" />
</apex:pageBlockSectionItem>

 

I want to combine the input from these two Text Area Fields into one field which does have a value, meaning upon save the concatenated (combined) value will be entered (saved) into the database. 

 

Example:

<apex:pageBlockSectionItem >
  <apex:outputLabel value="US001" for="test_us001" />
  <apex:inputTextArea value="{!SK__c.US001__c}" id="test_us001" />
</apex:pageBlockSectionItem>

 

What options do I have to accomplish this task. I have spent 4 days looking at the forums, code examples, etc. and can not figure out how to make this work. Any suggestions, ideas, code examples, and/or links are much appreciated. Please let me know if this is unclear and I will provide more detail.

 

Also, for anyone familiar with MS Access Databases, this would be similar to bound/unbound fields and how to reference those fields within a form via VBA etc.

SFDC has a limit of 25 long text fields per object. Unfortunately, our project requires 40 long text fields. So, I am trying to take the values of two text area fields (unbound) and concatenate their values into a custom object long text field (bound) to stay within the SFDC limits. At this point, I am completely lost... can this be accomplished entirely within the Visualforce tags or should I be using a controller extension? How do I reference the unbound fields, meaning fields that are not directly related to the standard controller? Is Ajax the only option? Rerender?

 

If a standard controller extension is required, any help with the code to get me started would be great. I am a Apex/Visualforce noob, so any help is much appreciated in regards to examples, links, etc.

 

How do I get the two values from 'test_us001vereq' and 'test_us001veres' concatenated into the custom object field 'test_us001'?

 

<!-- unbound field test_us001vereq -->
<apex:pageBlockSectionItem >
  <apex:outputLabel value="US001_VEReq" for="test_us001vereq" />
  <apex:inputTextarea id="test_us001vereq"/>
</apex:pageBlockSectionItem>

<!-- unbound field test_us001veres -->             
<apex:pageBlockSectionItem >
  <apex:outputLabel value="US001_VERes" for="test_us001veres" />
  <apex:inputTextarea id="test_us001veres" />
</apex:pageBlockSectionItem>
      
<!-- bound field test_us001 -->
<apex:pageBlockSectionItem >
  <apex:outputLabel value="US001" for="test_us001" />
  <apex:inputTextArea value="{!AESK_Certification__c.US001__c}" id="test_us001" />
</apex:pageBlockSectionItem>

 

Hello SF,

 

I am new to building SF Sites and have a few questions on design. I currently have a basic two-column design (header, left menu, body, footer). I am using components to populate the header, footer, and menu so I don't have to re-write the code for each page etc. Rather than creating separate pages, I would like to use components to populate the body as well, which will usually be a form.

 

My question: Using the left menu html links, what is the best way to populate data in the body of the page? I want a user to click a left-nav link and then have the body of the page populate with the correct component (i.e. form) info etc. I have looked everywhere and am unable to locate info on this use-case. I found brief examples of Ajax using "rerender" but I can not figure out how to integrate this with my setup (i.e. which code goes where).

 

My logic/concept may be completely wrong so suggestions, example code, or links to tutorials are much appreciated.

 

 

I am a noob to Visualforce. Basically, I am pulling in the 18 Digit Contact ID via a Salesforce Page and am trying to figure out how to style the field to match the rest of the standard page layout. Even though I am using the standardStylesheet, the field does not inherit styling (field label right aligned, field text left aligned, etc.). Any help with the below code is much appreciated:

 

<apex:page standardController="Contact" standardStylesheets="true"> <style type="text/css"> body {background: #F3F3EC; font-style: arial; } </style> <apex:outputLabel >Contact ID</apex:outputLabel> <apex:outputfield value="{!Contact.Id}" /> </apex:page>

 

This is pretty simple although I am a complete newb to triggers and Apex code. I have a field "Contact18Dig" on the Contact object that I am trying to populate the 18 digit contact id to. Any time a new contact is created or the "Contact18Dig" field is modified, I want the "Contact18Dig" field to populate with the full contact ID. If I create a contact and then edit the record, this code works fine. But, it is not inserting the 18 digit contact upon creating a new contact.

 

Any assitance, guidance, or corrected code examples are much appreciated.

 

trigger ContactID18Digit on Contact (before insert, before update) { for(Contact c : Trigger.new) { if(c.Contact18Dig__c != c.id) { c.Contact18Dig__c = c.id; } } }

 

Hi, I'm fairly new to Triggers and am hoping someone can give me a bit of direction.

 

I want a custom field "Record_Mode__c" on Child Object B to be updated to value "Edit" when Parent Object A's custom field "Status__c" is updated to "Open". Basically, any time the parent record's status changes, I want the child record's Record Mode field to be updated accordingly.

 

The Record Mode change will then drive workflow that will flip record types and page layouts. I prefer to use out of the box solutions, but I cannot use cross object workflows as there is no master detail relationship between Parent Object A and Child Object B.

 

Any assistance with code or alternate solutions are much appreciated! 

Sites Explanation:

We have a sites project which is public. The public access settings allow our end-users to login via a guest license and enter their information (no authentication).

 

Sites URL Setup:

Default URL: http://something.force.com/xyzenrollment

Secure URL: https://something.secure.force.com/xyzenrollment

Custom Web Address: http://enroll.something.com

 

The Issue:

The Site is not secure. All information entered via the Site by our end-users needs to be secure (i.e. currently http, needs to be https).

 

Question:

How do I point the users to the Secure URL vs. the Default URL while still keeping the Custom Web Address masking? I changed the Administration Setup > Security Controls > Session Settings > Require secure connections (HTTPS) to checked, but this does not seem to do the trick.

How do you test messages? I'm getting no coverage for the lines highlighted in red. Any help with how to write a test condition for the below code is much appreciated.

 

public PageReference save() {
  try {
    if(skTest.Submission_Type__c == 'New Submission' && (attachment.name == '' || attachment.description == '' || attachment.body == null)) {
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'All upload fields are required.'));
    return null;
  }

 

Anyone know how to test Catch blocks. I've looked around for creating Catch test conditions but have been unsuccessful so far.

 

Code Snippet:

            insert skEnroll;
        } 
        catch (DMLException e) {            
            ApexPages.addMessages(e);            
            return null;
        }
        return page.aeskenrollconfirm; 
    }        
}

 

This code was created by another developer and I need to achieve higher coverage to deploy an unrelated project. My test class (psuControllerTest) is receiving a test failure. It looks like it does not like the last part of the code where the "Status" is set. Any help with correcting the test code is much appreciated.

 

Method Name:

psuControllerTest.testPsuIdRequest

 

Message:

System.DmlException: Update failed. First exception on row 0 with id a0HP0000001ivPOMAY; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []

 

Stack Trace:

Class.psuIdRequestController.setStatus: line 88, column 13 Class.psuIdRequestController.Approve: line 45, column 9 Class.psuControllerTest.testPsuIdRequest: line 176, column 9 External entry point

 

 

Test class snippet:

     static testMethod void hierarchyControllerTest() {
        Id profileid = [Select id from Profile where name = 'Customer Portal Manager Custom'].id;
        Account account = new Account(Name = 'Test Account'); 
        
        insert account; 
        Contact businessContact = new Contact(AccountID = account.id, FirstName = 'Test', LastName = 'BusinessUser', email = 'bustest@test.com' ); 
        Contact technicalContact = new Contact(AccountID = account.id, FirstName = 'Test', LastName = 'TechnicalUser', email = 'tectest@test.com' ); 
        Contact financeContact = new Contact(AccountID = account.id, FirstName = 'Test', LastName = 'FinanceUser', email = 'fintest@test.com' );
        Contact treasuryContact = new Contact(AccountID = account.id, FirstName = 'Test', LastName = 'TreasuryUser', email = 'tretest@test.com' ); 
        Contact[] contacts = new Contact[]{businessContact,technicalContact,financeContact,treasuryContact};
        insert contacts;

        User BusinessUser = new User(email='business@test.com', 
                                     contactid = businessContact.id, 
                                     profileid = profileid, 
                                     UserName='business@test.com', 
                                     alias='bususer', CommunityNickName='bususer',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test', 
                                     LastName = 'BusinessUser');
        User TechnicalUser = new User(email='technical@test.com', 
                                     contactid = technicalContact.id, 
                                     profileid = profileid, 
                                     UserName='technical@test.com', 
                                     alias='tecuser', CommunityNickName='tecuser',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test', 
                                     LastName = 'TechnicalUser');
        User FinanceUser = new User(email='finance@test.com', 
                                     contactid = financeContact.id, 
                                     profileid = profileid, 
                                     UserName='finance@test.com', 
                                     alias='finuser', CommunityNickName='finuser',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test', 
                                     LastName = 'FinanceUser');
        User InvalidUser = new User(email='treasury@test.com', 
                                     contactid = treasuryContact.id, 
                                     profileid = profileid, 
                                     UserName='treasury@test.com', 
                                     alias='treuser', CommunityNickName='treuser',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test', 
                                     LastName = 'TreasuryUser');
        User[] users = new User[]{businessUser,technicalUser,financeUser,InvalidUser};
        insert users;    
        //Create a Request
        Participant_ID_Request__c request = new Participant_ID_Request__c(
        Name='New Hierarchy Test',
        Business_Approver__c = BusinessUser.ContactId, 
        Techincal_Approver__c  = TechnicalUser.ContactId, 
        Finance_Approver__c = FinanceUser.ContactId,  
        Treasury_Hierarchy_Approver__c = InvalidUser.ContactId
        );
        insert request;
        
        //Create a Hierarchy
        Participant_Hierarchy__c hierarchy = new Participant_Hierarchy__c(
        Name='Hierarchy Test',
        Business_Approver__c = BusinessUser.ContactId, 
        Technical_Approver__c  = TechnicalUser.ContactId,  
        Finance_Approver__c = FinanceUser.ContactId,
        Treasury_Hierarchy_Approver__c = InvalidUser.ContactId,
        Business_Approval__c = 'Pending', 
        Technical_Approval__c = 'Pending', 
        Finance_Approval__c = 'Pending',
        Treasury_Approval__c = 'Pending',
        Treasury_Comments__c = 'Test',
        Business_Comments__c = 'Test', 
        Technical_Comments__c= 'Test', 
        Finance_Comments__c= 'Test',
        New_Participant__c = request.Id
        );
        insert hierarchy;
    
                
        // Test class Complete_Requirements_Status methods 
        ApexPages.standardController hierarchyCntl = new ApexPages.standardController(hierarchy);
        Test.setCurrentPageReference(new PageReference('Page.hierarchyreview')); 
        System.currentPageReference().getParameters().put('requestid', request.Id);
        psuHierarchyController reviewController = new psuHierarchyController(hierarchyCntl);
        Participant_Hierarchy__c objHierarchy = reviewController.gethierarchy();
            
         //Test as Portal User
        String strStatus; 
        
        System.RunAs(BusinessUser)
        {
            String strApprover = reviewController.getApprover();
            String strComment = reviewController.getComment();
            reviewController.setComment(strComment);
            strStatus = reviewController.getStatus();
        } //end RunAs

        System.RunAs(TechnicalUser)
        {
            String strApprover = reviewController.getApprover();
            String strComment = reviewController.getComment();
            reviewController.setComment(strComment);
            strStatus = reviewController.getStatus();
        } //end RunAs
        System.RunAs(FinanceUser)
        {
            String strApprover = reviewController.getApprover();
            String strComment = reviewController.getComment();
            reviewController.setComment(strComment);
            strStatus = reviewController.getStatus();
        } //end RunAs
        System.RunAs(InvalidUser)
        {
            String strApprover = reviewController.getApprover();
            String strComment = reviewController.getComment();
            reviewController.setComment(strComment);
            strStatus = reviewController.getStatus();
        } //end RunAs

        reviewController.approve();
            
        reviewController.reject();

        reviewController.setStatus(strStatus);
        
        String hn = reviewController.getHierarchyName();
        String approver = reviewController.getApprover();
        Attachment attachment = reviewController.attachment;
        Attachment[] attachments = reviewController.attachments;
        
    }

 

Hello,

 

How do I set the Record Type ID (value) based off which Visualforce Page a user is currently viewing?

 

This is a Sites project. When a user is on the "enrollment" page and submits their form, I want the custom controller extension (or ?) to reference the Page ID to set the Record Type to "Enrollment" (i.e. Record Type Name = Enrollment, Record Type ID = 012Q00000004So4).

 

My Code (could be completely off, mashed a few things together from other forums):

 

public rtt() {

if(System.currentPageReference().getParameters().get('id')= "enrollment") {
  RecordType.ID = "012Q00000004So4";
  } 
}

My Error:

 

Error: Compile Error: line 84:60 no viable alternative at character '"' at line 84 column 60

  • September 30, 2010
  • Like
  • 0

For my Site, I want the user to be able to click, for example, the Enrollment link which will take the user to the Enrollment Page... but, I also want to set the record type based off which link is clicked as well. How do I accomplish this?

 

<apex:component >
  <div id = "menu_container">
    <div id = "menu">
      <ul>
        <li class="menu_header">Some Name
          <ul>
            <li><a href="http://testing.somename.cs3.force.com/enroll">Enrollment</a></li>
            <li><a href="http://testing.somename.cs3.force.com/cert">Certification</a></li>
          </ul>
        </li>                            
      </ul>
    </div>
  </div>
</apex:component>

 

  • September 24, 2010
  • Like
  • 0

I have two questions that should be pretty simple although I have spent good time trying to find the solution.

 

First: On my site I have a component acting as my sidebar with a set of links. When one of the links is clicked, I want it to dynamically set the record type. For example, if the user clicks the enrollment link, it would take them to the enrollment page, but I also want the record type to be set to "enrollment". Via the UI you can set record type via the URL but I do not know how to accomplish this via Sites.

 

<apex:component >
  <div id = "menu_container">
    <div id = "menu">
      <ul>
        <li class="menu_header">Some Name
          <ul>
            <li><a href="http://testing.somename.cs3.force.com/enroll">Enrollment</a></li>
            <li><a href="http://testing.somename.cs3.force.com/cert">Certification</a></li>
          </ul>
        </li>                            
      </ul>
    </div>
  </div>
</apex:component>

 

Second: I'm sure there is a better way of linking to pages vs. the static example above. I want to avoid scanning through the site if I change the name of a Page. Is there a better way of referencing a Page via a link?

 

Any assistance with code, ideas, and/or examples is much appreciated.

  • September 24, 2010
  • Like
  • 0

I have a checkbox that when checked, the section which contains a save button should appear using ajax render/rerender. What is wrong with my code? Also, I'm using DIVs to control look and feel... is there a better way to do this using panels etc?

 

Class:

public String test2 {get; set;}

 

Page:

      <div id = "body_row">
        <apex:pageblock id="test">
          <apex:pageBlockSection>
            <apex:pageBlockSectionItem >             
              <apex:inputCheckbox value="{!test2}" />
               <apex:actionsupport event="onclick" rerender="termsandconditions" />
            </apex:pageBlockSectionItem>
          </apex:pageBlockSection>
        </apex:pageblock>
      </div>
      
      <div id = "body_row">
        <apex:pageblock id="termsandconditions">
          <apex:messages />
          <apex:pageblockButtons location="bottom" rendered="{IF({!test2} == true,true,false)}">
            <apex:commandButton action="{!Save}" value="Submit Enrollment" />
          </apex:pageblockButtons>
        </apex:pageblock>
      </div>

 

  • September 03, 2010
  • Like
  • 0

I am utilizing Sites and my Visualforce pages use a custom object as the standard controller with an extension for additional functionality. 

 

How do I reference fields directly on a Visualforce page? For example, I have two fields that only have id's and no input value.

 

Example:

<apex:pageBlockSectionItem >
  <apex:outputLabel value="US001_VEReq" for="test_us001vereq" />
  <apex:inputTextarea id="test_us001vereq"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
  <apex:outputLabel value="US001_VERes" for="test_us001veres" />
  <apex:inputTextarea id="test_us001veres" />
</apex:pageBlockSectionItem>

 

I want to combine the input from these two Text Area Fields into one field which does have a value, meaning upon save the concatenated (combined) value will be entered (saved) into the database. 

 

Example:

<apex:pageBlockSectionItem >
  <apex:outputLabel value="US001" for="test_us001" />
  <apex:inputTextArea value="{!SK__c.US001__c}" id="test_us001" />
</apex:pageBlockSectionItem>

 

What options do I have to accomplish this task. I have spent 4 days looking at the forums, code examples, etc. and can not figure out how to make this work. Any suggestions, ideas, code examples, and/or links are much appreciated. Please let me know if this is unclear and I will provide more detail.

 

Also, for anyone familiar with MS Access Databases, this would be similar to bound/unbound fields and how to reference those fields within a form via VBA etc.

Hello SF,

 

I am new to building SF Sites and have a few questions on design. I currently have a basic two-column design (header, left menu, body, footer). I am using components to populate the header, footer, and menu so I don't have to re-write the code for each page etc. Rather than creating separate pages, I would like to use components to populate the body as well, which will usually be a form.

 

My question: Using the left menu html links, what is the best way to populate data in the body of the page? I want a user to click a left-nav link and then have the body of the page populate with the correct component (i.e. form) info etc. I have looked everywhere and am unable to locate info on this use-case. I found brief examples of Ajax using "rerender" but I can not figure out how to integrate this with my setup (i.e. which code goes where).

 

My logic/concept may be completely wrong so suggestions, example code, or links to tutorials are much appreciated.