• Patricia Lim
  • NEWBIE
  • 20 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 14
    Questions
  • 11
    Replies
Hello all. I am trying to upload an attachment through Visualforce so that end-users can upload documents and it will be related to the record they just created.  However when I assign the parentId of the attachment to the variable in my controller, it returns the following error:
duplicate value found: <unknown> duplicates value on record with id: <unknown>

Here is the code
Apex
/*
    1) Initalize objects
    2) Initalize lists
    3) Empty constructor 
    4) Add row to recipient list
    5) Add row to scholarship list
    6) Insert all records from both lists
    */

    //1) Initalize objects

    public without sharing class finalExperiment {
        
        //Recipient
        public Recipient__c rec {
            get {
                if(rec == null)
                    rec = new Recipient__c();
                return rec;
            }
            set;
        }

        //Scholarship Award
        public Scholarship_Award__c sch {
            get {
                if(sch == null)
                    sch = new Scholarship_Award__c();
                return sch;
            }
            set;
        }

        //Recipient List
        public List<Recipient__c> recList {
            get {
                if(recList == null)
                    recList = new List<Recipient__c>();
                return recList;
            }
            set;
        }

        //Scholarship List
        public List<Scholarship_Award__c> schList {
            get {
                if(schList == null)
                    schList = new List<Scholarship_Award__c>();
                return schList;
            }
            set;
        }

        //Attachment

        public Attachment myDocument {
        get {
            if(myDocument == null)
                myDocument = new Attachment();
            return myDocument;
            }
            set;
        }
        
        //Empty constructor
        public finalExperiment(){

        }

        //Add row method for both lists
        public PageReference add_record(){
            //Recipient fields
            Recipient__c anotherRecipient = new Recipient__c();
            anotherRecipient.Name = rec.Name;
            anotherRecipient.Last_Name__c = rec.Last_Name__c;
            anotherRecipient.School__c = rec.School__c;
            anotherRecipient.Specialty__c = rec.Specialty__c;
         	
            upsert anotherRecipient;
            
            //Insert any documents into recipient
            myDocument.parentId = anotherRecipient.Id;	

            //Scholarship fields
            Scholarship_Award__c anotherScholarship = new Scholarship_Award__c();
            anotherScholarship.Award__c = sch.Award__c;
            anotherScholarship.Year__c = sch.Year__c;
            anotherScholarship.School__c = sch.School__c;
            anotherScholarship.Recipient__c = anotherRecipient.Id;
            
            upsert anotherScholarship;

            //Add to lists
            recList.add(anotherRecipient);
            schList.add(anotherScholarship);
            
            return null;
        }

The VF is working fine - it is the assignment that is throwing an error. 
Thank you
Hi all. I have a pageBlockSection before the button that specifies 2 columns and I suspect this is why I cannot center my button despite using 
<div align="center">
Here is my VF markup:
<apex:pageBlock title="Added Participants">
    <apex:pageBlockTable id="people" value="{!allcontacts}" var="participant">
        
        <apex:column headervalue="First Name" value="{!participant.Name}"/> 
        <apex:column headerValue="Last Name" value="{!participant.Last_Name__c}"/>
        <apex:column headerValue="Age" value="{!participant.Age__c}"/>
        <apex:column headerValue="Phone" value="{!participant.Phone__c}"/>
        <apex:column headerValue="Victim/Offender" value="{!participant.Victim_Offender__c}"/>
        <!--Submit button-->
    </apex:pageBlockTable>
           <br/>
           <br/>
      <apex:pageBlock>
      <apex:pageBlockButtons location="bottom">
            <apex:commandButton action="{!save}" value="Submit Referral"/>
          <br/>
          <br/>
        <p>By clicking this button, you are agreeing to start the registration process.</p>
      </apex:pageBlockButtons>
      </apex:pageBlock>
        <div style="text-align:center">
      <p>© 2020. All rights reserved.</p>
      </div>
    </apex:pageBlock>
  </apex:form>
</apex:page>
Advice is appreciated
 
I am trying to combine both custom controller and extension in a single Apex class so I don't have to use an extension and can use 2 objects in one VF page.

I need to be able to add records from both `participant__c` and `referral__c` objects. Where participant records are inserted together from the record list.

First class for using 2 objects
public class ecrjcController {
    public Referral__c ref {get;set;}
    public Participant__c par {get;set;}
    
    public ecrjcController(){
        
        ref = new Referral__c();
	}
    
    public void saveRecords(){
        insert ref;
    }
}

2nd Apex Class for apex:pageBlockTable
 
public with sharing class ecrjcClass{
    
    public Participant__c record = new Participant__c();
    public Referral__c ref {get;set;}
    public List<Participant__c> allrecords {get;set;}

    public ecrjcClass(ApexPages.StandardController controller){
        ref = new Referral__c();
        record = (Participant__c)controller.getRecord();
        allrecords = new List<Participant__c>();
    }

    //Add a record row
    public pageReference Add_Row(){

        Participant__c anotherRecord = new Participant__c();   
        anotherRecord.Name = record.Name;
        anotherRecord.Last_Name__c = record.Last_Name__c;
        anotherRecord.Age__c = record.Age__c;
        anotherRecord.Victim_Offender__c = record.Victim_Offender__c;
        anotherRecord.Referral__c = record.Referral__c;
        allrecords.add(record);

        return null;
    }
	
    //Save and insert records in list
    public pageReference save(){
	
        insert ref;
        insert allrecords;
        return null;
            
    }
}
    //Delete button on each record on apex table
Unfortunately using a standard controller with an extension does not work as it is returning an error when I reference an object from the extension
I have a custom controller behind a VF page that sets the value of one of the fields to be the one that the user inputs in another field:
public void saveScholarship(){
        rec = new recipient__c(School__c=sch.School__c);
        insert rec;
        sch.Recipient__c = rec.Id;
        insert sch;
        sch = new scholarship_award__c(recipient__c=rec.Id);
    }
}

