• dfire
  • NEWBIE
  • 150 Points
  • Member since 2011

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

Hi All

 

I have try to work on Force.com site.

 

I need to use custom stylesheet on the page. So I try to study by myself from http://www.salesforce.com/us/developer/docs/pages/Content/pages_styling_custom.htm

 

I have some problem that I cannot use custom css file on my page.

 

Below this is my VF page code.

 

 

<apex:page showHeader="false" standardStylesheets="false">
	<apex:stylesheet value="{!$Resource.customCSS}" />

	<h1>Testing Custom Stylesheets</h1>

	<p>This text could go on forever...<BR /><BR />But it won't!</p>

	<apex:outputLink value="https://www.salesforce.com" styleClass="newLink">
		Click here to switch to www.salesforce.com
	</apex:outputLink>

</apex:page>

 And customCSS file is : 

 

h1 { color: #FF0000; }

p { background-color: #EEEECC; }

newLink { color: #FF6600; font-weight: bold;}

 for the result http://crmmarket-developer-edition.na7.force.com/index

 

 

the code result is :

 

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
 
 
	<html><head><script src="/index/jslibrary/1296001444000/JiffyStubs.js" type="text/javascript"></script><link class="user" href="/index/resource/1299612283000/customCSS" rel="stylesheet" type="text/css" /></head><h1>Testing Custom Stylesheets</h1> 
 
	<p>This text could go on forever...<BR /><BR />But it won't!</p><a href="https://www.salesforce.com" class="newLink"> 
		Click here to switch to www.salesforce.com</a></html>

 

 

I think h1 should show the text in the red but it dose not.

 

Please advise me that what I am wrong?

 

Below is a simple VF page and Controller. You will not on the Controller I hard code the

 

 

where nights__c = 4

 

 I want to make this dynamic using a input field on the VF page.

 

 

 

VF Page

 

 

<apex:page controller="Resmanager">
    <apex:sectionHeader title="Availability Search"/> 
                 
              <apex:pageBlock title="Reservations">
              <apex:pageBlockSection >
                    <apex:pageBlockTable value="{!Reservations}" var="res">
                        <apex:column value="{!res.Start_Date__c}"  />
                        <apex:column value="{!res.End_Date__c}"  />
                        <apex:column value="{!res.Nights__c}"  />
                    </apex:pageBlockTable>
               </apex:pageBlockSection>
               
               </apex:pageBlock>

</apex:page>

 

 

APEX Controller

 

 

public class Resmanager {
    
    public List<Reservation__c> getReservations(){
        List<Reservation__c> listBd=[select r.id, r.Start_Date__c, R.End_Date__c, nights__c from Reservation__c r where nights__c = 4];
        return listBd;   
    }
   
}

 

 

 

I want to create a many-many relationship between Student and Class. I have a junction obj call StudentClassJunction which creates the link. Then I have a related list in Class called Students and a related list in Student called Classes.

 

Fine. However the "New" button on both of them says "New StudentClassJunction" which I obviously don't want. On the Classes related list on the Student record page I want it to say "New Class" and on the Students related list on the Class record I want it to say "New Student."

 

Any ideas how to do this?

 

Thanks.

  • July 06, 2011
  • Like
  • 0

As we are using PersonAccounts, there is a bug that won't let us use <apex:inputfield> for picklists. Therefore we need to use <apex:selectList> and bind it to the field. Fine.

 

When we try to create a multi-select picklist, it uses the standard HTML multi-select list, but not the SFDC mutli-select with 2 columns and add/remove arrows in between. And yes, I have multiselect=true set in my selectList tag.

 

Anybody know a way to do this?

 

Thanks.

  • May 17, 2011
  • Like
  • 0

When trying to deploy my custom controller and VF pages for our Sites site from Eclipse, when running the test cases I get the following error

StudentApplicationControllerTest.testController System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, entity type cannot be inserted: Person Account: []

According to the WSDL docs this is a permissions error as follows:
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY
You do not have permission to create, update, or activate the specified record.

This doesn't make sense as I am the System Admin and have permissions to all objects, fields, record types, etc.

 

Here is the getter that creates the Person Account record

 

 

    public Account getStudent() {
        if(student == null) {
            RecordType recType = getPersonAccountRecordTypeId();            
            student = new Account(recordtypeid=recType.id,web_submission__c=true); 
            //student = new Account(); 
        }
        return student;
    }

   RecordType getPersonAccountRecordTypeId() {
    	return [select id,name,sobjectType,ispersontype from recordType where ispersontype=true and sobjectType='account' limit 1];
    }

 

 

 

This is preventing our move to production and is critical.

 

Any help is much appreciated.

  • May 04, 2011
  • Like
  • 0

I have a field which is a checkbox but in my VF page I want to display it as a radio with the options of Yes or No

 

I am using selectradio but the problem is it is defaulting to selecting the No value. I believe the reason for this is that since the checkbox itself is not set, its value is false which is then being reflected in the radio. This is expected behavior, I guess. But I need it so that no value is selected, so we can force validation to verify they chose something.

 

Anybody have an idea how to do this?

 

 

	public List<SelectOption> getYesNo() { 
		List<SelectOption> options = new List<SelectOption>();
		 options.add(new SelectOption('true', 'Yes'));
		 options.add(new SelectOption('false', 'No'));
		return options;
	}

 

<apex:SelectRadio id="radio" value="{!myobj.mycheckboxfield__c}">
     <apex:selectOptions value="{!yesno}"/>
</apex:SelectRadio>

 

 

 

  • April 29, 2011
  • Like
  • 0

We have an online application using Sites. Our applicatants come from a variety of countries with differing locals. Some are used to mm/dd/yyyy and others dd/mm/yyyy.

 

Is there any way to set a date field format to something more universal?

 

Since puting in 5/4/11 could mean May 4th or April 5th, we would like to use a format like 03 Jan 11

 

Is such a thing possible and if so, how?

 

thanks.

  • April 28, 2011
  • Like
  • 0

This is a top requirement from our Dean. We have Student (Person Account) records that have a formula field that uses the IMAGE formula on a URL of the photo of the student that we store on S3. It works fine in regular SFDC both viewed from PC browser and iphone browser, however when viewing in the iphone app it just says somthing like

 

imgsrc=http://...

 

Since the image is showing up in the iphone's browser, the issue is not the phone blocking the images. And I set the data limit to be high enough to include the image.

 

Anybody dealt with this?

 

Thanks.

  • April 08, 2011
  • Like
  • 0

Being that cross object reporting in the standard reporting mechanism is, well, pathetic. Is there any way to create a report driven by SOQL queries that can be viewed and stored like regular reports or are we talking visualforce with a custom controller?

  • April 06, 2011
  • Like
  • 0

I am writing a trigger that, among other things, is supposed to check if a record exists for my custom object Statistic__c with the same date and level as the one trying to be inserted.

 

Simply I want to grab the date and level from the trigger do a SOQL to find existing records and return an error to the record trying to be inserted/updated if a match is found. No problem, right?

 

Well as I am trying to bulkify, this is getting much more complicated. The issue is once I have my list of existing records how I then sync up to the list of statistic__c to send errors to the proper one. So I thought to create a map where the key = date+level and the value is the sobject. So that would work fine, I think except what if in the bulk upload are 2 records that have the same date and level. When creating the map, the 2nd record will overwite the first, so the 2nd will be found to return an error, but not the first. So does this mean I need a map with a key of date+level and the value a LIST of Statistic__c? That is what I am thinking, but this seems very complicated.

 

Perhaps I am overlooking some tip or trick to more efficiently do this.

 

Here is the code I have so far:

 

trigger UpdateDateStatistics on Statistic__c (before insert, before update, after delete, after insert, after undelete, 
after update) {

if(Trigger.isBefore) {
List<Date> dateList = new List<Date>();
List<Id> levelList = new List<Id>();
Map<String,Statistic__c> smap = new Map<String,Statistic__c>();

for(Statistic__c s : Trigger.new) {
dateList.add(s.date__c);
levelList.add(s.level__c);
             smap.put(s.date__c.format()+s.level__c,s);
         }
        List<Statistic__c> existing = [select id, date__c, level__c from Statistic__c where date__c in :dateList and level__c in :levelList];
        for(Statistic__c e : existing) {
             Statistic__c se = smap.get(e.date__c.format()+e.level__c);
            se.addError('A Record already exists for this Level and Date. Please edit that record or choose an unused date and level combinations');
}
} else { // isAfter
 // do some other stuff not relavant here
}
}

 

 

Thanks.

 

 

  • April 01, 2011
  • Like
  • 0

I have a multi-part form (like the wizard example in the docs) which travels from page to page using "Next" and "Previous" buttons.

 

Let's say I am on page1 and click next to go to page2. When page2 is loaded the URL bar says page1. If I go back to page1 with the Previous button or onwards to page3 with the Next button, then it says page2 in the URL.

 

I would like the correct URL to be displayed with the correct page.

 

Here is a snippet of VF markup from one of the pages:

 

 

<apex:page showHeader="false" controller="studentApplicationController" >
  <apex:includeScript value="{!$Resource.jquery}" />
  <apex:includeScript value="{!$Resource.js_utils}" />
  <style type="text/css">
      .required {color:#F00;}
  </style>
  <apex:sectionHeader title="Aish Hatorah Application - All information in this application is strictly confidental" subtitle="Page 6 of 7"/>
  <apex:form >
      <apex:pageBlock title="" mode="edit" id="pageblock">
          <apex:pageMessages />
         <apex:pageBlockButtons >
             <apex:commandButton action="{!page5}" value="Previous"/>
             <apex:commandButton action="{!page7}" value="Next" onclick="return validatePage('{!$Component.pageblock}')"/>
             <apex:commandButton action="{!cancel}" value="Cancel"
                              onclick="return confirmCancel()" immediate="true"/>

         </apex:pageBlockButtons>

 

Here is the controller snippet for page redirection:

 

 

    public PageReference page6() {
      return Page.StudentApplicationPage6;
    }

    public PageReference page7() {
      return Page.StudentApplicationPage7;
    }

    public PageReference confirmPage() {
      return Page.StudentApplicationSubmitConfirmPage;
    }

 

thanks for any suggestions

 

 

  • March 16, 2011
  • Like
  • 0

I have a multi-part form, which cycles from page to page, collecting info, and then on the last page saves the SObjects that have been created along the way.

 

This includes a Person Account, and severl custom objects. I have enabled read/create perms on Accounts, Contacts, and the relevant custom objs in the Site Public Access Settings.

 

When I do this inside SFDC it works fine, however when I try from the public site it navigates from page to page, but when I try to save I get a 401 - Authorization Required page. I know its not the Confirmation page that is supposed to appear after the save as I tried by-passing the save and going directly to the confirm page, and it worked.

 

I assume this is something to do with perms on doing DML. I am only inserting. I am currently running in a sandbox.

  • March 16, 2011
  • Like
  • 0

I have a multi-part form, which cycles from page to page, collecting info, and then on the last page saves the SObjects that have been created along the way.

 

This includes a Person Account, and severl custom objects. I have enabled read/create perms on Accounts, Contacts, and the relevant custom objs in the Site Public Access Settings.

 

When I do this inside SFDC it works fine, however when I try from the public site it naviagates from page to page, but when I try to save I get a 401 - Authorization Required page. I know its not the Confirmation page that is supposed to appear after the save as I tried by-passing the save and going directly to the confirm page, and it worked.

 

I assume this is something to do with perms on doing DML. I am only inserting. I am currently running in a sandbox.

 

Thanks.

  • March 16, 2011
  • Like
  • 0

I have a related list for student (master-detail) of educational institutions the student has previously attended.

 

Since this list will vary for student to student, I would like to create some sort of repeater that will create a new line of fields that will be entered as new record in the related list.

 

The examples I saw using <apex:repeat> seem to just be to display a list of fields for one record, but not a repetition of the same fields for multiple records.

 

So, anybody know how I can do this?

 

thanks.

  • March 11, 2011
  • Like
  • 0

We are on the verge of launching our new site in Sites, moving from a .net site hosted on a rackspace server.

 

I noticed in GA that a number of people have our home page url including the default.aspx bookmarked and are hitting that url. Once we redirect our domain to Sites, that URL will disappear and they'll just get a blank page on the new site or 404.

 

So how can I enact a 301 for a URL using .aspx on Sites?

  • March 08, 2011
  • Like
  • 0

From the documentation it looks like a component can only take a custom controller or extension.

 

We are using OrchestraCMS so we need to use their custom controller for the page. But I want to create a component that will fit in the page that includes a contact form that will submit to leads. Pretty straight forward. I don't need to do any addtional processing to the fields aside from some js stuff, so I think the standard leads controller would suffice.

 

The question is can I use the standard leads controller or do I have to create my own custom controller?

 

thanks.

  • February 28, 2011
  • Like
  • 0

I have a PersonAccount Student which has a Detail custom Object Date, which is a list of the date the student entered and left. I create the student and insert it no problem. But when I try to add the student id which is the Master to the Date's student field and insert, I get the following DML Exception error:


System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Student: id value of incorrect type: 001T000000h4YlVIAU: [Student__c]

 

Here is the controller:

public with sharing class studentApplicationController {

    // Non-Object VF Fields
    public String lastname { get; set; }
    public String firstName { get; set; }
    public String salutation { get; set; }

    // Object Variable
    Account student;
    Date__c startdate;
    RelativeContact__c spouse;
    RelativeContact__c father;
    RelativeContact__c mother;
    List<Educational_Institution__c> schools;
    
    // Other Variables
    String submittedPageURL = '';
    
    // util methods
    RecordType getPersonAccountRecordTypeId() {
        return [select id,name,sobjectType,ispersontype from recordType where ispersontype=true and sobjectType='account' limit 1];
    }
    
    // Getters
    public Account getStudent() {
        if(student == null) {
            RecordType recType = getPersonAccountRecordTypeId();            
            student = new Account(recordtypeid=recType.id);
            //student = new Account();
        }
        return student;
    }
 
   
    public Date__c getStartDate() {
        if(startdate == null) {
            startdate = new Date__c(status__c='Entered - Non-Academic');
        }    
        return startdate;
    }   
     
    
    // Save the application into Salesforce
    public PageReference save() {
        
        student.lastname = lastname;
        student.firstname = firstname;
        student.salutation = salutation;
        insert student;
        
        System.debug('Student Id is: '+student.id);
        startdate.student__c = student.id;
        insert startdate;
        
        PageReference submittedPage = new PageReference(submittedPageURL);
        submittedPage.setRedirect(true);
        return submittedPage;
    }
}

 

 

According to the debug, the student does have a valid id, so it's not a null value issue.

 

Here is the test code:

 

 

@isTest
private class StudentApplicationControllerTest {

    static testMethod void testController() {
        studentApplicationController sac = new StudentApplicationController();
        sac.getStudent();
        sac.firstName = 'Unit';
        sac.lastname = 'Test';
        sac.salutation = 'Mr.';
        
        sac.getStartDate().Date__c = Date.newInstance(2, 25, 2011);
        
        sac.save();
    }
}

 

 

 

I get the same error when trying from my VF page.

 

I am not using queues. But the Account is a person account.

 

Any help would be greatly appreciated.

  • February 25, 2011
  • Like
  • 0

I have a PersonAccount Student which has a Detail custom Object Date, which is a list of the date the student entered and left. I create the student and insert it no problem. But when I try to add the student id which is the Master to the Date's student field and insert, I get the following DML Exception error:

 

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Student: id value of incorrect type: 001T000000h4YlVIAU: [Student__c]

 

Here is the controller:

public with sharing class studentApplicationController {

// Non-Object VF Fields
public String lastname { get; set; }
public String firstName { get; set; }
public String salutation { get; set; }

// Object Variable
Account student;
Date__c startdate;

// Other Variables
String submittedPageURL = '';

// util methods
RecordType getPersonAccountRecordTypeId() {
return [select id,name,sobjectType,ispersontype from recordType where ispersontype=true and sobjectType='account' limit 1];
}

// Getters
public Account getStudent() {
if(student == null) {
RecordType recType = getPersonAccountRecordTypeId();
student = new Account(recordtypeid=recType.id);
//student = new Account();
}
return student;
}

public Date__c getStartDate() {
if(startdate == null) {
startdate = new Date__c(status__c='Entered - Non-Academic');
}
return startdate;
}

// Save the application into Salesforce
public PageReference save() {

student.lastname = lastname;
student.firstname = firstname;
student.salutation = salutation;
insert student;

System.debug('Student Id is: '+student.id);
startdate.student__c = student.id;
insert startdate;

PageReference submittedPage = new PageReference(submittedPageURL);
submittedPage.setRedirect(true);
return submittedPage;
}
}

 

According to the debug, the student does have a valid id, so it's not a null value issue.

 

Here is the test code:

 

@isTest
private class StudentApplicationControllerTest {

static testMethod void testController() {
studentApplicationController sac = new StudentApplicationController();
sac.getStudent();
sac.firstName = 'Unit';
sac.lastname = 'Test';
sac.salutation = 'Mr.';

sac.getStartDate().Date__c = Date.newInstance(2, 25, 2011);

sac.save();
}
}

 

 

I get the same error when trying from my VF page.

 

I am not using queues. But the Account is a person account.

 

Any help would be greatly appreciated.

 

 

  • February 25, 2011
  • Like
  • 0

I noticed when trying to add a custom field to a VF page using a custom controller when the field is of type picklist or m-s picklist, I get the validation error Record Type ID: not valid entry for Account.

 

On the examples I saw, it looked like using inputfield should work, except the examples were using standard picklists not custom.

 

Is there a quick easy way to add the picklist to the page, or am I going to have to create a selectlist, and in the controller create a List with the values pulled via SOQL? If I have several picklists, is there an efficient way to query to avoid any govenor limits issues?

 

Here's the page:

The Gender, Country of Birth are Picklists, Citizenship is a Mulit-select Picklist

 

 

<apex:page showHeader="false" controller="studentApplicationController" >
<apex:sectionHeader title="Student Application" subtitle="Page 1 of 5"/>
<apex:form >
<apex:pageBlock title="General and Contact Information" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!cancel}" value="Cancel"
onclick="return confirmCancel()" immediate="true"/>

</apex:pageBlockButtons>
<p>Salutation:&nbsp; <apex:inputtext id="studentSalutation" value="{!salutation}"/></p>
<p>First Name:&nbsp; <apex:inputtext id="studentFirstName" value="{!firstName}"/></p>
<p>Last Name:&nbsp; <apex:inputtext id="studentLastName" value="{!lastname}"/></p>
<p>Date of Birth:&nbsp; <apex:inputfield id="studentBirthdate" value="{!student.personBirthdate}"/></p>
<p>Gender:&nbsp; <apex:inputfield id="studentGender" value="{!student.Gender__pc}"/></p>
             <p>Citizenship:&nbsp; <apex:inputfield id="studentCitizenship" value="{!student.Citizenship__pc}"/></p>
             <p>Country of Birth:&nbsp; <apex:inputfield id="studentCoB" value="{!student.County_of_Birth__pc}"/></p>



<p>Social Security, Social Insurance, or similar Government ID Number:&nbsp; <apex:inputfield id="studentForeignId" value="{!student.Social_Security__pc}"/><br />
Passport Number:&nbsp; <apex:inputfield id="studentPassport" value="{!student.Passport_Foreign__pc}"/></p>
<p>Driver License Number:&nbsp; <apex:inputfield id="studentDLN" value="{!student.Drivers_License__pc}"/></p>
<p>Driver License State:&nbsp; <apex:inputfield id="studentDLS" value="{!student.Drivers_License_State__pc}"/></p>
<p>Did you serve in the I.D.F.?&nbsp; <apex:inputfield id="studentIDF" value="{!student.IDF__pc}"/></p>

<h2>Contact Information</h2>
<p>Current Street Address:&nbsp; <apex:inputfield id="studentCurrentStreet" value="{!student.billingStreet}"/></p>
<p>Current City:&nbsp; <apex:inputfield id="studentCurrentCity" value="{!student.billingCity}"/></p>
<p>Current State/Province:&nbsp; <apex:inputfield id="studentCurrentSoP" value="{!student.billingState}"/></p>
<p>Current Zipcode/Postal Code:&nbsp; <apex:inputfield id="studentCurrentZoPC" value="{!student.billingPostalCode}"/></p>
<p>Current Country:&nbsp; <apex:inputfield id="studentCurrentCountry" value="{!student.billingCountry}"/></p>
<p>Phone Number:&nbsp; <apex:inputfield id="studentPhone" value="{!student.personHomePhone}"/></p>
<p>Cell Number:&nbsp; <apex:inputfield id="studentCell" value="{!student.personMobilePhone}"/></p>
<p>Fax:&nbsp; <apex:inputfield id="studentFax" value="{!student.fax}"/></p>
<p>Email:&nbsp; <apex:inputfield id="studentEmail" value="{!student.personEmail}"/></p>
<p>Second Email:&nbsp; <apex:inputfield id="studentEmail2" value="{!student.X2nd_Email__pc}"/></p>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Here is the Controller:

 

 

 public with sharing class studentApplicationController {

    // Non-Object VF Fields
    public String lastname { get; set; }
    public String firstName { get; set; }
    public String salutation { get; set; }

    // Object Variable
    Account student;
    Date__c startdate;
    RelativeContact__c spouse;
    RelativeContact__c father;
    RelativeContact__c mother;
    List<Educational_Institution__c> schools;
    
    // Other Variables
    String cancelPageURL = 'https://c.cs0.visual.force.com/apex/StudentApplicationPage1';
    String submittedPageURL = 'https://c.cs0.visual.force.com/apex/StudentApplicationPage1';
       
    // Getters
    public Account getStudent() {
        if(student == null) {
            RecordType recType = [select id,name,sobjectType,ispersontype from recordType where ispersontype=true and sobjectType='account' limit 1];          
            student = new Account(recordtypeid=recType.id); 
        }
        return student;
    }
    
    public Date__c getStartDate() {
        if(startdate == null) {
            startdate = new Date__c(status__c='Entered - Non-Academic');
        }   
        return startdate;
    }   
     
    public RelativeContact__c getSpouse() {
        if(spouse == null)
            spouse = new RelativeContact__c();
        return spouse;
    }
    
    public RelativeContact__c getFather() {
        if(spouse == null)
            spouse = new RelativeContact__c();
        return spouse;
    }
    
    public RelativeContact__c getMother() {
        if(spouse == null)
            spouse = new RelativeContact__c();
        return spouse;
    }
    
    // Page References for Navigation
    public PageReference page1() {
      return Page.StudentApplicationPage1;
    }

    // If applicant cancels, redirect to cancel page
    public PageReference cancel() {
        PageReference cancelPage = new PageReference(cancelPageURL);
        cancelPage.setRedirect(true);
        return cancelPage; 
    }
    
    // Save the application into Salesforce
    public PageReference save() {
        
        student.lastname = lastname;
        student.firstname = firstname;
        student.salutation = salutation;
        insert student;
        
        startdate.student__c = student.id;
        insert startdate;
        
        PageReference submittedPage = new PageReference(submittedPageURL);
        submittedPage.setRedirect(true);
        return submittedPage; 
    }

 }

 

 

 

  • February 24, 2011
  • Like
  • 0

I posted this problem on Sunday but with little response, so I am trying again now that it's the middle of the week.

 

Here is the original post

http://boards.developerforce.com/t5/Visualforce-Development/error-creating-a-Person-Account-in-a-custom-controller/td-p/248719

 

I am trying to create a new Account object which is a person account, however no matter what I try, I keep getting the error

 

Record Type ID: value not valid for the entity: PersonAccount, if I use a default constructor

 

or

 

Record Type ID: value not valid for the entity: Account, if I set the record type id in the constructor.

 

All of my profiles have the person account record type enabled, at least when I click on the record type assignments they are all listed as set to person account and person account is the default record type. I am working in DE as the system admin. I tried adding the Business Account record type to admin, and even tried setting it to default and then ran the code with a default constructor. No change.

 

I am going out of my mind, as I can't seem to locate the problem and can't progress. Not to mention there seems to be relatively little documentation and examples on using person accounts, especially in apex.

  • February 22, 2011
  • Like
  • 0

I am creating an online application that will dump into a Person Account. However when I try to instanciate the account obj in the getter I get the following runtime validation error:

 

Validation Errors While Saving Record(s) There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Student Record Type: value not valid for the entity: Account".

 

Here's the VF page

 

 

<apex:page showHeader="false" controller="newStudentApplicationController" >
  <apex:sectionHeader title="Application" subtitle="Page 1 of 5"/>
  <apex:form >
      <apex:pageBlock title="Student Application" mode="edit">
         <apex:pageBlockButtons >
             <apex:commandButton action="{!save}" value="Save"/>
             <apex:commandButton action="{!cancel}" value="Cancel" 
                              onclick="return confirmCancel()" immediate="true"/>

         </apex:pageBlockButtons>
         <apex:pageBlockSection title="General Information">
             <apex:inputfield id="studentTitle" value="{!student.salutation}"/>
             <apex:inputfield id="studentFirstName" value="{!student.firstName}"/>
             <apex:inputfield id="studentLastName" value="{!student.lastname}"/>
             <apex:inputfield id="studentBirthdate" value="{!student.personBirthdate}"/>
             <apex:inputfield id="studentAffiliation" value="{!student.Affiliation__pc}"/>
         </apex:pageBlockSection>
      </apex:pageBlock>
  </apex:form>
</apex:page>

 

 

 

Here is the Controller

 

 

public class newStudentApplicationController {
    // Object Variable
    Account student;
    
    // Getters
    public Account getStudent() {
        if(student == null) {
            RecordType recType = [select id,name,sobjectType,ispersontype from recordType where ispersontype=true and sobjectType='account' limit 1];            
           // student = new Account(recordtypeid=recType.id); 
            student = new Account(); 
        }
        return student;
    }
    

 

If I try using the default constructor (commented out line above), I this error:

 

 

Validation Errors While Saving Record(s) There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Student Record Type: value not valid for the entity: PersonAccount".

 

I have a feeling I am missing somethign small. Any help would be GREATLY Appreciated.

 

Thanks!

  • February 20, 2011
  • Like
  • 0

I am trying to create an online student application. The application is quite lengthy, so ideally I want to break it up into multiple pages, using a "next" button. Also, while most of the info is on the student record (PersonAccount), some info goes into custom objs with a master-detail relationship to the student record.

 

I was hoping to do this with cmsForce2, but it looks like this is too complicated for that. If anyone knows a good app or tool to do this, I would love to know. Barring that, I am assuming I am going to have to create custom Visualforce pages with custom controllers.

 

Now I have some experience creating Visualforce pages and writing some apex triggers, but nothing on this scale.

 

So, how would I

1. submit the first page to the PersonAccount (all fields are on the Contact side), retrieve the id and send it as a hidden field to the 2nd page? Would I just extend the Contact controller or do I need to write something new from scratch?

2. submit to the custom objs?

3. If the applicant quits in the middle, to rollback the changes as we do not want a half filled out application?

 

Thanks for speedy answers to any or all of the above mentioned questions and any other advice anyone can give.

  • February 17, 2011
  • Like
  • 0

Hello everyone.

 

I have been trying to test trigger code but I cannot reach to over 75% coverage. Can you give me tips to help me out, please?

 

This is this trigger does:

・This trigger runs when new Opportunity with certain record type is created.

・This trigger updates a field called "Application Progress" on Contact.

 

Here is trigger code

 

trigger updateAppProgress2CS on Opportunity (after insert) {
    //updateAppProgress2CS
    ID recType = '0121000000008C7AAI'; //Study Abroad Opportunity RecordType
    
    try{
        //obtain Opportunity ID when new Opportunity is created
        for(Opportunity opp : Trigger.new){
            //check if opportunity record type is study abroad or not
            Opportunity oppRec = [SELECT RECORDTYPEID FROM Opportunity WHERE ID = :opp.id];
            
            if(oppRec.RECORDTYPEID == recType){
                //obtain contact id from OpportunityContactRole
                OpportunityContactRole OppRole = [SELECT ContactId FROM OpportunityContactRole WHERE OpportunityId = :opp.id];
        
                //Check if there is any contact record associated with Contact Role in Opportunity
                if(OppRole != null) {
                    //get Application Progress value
                    Contact con = [SELECT AppProg__c FROM Contact WHERE Id = :OppRole.ContactId];
              
                    //set Application Progress value
                    con.AppProg__c = 'Course selection';
              
                    //update contact
                    update con;
                }//end if
            }//end if
        }//end for

    }catch(Exception e){
    }
}

 

 

Here is a test code

 

@isTest
private class updateAppProgress2CSTest{
    static testMethod void runSuccessCase(){
    
        //get existing account id (Account record for testing)
        Account acc = [select id from Account where name ='【ダミー】EIKOKU Hanako'];
        
        try{
        //create an Opportunity(Study Abroad record type) 
        Opportunity opp = new Opportunity(Name = 'Test Opportunity', AccountID = acc.Id, CloseDate=date.newInstance(1986,4,27), StageName='商品ご案内', RECORDTYPEID='0121000000008C7AAI');
       
        //execute updateAppProgress2CS trigger.
        insert opp;
 
        //get contact id from ContactRole
        OpportunityContactRole OppRole = [SELECT ContactId FROM OpportunityContactRole WHERE Opportunity.Id = :Opp.Id];
          
        system.assert(OppRole != null);
        
        //get Application Progress value
        Contact con = [SELECT AppProg__c FROM Contact WHERE Id = :OppRole.ContactId];         
        
        system.assert(con.AppProg__c == 'Course selection');
        }catch(Exception e){       
        }           
    }

}

 

 

According to Testing result, my test code does not cover the code in the trigger(line 16~) and the coverage is 63%.

 

if(OppRole != null) {
    //get Application Progress value
    Contact con = [SELECT AppProg__c FROM Contact WHERE Id = :OppRole.ContactId];
              
    //set Application Progress value
    con.AppProg__c = 'Course selection';
              
    //update contact
    update con;
}//end if

 

 

 

 

 

 

 

 

 

 

When trying to deploy my custom controller and VF pages for our Sites site from Eclipse, when running the test cases I get the following error

StudentApplicationControllerTest.testController System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, entity type cannot be inserted: Person Account: []

According to the WSDL docs this is a permissions error as follows:
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY
You do not have permission to create, update, or activate the specified record.

This doesn't make sense as I am the System Admin and have permissions to all objects, fields, record types, etc.

 

Here is the getter that creates the Person Account record

 

 

    public Account getStudent() {
        if(student == null) {
            RecordType recType = getPersonAccountRecordTypeId();            
            student = new Account(recordtypeid=recType.id,web_submission__c=true); 
            //student = new Account(); 
        }
        return student;
    }

   RecordType getPersonAccountRecordTypeId() {
    	return [select id,name,sobjectType,ispersontype from recordType where ispersontype=true and sobjectType='account' limit 1];
    }

 

 

 

This is preventing our move to production and is critical.

 

Any help is much appreciated.

  • May 04, 2011
  • Like
  • 0

We have an online application using Sites. Our applicatants come from a variety of countries with differing locals. Some are used to mm/dd/yyyy and others dd/mm/yyyy.

 

Is there any way to set a date field format to something more universal?

 

Since puting in 5/4/11 could mean May 4th or April 5th, we would like to use a format like 03 Jan 11

 

Is such a thing possible and if so, how?

 

thanks.

  • April 28, 2011
  • Like
  • 0

Being that cross object reporting in the standard reporting mechanism is, well, pathetic. Is there any way to create a report driven by SOQL queries that can be viewed and stored like regular reports or are we talking visualforce with a custom controller?

  • April 06, 2011
  • Like
  • 0

I am writing a trigger that, among other things, is supposed to check if a record exists for my custom object Statistic__c with the same date and level as the one trying to be inserted.

 

Simply I want to grab the date and level from the trigger do a SOQL to find existing records and return an error to the record trying to be inserted/updated if a match is found. No problem, right?

 

Well as I am trying to bulkify, this is getting much more complicated. The issue is once I have my list of existing records how I then sync up to the list of statistic__c to send errors to the proper one. So I thought to create a map where the key = date+level and the value is the sobject. So that would work fine, I think except what if in the bulk upload are 2 records that have the same date and level. When creating the map, the 2nd record will overwite the first, so the 2nd will be found to return an error, but not the first. So does this mean I need a map with a key of date+level and the value a LIST of Statistic__c? That is what I am thinking, but this seems very complicated.

 

Perhaps I am overlooking some tip or trick to more efficiently do this.

 

Here is the code I have so far:

 

trigger UpdateDateStatistics on Statistic__c (before insert, before update, after delete, after insert, after undelete, 
after update) {

if(Trigger.isBefore) {
List<Date> dateList = new List<Date>();
List<Id> levelList = new List<Id>();
Map<String,Statistic__c> smap = new Map<String,Statistic__c>();

for(Statistic__c s : Trigger.new) {
dateList.add(s.date__c);
levelList.add(s.level__c);
             smap.put(s.date__c.format()+s.level__c,s);
         }
        List<Statistic__c> existing = [select id, date__c, level__c from Statistic__c where date__c in :dateList and level__c in :levelList];
        for(Statistic__c e : existing) {
             Statistic__c se = smap.get(e.date__c.format()+e.level__c);
            se.addError('A Record already exists for this Level and Date. Please edit that record or choose an unused date and level combinations');
}
} else { // isAfter
 // do some other stuff not relavant here
}
}

 

 

Thanks.

 

 

  • April 01, 2011
  • Like
  • 0

Hello,

 

I am trying to create a custom page that allows people to enter information about Accounts. It was working fine until we added Person Accounts, now it fails with this error when you try to access the page:

 

 

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Record Type ID: value not valid for the entity: Account". 

 

 

It still works fine when entering the information of a Business Account, but fails when attempting to do so for a Person Account.

 

I have narrowed it down to a picklist field causing the error. Whenever an inputField that is bound to a picklist is added the error occurs.

 

Snipped code:

 

 

<apex:page id="NeedsPage" standardController="Account">
  
    <apex:form >
    <apex:pageBlock title="Enter {!account.name}'s Needs">
    
    <apex:pageblockButtons >
        <apex:commandButton value="Save" action="{!save}"/>
    </apex:pageblockButtons>

    <!-- Bound to CheckBox - works fine -->
    <apex:inputField value="{!account.Cut_Home_Phone_Costs__c}"/>

    <!-- bound to textbox - works fine -->
    <apex:inputField value="{!account.Home_Phone_Type__c}" />

    <!-- Bound to picklist - fails on Person Account - works on Business account -->
    <apex:inputField value="{!account.Home_Phone_Provider_Other__c}" />
    </apex:pageBlock>
    </apex:form>
</apex:page>

 

Any suggestions?

 

Thanks,

Peter

 

I have a multi-part form, which cycles from page to page, collecting info, and then on the last page saves the SObjects that have been created along the way.

 

This includes a Person Account, and severl custom objects. I have enabled read/create perms on Accounts, Contacts, and the relevant custom objs in the Site Public Access Settings.

 

When I do this inside SFDC it works fine, however when I try from the public site it navigates from page to page, but when I try to save I get a 401 - Authorization Required page. I know its not the Confirmation page that is supposed to appear after the save as I tried by-passing the save and going directly to the confirm page, and it worked.

 

I assume this is something to do with perms on doing DML. I am only inserting. I am currently running in a sandbox.

  • March 16, 2011
  • Like
  • 0

I have a related list for student (master-detail) of educational institutions the student has previously attended.

 

Since this list will vary for student to student, I would like to create some sort of repeater that will create a new line of fields that will be entered as new record in the related list.

 

The examples I saw using <apex:repeat> seem to just be to display a list of fields for one record, but not a repetition of the same fields for multiple records.

 

So, anybody know how I can do this?

 

thanks.

  • March 11, 2011
  • Like
  • 0

We are on the verge of launching our new site in Sites, moving from a .net site hosted on a rackspace server.

 

I noticed in GA that a number of people have our home page url including the default.aspx bookmarked and are hitting that url. Once we redirect our domain to Sites, that URL will disappear and they'll just get a blank page on the new site or 404.

 

So how can I enact a 301 for a URL using .aspx on Sites?

  • March 08, 2011
  • Like
  • 0

Hi All

 

I have try to work on Force.com site.

 

I need to use custom stylesheet on the page. So I try to study by myself from http://www.salesforce.com/us/developer/docs/pages/Content/pages_styling_custom.htm

 

I have some problem that I cannot use custom css file on my page.

 

Below this is my VF page code.

 

 

<apex:page showHeader="false" standardStylesheets="false">
	<apex:stylesheet value="{!$Resource.customCSS}" />

	<h1>Testing Custom Stylesheets</h1>

	<p>This text could go on forever...<BR /><BR />But it won't!</p>

	<apex:outputLink value="https://www.salesforce.com" styleClass="newLink">
		Click here to switch to www.salesforce.com
	</apex:outputLink>

</apex:page>

 And customCSS file is : 

 

h1 { color: #FF0000; }

p { background-color: #EEEECC; }

newLink { color: #FF6600; font-weight: bold;}

 for the result http://crmmarket-developer-edition.na7.force.com/index

 

 

the code result is :

 

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
 
 
	<html><head><script src="/index/jslibrary/1296001444000/JiffyStubs.js" type="text/javascript"></script><link class="user" href="/index/resource/1299612283000/customCSS" rel="stylesheet" type="text/css" /></head><h1>Testing Custom Stylesheets</h1> 
 
	<p>This text could go on forever...<BR /><BR />But it won't!</p><a href="https://www.salesforce.com" class="newLink"> 
		Click here to switch to www.salesforce.com</a></html>

 

 

I think h1 should show the text in the red but it dose not.

 

Please advise me that what I am wrong?

 

i want to export the reports from one sandbox and import that reports into another sandbox
how can i do that, if anybody knows please let me know....

 

thanks in advance

  • March 08, 2011
  • Like
  • 0

 

How to pass values to multipicklist field type using apex code.

Here is my Requirement:

 

I have  a Value stored in string now how to pass value of a string to a multi picklist field of an object using apex code.

 

I have a value stored in a string as:

string str =

004 - Florida;008 - Ohio River;013 - Carolinas;015 - Texas;024 - Gulf Coast;024 - Gulf Coast;030 - Empire State;040 - Sun Coast;032 - Pacific Northw;029 - Rocky Mountain

Hi,

 

We have a process where customers need to submitted / upload scanned documents via a force.com app

Is it possible to store the documents externally via Google Docs OR Amazon S3 services?

 

There will be 100's of jpg scanned docs per week uploaded via the application.

 

Appreciate any advise on best practice.

 

Many thanks

Matt

  • March 08, 2011
  • Like
  • 0

I'm new to Salesforce so this may be an easy one:

I would like to create a Picklist whose values I can manage in one place but will be included in multiple objects.

For example, I want to create a Picklist called End User Types.

It will have the values: Hospital, Restaurant, University, etc.

I want to add the End User Types picklist  to Account, Opportunities, Leads, and other custom objects. 

Most importantly, I don't want the user to have to do a Lookup of the values.  I want it to look like a regular Picklist within Account, Opportunities, etc.

It will show up as a dropdown.

But I can manage the values in one place rather than creating separate Picklists within each object (Account, Opportunities, etc.)

 

It seems that I can do this with custom java development, but that is beyond my skillset.  Isn't there another way?

 

 

 

Below is a simple VF page and Controller. You will not on the Controller I hard code the

 

 

where nights__c = 4

 

 I want to make this dynamic using a input field on the VF page.

 

 

 

VF Page

 

 

<apex:page controller="Resmanager">
    <apex:sectionHeader title="Availability Search"/> 
                 
              <apex:pageBlock title="Reservations">
              <apex:pageBlockSection >
                    <apex:pageBlockTable value="{!Reservations}" var="res">
                        <apex:column value="{!res.Start_Date__c}"  />
                        <apex:column value="{!res.End_Date__c}"  />
                        <apex:column value="{!res.Nights__c}"  />
                    </apex:pageBlockTable>
               </apex:pageBlockSection>
               
               </apex:pageBlock>

</apex:page>

 

 

APEX Controller

 

 

public class Resmanager {
    
    public List<Reservation__c> getReservations(){
        List<Reservation__c> listBd=[select r.id, r.Start_Date__c, R.End_Date__c, nights__c from Reservation__c r where nights__c = 4];
        return listBd;   
    }
   
}

 

 

 

I posted this problem on Sunday but with little response, so I am trying again now that it's the middle of the week.

 

Here is the original post

http://boards.developerforce.com/t5/Visualforce-Development/error-creating-a-Person-Account-in-a-custom-controller/td-p/248719

 

I am trying to create a new Account object which is a person account, however no matter what I try, I keep getting the error

 

Record Type ID: value not valid for the entity: PersonAccount, if I use a default constructor

 

or

 

Record Type ID: value not valid for the entity: Account, if I set the record type id in the constructor.

 

All of my profiles have the person account record type enabled, at least when I click on the record type assignments they are all listed as set to person account and person account is the default record type. I am working in DE as the system admin. I tried adding the Business Account record type to admin, and even tried setting it to default and then ran the code with a default constructor. No change.

 

I am going out of my mind, as I can't seem to locate the problem and can't progress. Not to mention there seems to be relatively little documentation and examples on using person accounts, especially in apex.

  • February 22, 2011
  • Like
  • 0

I have the following VF page that is called by a button on a Person Account record.

 

 

<apex:page standardController="Account" title="Cancel Account">
    <apex:sectionHeader title="Cancel Account"/>
    <apex:form id="theForm">
        <apex:pageBlock id="theBlock">
            <apex:pageBlockSection id="sectionOne">
                <apex:outputField value="{!Account.Name}" />
                <!-- Bound to Date Field -->                
                <apex:inputField value="{!Account.Account_Cancel_Eff_Date__c}" />
                <!-- Bound to Picklist -->
                <apex:inputField value="{!Account.Account_Cancel_Reason__c}" />
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

When the page is called for a person account, Salesforce returns:

 

Validation Errors While Saving Record(s)

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Record Type ID: value not valid for the entity: Account". 

When the page is called for a normal Account, it renders as expected. If I remove the inputField that is bound to the picklist, then call the page for a person account, everything works as expected. What's going on here?

 

  • February 09, 2011
  • Like
  • 0