function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sudhirn@merunetworks.comsudhirn@merunetworks.com 

Create account from custom object

I am create a new account based on custom object data. I am creating a prospect account record type. I am trying to pass ship to address information but account is not allowing to create. please advice how to create ship to address. 

I am creating account using trigger 
 
* Create Account */
  Account acc = new Account();
  acc.RecordTypeId = AccountRecordTypeID.Id; // Prospect record type
  acc.name = Deal.customer_name__c;
  acc.Industry = Deal.Industry__c;
  acc.Website = Deal.Company_Url__c;
  acc.Type = 'Prospect';                        
  //acc.ShippingStreet =  Deal.Address_Line1__c;
  //acc.ShippingCity = Deal.City__c;
  //acc.ShippingState = Deal.State__c;
  //acc.ShippingPostalCode = Deal.Zip_Postal_Code__c;
  //acc.ShippingCountry = Deal.Country__c;




Thanks
Sudhir
siddarth rajsiddarth raj
There is no clear info what actual error your getting while trying to create account but for your information there are different character size limits for shipping related fileds. 

Thanks
Sid
Mathew Andresen 5Mathew Andresen 5
Question, shouldn't the acc.RecordTypeId = AccountRecordTypeID.Id;  
be something like acc.RecordTypeId = Deal.Id?  

Assuming you are linking the Account to the deal.  If you provided all the code, it might be easier to diagnois
 