However when the record is saved to my org, the ID is saved in the `recipient__c` name field instead of the name that was inputted by the user. How can I get the name to save and display instead of the ID?
I would like to add document upload functionality to my VF page of which already has a custom controller defined. When I use extension controllers it simply returns the error: `Unknown constructor 'documentExt.documentExt(c2 controller)'`

I consolidated my extension controller code into my custom controller, but it doesn't seem to be doing anything:
User-added image
Here is my controller code:
public class c2{
    public scholarship_award__c sch {get;set;}
    public recipient__c rec {get;set;}
    public document doc {get;set;}
    
    public c2(){
        sch = new scholarship_award__c();
        rec = new recipient__c();
    }
    
    public void saveScholarship(){
        insert rec;
        sch.Recipient__c = rec.Id;
        insert sch;
        sch = new scholarship_award__c(Recipient__c=rec.Id);
   		rec = new recipient__c();
    }   

    	public void documentExt(ApexPages.StandardController controller)
    {
        Document d = (Document)controller.getRecord();
        d.folderid = UserInfo.getUserId(); //Put in personal documents
    }    
}
VF page:
<apex:page showHeader="False" applyHtmlTag="true" applyBodyTag="false" controller="c2" lightningStyleSheets="True" extensions="c2">
<head>
   <apex:slds >
    <body class="slds-scope">
    <apex:form >
        <apex:pageBlock title="Academic Year 2020-2021">
        <apex:pageBlockSection columns="2" title="Add Scholarships">
            <apex:inputField value="{!rec.Name}"/>
            <apex:inputField value="{!rec.Last_Name__c}"/>S
            <apex:inputField value="{!rec.Preferred_Name__c}"/>
            <apex:inputField value="{!sch.School__c}"/>
            <apex:inputField value="{!sch.Year__c}"/>
            <apex:inputField value="{!sch.Award__c}"/>
            <apex:inputField value="{!rec.Email__c}"/>
            <apex:inputField value="{!rec.Specialty__c}"/>
            <apex:inputField value="{!rec.school__c}"/>
        </apex:pageBlockSection>      
            <div align="center" >
            <apex:inputField value="{!rec.Biography__c}" style="width: 100px; height:40px"/>           
            </div>	
        <apex:pageBlockButtons location="bottom">
            <apex:commandButton action="{!saveScholarship}" value="Submit"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
    </body>
   </apex:slds>
