• Raghu Rao 6
  • 0 Points
  • Member since 2015
  • Sr. Manager
  • Acumen Solutions Inc.

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
  • 2
I have the following parent - Project Mgmt and related child objects - Application, Project Deliverables, Project Milestones. Application has a child called Reviews.
I need to display in the following layout in visual force page and I can pass the Application Id as input URL param.
Column 1    (Read Only Display    )                                                                                                                Column 2 (Input Form)
Project Mgmt Field 1       Project Mgmt Field 2                                                                                            Review Field 1
Project Mgmt Field 3                                                                                                                                        Review Field 2

Project Deliverables Related List (display only)
Project Milestones Related List (Display Only)

Is this possible using just custom controller or extensions?
Raghu Rao
I am trying to initiate a Visual Flow from a standard list view custom button and pass the selected Record Id as an input parameter. This is not a URL but a OnClick Javascript. I am able to initiate the flow but the flow is not able to capture the parameter being passed to it. Code below for reference. Would appreciate if someone has faced similar issue.

function getBaseURL() {
var url = location.href; // entire url including querystring - also: window.location.href;
var baseURL = url.substring(0, url.indexOf('/', 14));

if (baseURL.indexOf('http://localhost') != -1) {
// Base Url for localhost
var url = location.href; // window.location.href;
var pathname = location.pathname; // window.location.pathname;
var index1 = url.indexOf(pathname);
var index2 = url.indexOf("/", index1 + 1);
var baseLocalUrl = url.substr(0, index2);

return baseLocalUrl + "/";
else {
// Root Url for domain name
return baseURL + "/";


var url = parent.location.href;
var records = {!GETRECORDIDS($ObjectType.Application__c)};
var applId=records[0];

var baseUrl = getBaseURL();

var uriToOpen = baseUrl+encodeURI('flow/RSDCreateReview?appID='+applId+'\&'+'retURL=/a0m?fcf=00Br0000000LWqU');

if (records[0] == null) {
alert("Please select at least one Application to Review.");
} else if (records[1] != null) {
alert("You have selected more than one Application record. This will work only on the first Application record selected.");
window.open(uriToOpen );
} else

window.open(uriToOpen );
In one of Jeff Douglas's blog posts he demonstrated how to create a custom Attachment related list for specific objects. http://blog.jeffdouglas.com/2014/05/30/how-to-customize-salesforce-attachments/ 
I've implemented that code to work with our custom Project object by following his examples, but I don't know how to write the test classes for both the VisualForce page and the Apex class so that we can put this custom object into production. I would really appreciate it if someone could provide a test class for this code or at least get me started. 

The code I've written thus far is below:

The Apex Controller:
public with sharing class UploadAttachmentController {
    public String selectedType {get;set;}
    public String description {get;set;}
    public MPM4_BASE__Milestone1_Project__c project {get;set;} 
    public Project_Attachment__c attachment {get;set;}
    public String fileName {get;set;}
    public Blob fileBody {get;set;}
    public UploadAttachmentController(ApexPages.StandardController controller) { 
        this.project = (MPM4_BASE__Milestone1_Project__c)controller.getRecord();
    // creates a new Project_Attachment__c record
    private Database.SaveResult saveCustomAttachment() {
        Project_Attachment__c obj = new Project_Attachment__c();
        obj.Project__c = project.Id; 
        obj.description__c = description;
        obj.type__c = attachment.Type__c;
        // fill out cust obj fields
        return Database.insert(obj);
    // create an actual Attachment record with the Contact_Attachment__c as parent
    private Database.SaveResult saveStandardAttachment(Id parentId) {
        Database.SaveResult result;
        Attachment attachment = new Attachment();
        attachment.body = this.fileBody;
        attachment.name = this.fileName;
        attachment.parentId = parentId;
        // insert the attachment
        result = Database.insert(attachment);
        // reset the file for the view state
        fileBody = Blob.valueOf(' ');
        return result;
    * Upload process is:
    *  1. Insert new Contact_Attachment__c record
    *  2. Insert new Attachment with the new Contact_Attachment__c record as parent
    *  3. Update the Contact_Attachment__c record with the ID of the new Attachment
    public PageReference processUpload() {
        try {
            Database.SaveResult customAttachmentResult = saveCustomAttachment();
            if (customAttachmentResult == null || !customAttachmentResult.isSuccess()) {
                ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 
                  'Could not save attachment.'));
                return null;
            Database.SaveResult attachmentResult = saveStandardAttachment(customAttachmentResult.getId());
            if (attachmentResult == null || !attachmentResult.isSuccess()) {
                ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 
                  'Could not save attachment.'));            
                return null;
            } else {
                // update the custom attachment record with some attachment info
                Project_Attachment__c customAttachment = [select id from Project_Attachment__c where id = :customAttachmentResult.getId()];
                customAttachment.name = this.fileName;
                customAttachment.Attachment__c = attachmentResult.getId();
                update customAttachment;
        } catch (Exception e) {
            return null;
        return new PageReference('/'+project.Id);
    public PageReference back() {
        PageReference pgRef = new PageReference('/'+ this.project.Id);
        return pgRef; 
The VisualForce Page:
<apex:page StandardController="MPM4_BASE__Milestone1_Project__c" tabStyle="MPM4_BASE__Milestone1_Project__c" extensions="UploadAttachmentController">
 <apex:sectionHeader title="{!MPM4_BASE__Milestone1_Project__c.Name}" subtitle="Attach File"/>
 <apex:form id="form_Upload">
 <apex:pageBlock >
 <apex:pageBlockButtons >
   <apex:commandButton action="{!back}" value="Back to Project"/>
   <apex:commandButton action="{!back}" value="Cancel"/>
 <apex:pageMessages />
  <apex:pageBlockSection columns="1">
    <apex:pageBlockSectionItem >
      <apex:outputLabel value="File" for="file_File"/>
      <apex:inputFile id="file_File" value="{!fileBody}" filename="{!fileName}"/>
    <apex:pageBlockSectionItem >
      <apex:outputLabel value="Type" for="type"/>
      <apex:inputfield value="{!attachment.Type__c}" id="type" required="true"/> 
    <apex:pageBlockSectionItem >
      <apex:outputLabel value="Description" for="description"/> 
      <apex:inputTextarea id="description" value="{!description}" rows="4" cols="50"/>
    <apex:pageBlockSectionItem >
      <apex:outputLabel value="" for="uploadBtn"/> 
      <apex:commandButton id="uploadBtn" value="Attach File" action="{!processUpload}" />

Hi all,

We have the below requirement:

1. Create a Vf page and a button named 'Upload CSV' . The csv file contains lines/rows, each row contains 2 columns each of which is name of two custom objects.
For example, the csv file can contain below:

CustObj1Name, CustObj1Name2
TestName1, TestName2
Name1, Name2

2. On click of the button 'Upload CSV', a batch class should parse the csv and should upsert the two custom object records picking their respective name from csv. i.e. If we have CustObj1__c and CustObj2__c as custom objects, then these two custom object records shud be upserted by populating their name field from csv, say CustObj1__c.Obj1Name__c shud be populated with TestName1 and upsert CustObj1__c, similarly CustObj2__c.Obj2Name__c shud be populated with TestName2 and upsert CustObj2__c

Please let me know on the feasible solution for the above. If you have any sample code, please share which would be very helpful to me.

Thanks a lot!