sudhirn@merunetworks.comsudhirn@merunetworks.com
trigger DealReg_To_Opportunity on DealReg__c (After Insert)
{
 
   Set<Id> idSet = Trigger.newMap.keySet();     
   
   /* Fetch Deal Reg Information for New record */ 
   DealReg__c Deal = [SELECT id, customer_name__c, deal_stage__c,
                            account_id__c, estimated_close_date__c,
                            estimated_value__c, competitor__c,
                            account__c, project_name__c,
                            distributor__c, reseller__c,
                            channel_source__c, discount_program__c,
                            ownerid, status__c, owner.type,
                            field_representative__c, theater__c,
                            Partner_Initiated__c,Partner_Led__c,K_12__c,Industry__c,Company_Url__c,Cloud_Deal_Registration__c,Product_Quantity__c,
                            Cloud_Product__c,Cloud_Service_Term__c,Cloud_Subscription_Term__c                            
                        FROM DealReg__c
                        WHERE id = :idSet ]; 
                        
                           
                        
    /* Get User Id */
    User UserDon = [SELECT ID FROM User WHERE USERNAME = 'dtrimble@merunetworks.com' limit 1];    
    User UserRoger = [SELECT ID FROM User WHERE USERNAME = 'raustin@merunetworks.com' limit 1];                 
    String OppOwner;
    
    /* Region */   
    String Region = deal.theater__c;
    
    /* Price Books */
    Pricebook2 NAMPriceID  = [SELECT Id FROM Pricebook2 where Name = 'NAM Price Book' limit 1];
    Pricebook2 EMEAPriceID = [SELECT Id FROM Pricebook2 where Name = 'EU Price Book' limit 1];
    String PriceBook;
    
    
    /* Based on region opportunit owner and price book assignment */
    if ( Region == 'NAM')
    {    
     OppOwner = UserRoger.id;
     PriceBook = NAMPriceID.Id;
    }          
    else if ( Region == 'EMEA') 
    {
     OppOwner = UserDon.id;  
     PriceBook = EMEAPriceID.Id; 
    }        
    
    /* Assigning Distributor*/
    String   Distributor;                     
    Account  WesconAccountID = [SELECT id FROM account where name = 'Westcon Group' limit 1];
    Account  ZyckoAccountID = [SELECT id FROM account where name = 'Zycko Limited' limit 1]; 
    
    /* Assign Opportunity Record Type */
    String RecordType;
    RecordType SubRecordTypeID = [Select ID From RecordType Where sObjectType = 'Opportunity' and Name = 'Subscription'];
    RecordType IndirectTypeID  = [Select ID From RecordType Where sObjectType = 'Opportunity' and Name = 'Indirect'];  
    
    /* Assign Account Record Type */
    RecordType  AccountRecordTypeID = [Select ID  From RecordType Where sObjectType = 'Account' and Name = 'Prospect'];
    
    If ( Deal.Cloud_Product__c <> NULL ) 
    {
     Distributor = Deal.distributor__c;
     RecordType = IndirectTypeID.id;
    }
    ELSE If ( Deal.Cloud_Subscription_Term__c <> NULL && Region == 'NAM' )
    {
     Distributor = WesconAccountID.Id;     
     RecordType = SubRecordTypeID.Id;
    } 
    ELSE If ( Deal.Cloud_Subscription_Term__c <> NULL && Region == 'EMEA' )
    {
     Distributor = ZyckoAccountID.Id;     
     RecordType = SubRecordTypeID.Id;
    } 
     
                        
  /* Create Account */
  Account acc = new Account();
  acc.RecordTypeId = AccountRecordTypeID.Id;
  acc.name = Deal.customer_name__c;
  acc.Industry = Deal.Industry__c;
  acc.Website = Deal.Company_Url__c;
  acc.Type = 'Prospect';                        
  //acc.ShippingStreet =  Deal.Address_Line1__c;
  //acc.ShippingCity = Deal.City__c;
  //acc.ShippingState = Deal.State__c;
  //acc.ShippingPostalCode = Deal.Zip_Postal_Code__c;
  //acc.ShippingCountry = Deal.Country__c;
  
  
  Insert acc;
  
  /* Create Opportunity */                          
       Opportunity opp = new opportunity();  
        opp.AccountId = acc.id;     
        opp.RecordTypeId = RecordType;              
        opp.name = Deal.project_name__c +  ' ' +'FOR'+' '+deal.customer_name__c;    
        opp.OwnerId = OppOwner;  
        opp.discount_program__c = 'DEALREG/PI/PL';
        opp.Abbv_Discount_Program__c =  'DR/PI/PL';  
        opp.StageName = Deal.deal_stage__c;
        opp.CloseDate = Deal.estimated_close_date__c;   
        opp.Primary_Competitor__c = deal.competitor__c;
        opp.type = 'Existing Customer';
        opp.Government_Contract__c = 'None';
        opp.leadsource = 'Deal Registration';
        opp.Partner_Driven__c = 'yes';
        opp.Partner_Account__c = Distributor;
        opp.primary_distributor__c = Distributor;
        opp.primary_reseller__c = Deal.reseller__c;
        opp.channel_source__c = deal.channel_source__c;
        opp.K_12__c  = deal.K_12__c;
        opp.Renewal_Opportunity__c = 'No';
        opp.Renewal_Incumbant_Reseller__c = 'No';
        opp.Renewal_K_12__c = 'No';    
        opp.DEALREG_SEND_QUOTE__c = 'Do Not Send';
        opp.RENEWAL_SEND_QUOTE__c = 'Do Not Send';  
        opp.Partner_Driven__c  = 'Yes';
        opp.Partner_Led__c = 'Yes';     
        opp.deal_registration__c = deal.id; 
        opp.Partner_Initiated_International__c = 'No';  
        opp.Pricebook2Id = PriceBook;  //NAM Price Book 
  
   Insert opp;
    
    /* Insert Opportunity Products */
    List<OpportunityLineItem> oliList  = new List<OpportunityLineItem>();    
    List<PricebookEntry>  pbeList  = new List<PricebookEntry>(); 
       
    String CProduct = Deal.Cloud_Product__c;
    String CST      = Deal.Cloud_Service_Term__c;
    String SUBT     = Deal.Cloud_Subscription_Term__c;
     
    
    if ( CProduct <> NULL ) 
    {
    pbeList  = [SELECT id, UnitPrice
                FROM PricebookEntry 
                WHERE   priceBook2Id = :PriceBook and ( Product2Id = :CProduct or Product2Id = :CST ) ];
    }
    ELSE if ( SUBT <> NULL )
    {
    pbeList  = [SELECT id, UnitPrice
                FROM PricebookEntry 
                WHERE   priceBook2Id = :PriceBook and  Product2Id = :SUBT ];      
    }            
    
    for(PricebookEntry pbe: pbeList){
    OpportunityLineItem oli = new OpportunityLineItem();
    oli.OpportunityId = opp.id;
    oli.PricebookEntryId = pbe.id;
    oli.Quantity = deal.Product_Quantity__c;
    oli.UnitPrice = pbe.UnitPrice;
    oliList.add(oli);
    }
    
    insert oliList;       
      
}
Please see the complete code