2

When i upload a csv it must create account, contact, opportunity. In my custom lead i am having custom field company name, company street, company city, comapny state, company postal code.

When i upload csv file,this fields must be mapped to "Billing Address" field on "Account". How this can be done. i didn't how to map this fileds.

Apex code:

public class FileUploaderAll
{
public FileUploaderAll(ApexPages.StandardController controller) {
}
public PageReference fileAccess() {
return null;
}
public FileUploaderAll(){
}
public string nameFile{get;set;}
public Blob contentFile{get;set;}
String[] filelines = new String[]{};
List<Account> accstoupload;
List<Contact> contoupload;
List<Opportunity> opptoupload;
List<CustomLead__c> custtoupload;
List<String> acctNames;

List<Account> newAccts = new List<Account>();
public Pagereference ReadFile()
{
nameFile=contentFile.toString();
filelines = nameFile.split('\n');
accstoupload = new List<Account>();
contoupload = new List<Contact>();
opptoupload = new List<Opportunity>();
custtoupload = new List<CustomLead__c>();
acctNames = new List<String>();
List<Account> existingAccts =new List<Account>();
for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');
Account a = new Account();
a.Name = inputvalues[0];
acctNames.add(a.Name);
    accstoupload.add(a);
}
existingAccts = [SELECT Id, Name FROM Account where name in :acctNames];
//create a map with names as key
Map<String, Id> acctNamesIdMap = new Map<String, Id>();
// load the map - this will help you find out if an account name exists already
for (Account acct : existingAccts)
{
acctNamesIdMap.put(acct.Name, acct.Id);
System.debug('******Sai******');
}

for (Account acct : accstoupload)
{
//if account name does not exist in map, add it to list of new accounts
if (!acctNamesIdMap.containsKey(acct.Name))
//if (!acctNamesIdMap.containsKey(acct.Id))
{
newAccts.add(acct);
}

}

try
{

insert newAccts;
ApexPages.Message msg = new ApexPages.Message(ApexPages.severity.info,'AccountName with Account Id are the new Account created.Related Contact and Opportunity also created');
ApexPages.Message msg1 = new ApexPages.Message(ApexPages.severity.info,'AccountName without Account Id are the existing Accounts');
ApexPages.addMessage(msg);
ApexPages.addMessage(msg1);

}
catch (Exception e)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'Account     Name already exist, change Account Name and try again');
ApexPages.addMessage(errormsg);    
}
//return null;
for (Integer i=1;i<filelines.size();i++)
{
String[] inputconvalues = new String[]{};
inputconvalues = filelines[i].split(',');
Contact con = new Contact();
for(account a: accstoupload)
{
con.AccountId = accstoupload[i-1].id;
//con.AccountId = a.Id;
}
//con.Account= inputconvalues[0];
if(con.AccountId!= null){
con.Lastname = inputconvalues[1];
con.Lastname_lead__c = inputconvalues[2];
contoupload.add(con);
}}
try
{
insert contoupload;

1 Answer 1

0

The Billing Address fields are...

  • BillingStreet
  • BillingCity
  • BillingState
  • BillingPostalCode
  • BillingCountry

The same is true for Shipping Address, just apply the Shipping prefix instead to the above.

Here is the full list of fields on the Account object from the Salesforce docs.

3
  • Thanks a lot for the reply @ Andrew. It helps me to resolve my issue. Commented Apr 27, 2013 at 7:35
  • Your Welcome! :) Commented Apr 28, 2013 at 8:58
  • @AndrewFawcett I can't see BillingStreet and other fields in Custom metadata entity field definition. How could I do that? :( Commented Mar 5, 2018 at 9:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .