0

When I insert the Order record, the Order saves but the custom phone number field does not. What are the parameters for saving a phone number field in Apex?

Order o = new Order(AccountId = a.Id, OwnerId = UserInfo.getUserId(), Pricebook2Id = Test.getStandardPricebookId(),
            ShipToContactId = c.Id,
            Status = 'Active',
            EffectiveDate = Date.newInstance(DateTime.now().year(),DateTime.now().month(),DateTime.now().day()),
            Requested_Delivery_Date__c = Date.newInstance(DateTime.now().year(),DateTime.now().month(),DateTime.now().day() + 1),
            Date_Fulfilled__c = Date.newInstance(DateTime.now().year(),DateTime.now().month(),DateTime.now().day() + 1),
            Ship_to_Phone__c = '2345678901'
    );
    system.debug(o.Ship_to_Phone__c);
    insert o;
    system.debug(o.Ship_to_Phone__c);
    o = [SELECT Id, ShipToContact.LastName, Ship_to_Phone__c FROM Order WHERE ShipToContact.LastName = 's********' LIMIT 1];
    system.debug(o);
10
  • Please edit your question with minimal code illustrating the problem, that is always useful to get a more precise answer.
    – Raul
    Commented May 4, 2022 at 16:07
  • @Raul cool, that is good to go Commented May 4, 2022 at 16:21
  • Code looks alright, just to rule out possibility that you may be looking at different data, Is it possible that you have multiple records for result that is returned via soql? If you use same data and create record from Salesforce UI do you see same behavior?
    – Raul
    Commented May 4, 2022 at 16:29
  • they're the same object with the same SF ID Commented May 4, 2022 at 16:33
  • 1
    Do you have other automation that could be clearing this value? E.g. a second trigger, a flow or process builder?
    – Phil W
    Commented May 4, 2022 at 16:54

1 Answer 1

-1

Maybe trying using this way work

Order o = new Order();
o.AccountId = a.Id;
o.OwnerId = UserInfo.getUserId();
o.Pricebook2Id = Test.getStandardPricebookId();
o.ShipToContactId = c.Id;
o.Status = 'Active';
o.EffectiveDate = Date.newInstance(DateTime.now().year(),DateTime.now().month(),DateTime.now().day());
o.Requested_Delivery_Date__c = Date.newInstance(DateTime.now().year(),DateTime.now().month(),DateTime.now().day()+ 1);
o.Date_Fulfilled__c = Date.newInstance(DateTime.now().year(),DateTime.now().month(),DateTime.now().day()+ 1);
o.Ship_to_Phone__c = '2345678901';   

system.debug(o.Ship_to_Phone__c);
insert o;
system.debug(o.Ship_to_Phone__c);
o = [SELECT Id, ShipToContact.LastName, Ship_to_Phone__c FROM Order WHERE ShipToContact.LastName = 's********' LIMIT 1];
system.debug(o);
1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented May 4, 2022 at 19:09

You must log in to answer this question.

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