</head> 
</apex:page>

Thanks
Hi all. I have a VF page with a custom controller that saves new records from 2 objects in the same single page. I need a save button for this page and it is returning the error 
Unknown method 'c2.save()'
I suspect this is because I am using a custom controller instead of a standard one - how can I configure my controller so that I can add the save button, and any other buttons?

Apex class:
public class c2{
    public scholarship_award__c sch {get;set;}
    public recipient__c rec {get;set;}
    
    public c2(){
        sch = new scholarship_award__c();
        rec = new recipient__c();
    }
    
    public void saveScholarship(){
        insert rec;
        rec = new recipient__c();
        
        insert sch;
        sch = new scholarship_award__c(Recipient__c=rec.Name + rec.Last_Name__c);
    }
}

VF page:
<apex:page controller="c2">
	<apex:form >
        <apex:pageBlock title="Academic Year 2020-2021">
        <apex:pageBlockSection title="Add Scholarships">
            <apex:inputField value="{!rec.Name}"/>
            <apex:inputField value="{!rec.Last_Name__c}"/>
            <apex:inputField value="{!rec.Preferred_Name__c}"/>
            <apex:inputField value="{!sch.School__c}"/>
            <apex:inputField value="{!sch.Year__c}"/>
            <apex:inputField value="{!sch.Award__c}"/>
            <apex:inputField value="{!rec.Email__c}"/>
            <apex:inputField value="{!rec.Specialty__c}"/>
            <apex:inputField value="{!rec.Biography__c}"/>
        </apex:pageBlockSection>
        <apex:pageBlockButtons >
        	<apex:commandButton action="{!save}" value="Save"/>
        </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Thanks!
 
Hi all. I am trying to complete the custom controller trailhead and the following code samples are returning these errors:

- VF page - Unknown property: 'ContactsListController.contacts'
- Apex class - Unexpected token 'String'.

VF page
 
<apex:page controller="ContactsListController">
    <apex:form>
    	<apex:pageBlock title="Contacts List" id="contacts_list">
		<!-- Contacts List -->
		<apex:pageBlockTable value="{! contacts }" var="ct">
            <apex:column value="{! ct.FirstName }"/>
            <apex:column value="{! ct.LastName }"/>
            <apex:column value="{! ct.Title }"/>
            <apex:column value="{! ct.Email }"/>
        </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Custom Apex Controller
 
private String sortOrder = 'LastName';
public List<Contact> getContacts() {
    List<Contact> results = Database.query(
        'SELECT Id, FirstName, LastName, Title, Email ' +
        'FROM Contact ' +
        'ORDER BY ' + sortOrder + ' ASC ' +
        'LIMIT 10'
    );
    return results;
}

Thanks community! Learning as I go here
I am in the process of developing an apex:form that will save two records: Recipient__c and Scholarship_Award__c. 

I need to create a custom controller to save new records for both objects on the same VF page. 
The trouble is the Recipient__c record will need to be saved first following the insertion of Scholarship_Award__c because it references Recipient__c as the parent in a master-detail relationship. 

Ideally, the end-user will input the fields of recipient__c, and scholarship_award__c and two records will be saved: a new recipient, and a new scholarship with that recipient as the parent. 

How can I go about developing this?
I would like to populate the lookup icon for a master-detail field so that end-users can choose the parent object for a new child record.
How can I do this with a custom controller?
 
