Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- Re: How to insert records CSV format in child Obj ...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
How to insert records CSV format in child Obj based on field in parent Obj without using Dataloader
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-09-2012 02:16 AM
Parent Object:
PName: (Primary field)
price:
county:
customerID:(child lookup field)
Given the above record on the parent object, I want the following records to be automatically created on the child object:
Child Object:
customerID:
customerName:
Address:
Tprice:
How to archive this ?
Re: How to insert records CSV format in child Obj based on field in parent Obj without using Dataloa
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-09-2012 02:30 AM - edited 12-09-2012 02:32 AM
This code :
VF Code
<apex:page controller="UploadDoc">
<apex:form >
<apex:sectionHeader title="Upload a Document into Salesforce"/>
<apex:pageblock >
<apex:panelGroup >
<center>
Import DTR File
<apex:inputfile value="{!myImage}"/>
<P align="">(file formats .csv, .txt)</p><br/><br/><br/>
<apex:commandButton action="{!readFile}" value="Submit"/> &nbs
<apex:commandButton action="{!cancel}" value="Cancel" immediate="true"/>
</center>
</apex:panelGroup>
</apex:pageblock>
</apex:form>
</apex:page>
Apex Class:
public class UploadDoc {
public PageReference cancel() {
return null;
}
public blob myImage { get; set; }
//file (blob) as String
public PageReference readFile() {
String fContent=myImage.toString();
// line by line
String[] NewLineSplit=fContent.split('\n');
List<Property__c> lstpropty=new List<Property__c>();
for(Integer i=0;i<NewLineSplit.size();i++){
//Each line (record)
String[] inputvalues = NewLineSplit[i].split(',');
Property__c objpropty=new Property__c();
objpropty.Name=inputvalues[0];
objpropty.price__c= Integer.valueOf(inputvalues[1]);
objpropty.county__c= Integer.valueOf(inputvalues[2]);
objpropty.Name.CustmerID__c=String.valueOf(inputva
lstpropty.add(objpropty);
}
try
{
// Inserting the data in to object
insert lstpropty;
}
catch(Exception e)
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'An error has occured. Please check the template or try again later'+e));
return null;
}
}
Re: How to insert records CSV format in child Obj based on field in parent Obj without using Dataloa
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-13-2012 03:35 AM
Hi Friends...
Any one can achieve this problem....
reply as soon as ....

