You need to sign in to do that
Don't have an account?
![catchforshiva catchforshiva](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
How to insert records CSV format in child Obj based on field in parent Obj without using Dataloader
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 ?
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"/>
<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(inputvalues[3]);
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;
}
}
Hi Friends...
Any one can achieve this problem....
reply as soon as ....