<apex:page standardController="Scholarship_Award__c">
    <h1>2020-2021 Academic Year</h1>
    <apex:form >
    <!-- Hi -->
    <apex:pageBlock title="Add Scholarship Awards">
        <apex:pageBlockSection columns="2">
            <apex:inputField value="{!Scholarship_Award__c.Name}"/>
            <apex:inputField value="{!Scholarship_Award__c.Year__c}"/>
            <apex:inputField value="{!Scholarship_Award__c.Recipient__c}"/>	
        </apex:pageBlockSection>
        <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Save"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
    </apex:form>
</apex:page>



Thanks, I am new to VF
Hi all. I am creating an <apex:form> with one of the fields being a master-detail relationship that looks up the parent in the UI field. When I add this to my form, it does not appear on the VF page - what am I missing here?

User-added imageCode:
<apex:page standardController="Scholarship_Award__c">
    <h1>2020-2021 Academic Year</h1>
    <apex:form >
    <!-- Hi -->
    <apex:pageBlock title="Add Scholarship Awards">
        <apex:pageBlockSection columns="2">
            <apex:inputField value="{!Scholarship_Award__c.Name}"/>
            <apex:inputField value="{!Scholarship_Award__c.Year__c}"/>
        </apex:pageBlockSection>
        <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Save"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
    </apex:form>
</apex:page>

 
Hi all. I have a VF page with an <apex:form> component with Account as the standard controller however when I enter details and click save in the preview page or on the community where I placed it as a component, it doesn't add the record to my Salesforce org - what am I missing here?
 
<apex:page standardController="Account">
    <h1>Enter Account</h1>
    <apex:form >
    <apex:pageBlock title="Edit Account">
        <apex:pageBlockSection columns="2">
            <apex:inputField value="{! Account.Name}"/>
            <apex:inputField value="{! Account.Phone}"/>
            <apex:inputField value="{! Account.Industry}"/>
        </apex:pageBlockSection>
        <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Save"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
    </apex:form>
</apex:page>

Thanks
Hi all, new to Apex here doing Trailhead..
I am receiving the error in the title above - here is my apex class:
 
public class AccountHandler {
    public static void insertAccount(Integer value){
        Integer counter = 1;
        //create a list
        List<Account> addAccounts = new List<Account>();
        while(counter <= value){
        //display current counter value
        system.debug('Counter value before incrementing' + counter);
        //create a new account
        Account store = new Account();
        store.Name = 'Acme Inc n' + counter;
        store.AccountNumber = 'A00n' + counter;
        addAccounts.add(store);
        system.debug(addAccounts);
        //increment counter
        counter = counter + 1;
        system.debug('Counter value after incrementing' + counter);     
        
        }
        system.debug('Size of Account list:' + addAccounts.size());
        system.debug('Elements in Account List:' + addAccounts);
        //insert
        insert addAccounts;
    }
}
And my execution code:
AccountHandler.sObjectsInsert(3);

 
Hi all,
After some digging around the Trailblazer community, I discovered that adding this funcitonality to custom objects can be done with VF and apex. I am learning visualforce anyway, so I don't mind this method.

For context, my organization awards scholarships. Where scholarship is the product, and our recipients are a custom object 'recipient'. Initially, I created three products and added the product related list to the recipient page layout, but cannot add products, only create new ones.

Ultimately, I need the ability to add products to a contact. Ideally, at the end I envision that there will be a scholarships related list displaying the name of the award, the amount, and the year that the recipient received it.

User-added image

Where the year might be something only inputted when adding a new scholarship to a recipient. Just like in adding products, there is a date field.

User-added image
Suggestions are welcomed!
Thank you!
Hi all, I am trying to complete the second step of the process automation specialist creating a validation rule however it is giving me a syntax error despite using code that others have used with no errors:
 
OR( AND( LEN(BillingState) > 2, NOT(CONTAINS(“AL:AK:AZ:AR:CA:CO:CT:DE:DC:FL:GA:HI:ID:IL:IN:IA:KS:KY:LA:ME:MD:MA:MI:MN:MS:MO:MT:NE:NV:NH:NJ:NM:NY:NC:ND:OH:OK:OR:PA:RI:SC:SD:TN:TX:UT:VT:VA:WA:WV:WI:WY”, BillingState )) ), AND( LEN(ShippingState) > 2, NOT(CONTAINS(“AL:AK:AZ:AR:CA:CO:CT:DE:DC:FL:GA:HI:ID:IL:IN:IA:KS:KY:LA:ME:MD:MA:MI:MN:MS:MO:MT:NE:NV:NH:NJ:NM:NY:NC:ND:OH:OK:OR:PA:RI:SC:SD:TN:TX:UT:VT:VA:WA:WV:WI:WY”, ShippingState)) ), NOT(OR(BillingCountry =”US”,BillingCountry =”USA”,BillingCountry =”United States”, ISBLANK(BillingCountry))), NOT(OR(ShippingCountry =”US”,ShippingCountry =”USA”,ShippingCountry =”United States”, ISBLANK(ShippingCountry))) )

I am not a dev, however I am trying to learn the basics as an admin
I have a custom controller behind a VF page that sets the value of one of the fields to be the one that the user inputs in another field:
public void saveScholarship(){
        rec = new recipient__c(School__c=sch.School__c);
        insert rec;
        sch.Recipient__c = rec.Id;
        insert sch;
        sch = new scholarship_award__c(recipient__c=rec.Id);
    }
}

However when the record is saved to my org, the ID is saved in the `recipient__c` name field instead of the name that was inputted by the user. How can I get the name to save and display instead of the ID?
Hi all. I am creating an <apex:form> with one of the fields being a master-detail relationship that looks up the parent in the UI field. When I add this to my form, it does not appear on the VF page - what am I missing here?

User-added imageCode:
<apex:page standardController="Scholarship_Award__c">
    <h1>2020-2021 Academic Year</h1>
    <apex:form >
    <!-- Hi -->
    <apex:pageBlock title="Add Scholarship Awards">
        <apex:pageBlockSection columns="2">
            <apex:inputField value="{!Scholarship_Award__c.Name}"/>
            <apex:inputField value="{!Scholarship_Award__c.Year__c}"/>
        </apex:pageBlockSection>
        <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Save"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
    </apex:form>
</apex:page>

 
Hi all, new to Apex here doing Trailhead..
I am receiving the error in the title above - here is my apex class:
 
public class AccountHandler {
    public static void insertAccount(Integer value){
        Integer counter = 1;
        //create a list
        List<Account> addAccounts = new List<Account>();
        while(counter <= value){
        //display current counter value
        system.debug('Counter value before incrementing' + counter);
        //create a new account
        Account store = new Account();
        store.Name = 'Acme Inc n' + counter;
        store.AccountNumber = 'A00n' + counter;
        addAccounts.add(store);
        system.debug(addAccounts);
        //increment counter
        counter = counter + 1;
        system.debug('Counter value after incrementing' + counter);     
        
        }
        system.debug('Size of Account list:' + addAccounts.size());
        system.debug('Elements in Account List:' + addAccounts);
        //insert
        insert addAccounts;
    }
}
And my execution code:
AccountHandler.sObjectsInsert(3);

 
Hi all,
After some digging around the Trailblazer community, I discovered that adding this funcitonality to custom objects can be done with VF and apex. I am learning visualforce anyway, so I don't mind this method.

For context, my organization awards scholarships. Where scholarship is the product, and our recipients are a custom object 'recipient'. Initially, I created three products and added the product related list to the recipient page layout, but cannot add products, only create new ones.

Ultimately, I need the ability to add products to a contact. Ideally, at the end I envision that there will be a scholarships related list displaying the name of the award, the amount, and the year that the recipient received it.

User-added image

Where the year might be something only inputted when adding a new scholarship to a recipient. Just like in adding products, there is a date field.

User-added image
Suggestions are welcomed!
Thank you!
I want to upload the multiple files in the vf page & inserted in the document object. Please help me out buddies.
  • September 24, 2015
  • Like
  • 0

Hi,

       I have one requirement to add Product standard functionality in custom object.so if anyone knows please help me.If any suggestion you have let me know.

 

Minkesh Patel.