Table of Contents

  1. Install ShipAutomation Package
  2. Define object IDs and Load Preference
  3. Create the Bulk Shipment object
  4. Select the Object you would like to ship to
  5. Create and Insert the Queued Shipment
  6. The Full Code Sample

1. Install ShipAutomation Package

Before writing APEX code, please install the ShipAutomate package here

2. Define object IDs and Load Preference

Id prefId = 'a038000000cErPP'; // a038000000cErPP - 630002141 FedEx
Id contactId = '0038000001z5bNl';
Id intlCommodityDataId = 'a0I8000000GszdF';
Id commercialInvoiceId = 'a0L8000000EA35c';
Id naftaCoId = 'a0M80000009yDq3';
Id proFormaInvoiceId = 'a0N8000000Csxcr';
 
zkfedex__ShipmatePreference__c shipmatePref = [SELECT zkfedex__CompanyName__c, zkfedex__ShippingIsResidential__c, zkfedex__ShippingCity__c,
zkfedex__ShippingCountry__c, zkfedex__SenderEMailDefault__c, zkfedex__SenderPhoneDefault__c,
zkfedex__ShippingState__c, zkfedex__ShippingStreet__c, zkfedex__ShippingPostalCode__c,
zkfedex__FedExAccountNumber__c, zkfedex__BillingCountry__c,
zkfedex__DropoffTypeDefault__c, zkfedex__LabelImageTypeDefault__c
FROM zkfedex__ShipmatePreference__c
WHERE Id = :prefId];

3. Create the Bulk Shipment object

// 1. zkfedex__BulkShipment__c object
zkfedex__BulkShipment__c bulkShipment = new zkfedex__BulkShipment__c (
zkfedex__ShipmatePreference__c = shipmatePref.Id
);
insert bulkShipment;

4. Select the object you'd like to ship to

// Joe Collins
Contact con = [
SELECT MailingCity, Account.Name, MailingCountry,
 Email, FirstName, LastName,
Phone, MailingState, MailingStreet,
  MailingPostalCode
FROM Contact
WHERE Id = :contactId];

5. Create and insert the QueuedShipment

List queuedShipmentsToInsert = new List();zkfedex__QueuedShipment__c queuedShipment = new zkfedex__QueuedShipment__c (
zkfedex__BulkShipment__c = bulkShipment.Id,
zkfedex__ShipDate__c = Date.today(),
zkfedex__DropoffType__c = 'STATION',
zkfedex__LabelImageType__c = shipmatePref.zkfedex__LabelImageTypeDefault__c,
zkfedex__ServiceType__c = 'International: FedEx International Economy',
zkfedex__PackagingType__c = 'Your Packaging',
zkfedex__WeightDimensionUnits__c = 'LB / IN',
// international fields
zkfedex__DocumentContentType__c = 'NON_DOCUMENTS',// NON_DOCUMENTS OR DOCUMENTS_ONLY
zkfedex__DutiesPaymentType__c = 'SENDER',
// set duties
zkfedex__DutiesPayorAccount__c = shipmatePref.zkfedex__FedExAccountNumber__c, // intl info
zkfedex__DutiesPayorAccountCountry__c = shipmatePref.zkfedex__BillingCountry__c, // intl info


// sender info
zkfedex__SenderName__c = shipmatePref.zkfedex__CompanyName__c,
zkfedex__SenderIsResidential__c = shipmatePref.zkfedex__ShippingIsResidential__c,
zkfedex__SenderCity__c = shipmatePref.zkfedex__ShippingCity__c,
zkfedex__SenderCompany__c = shipmatePref.zkfedex__CompanyName__c,
zkfedex__SenderCountry__c = shipmatePref.zkfedex__ShippingCountry__c,
zkfedex__SenderEmail__c = shipmatePref.zkfedex__SenderEMailDefault__c,
zkfedex__SenderPhone__c = shipmatePref.zkfedex__SenderPhoneDefault__c,
zkfedex__SenderState__c = shipmatePref.zkfedex__ShippingState__c,
zkfedex__SenderStreet__c = shipmatePref.zkfedex__ShippingStreet__c,
zkfedex__SenderPostalCode__c = shipmatePref.zkfedex__ShippingPostalCode__c,

// recipient info
zkfedex__RecipientIsResidential__c = false,
zkfedex__RecipientCity__c = con.MailingCity,
zkfedex__RecipientCompany__c = con.Account.Name,
zkfedex__RecipientCountry__c = con.MailingCountry,
zkfedex__RecipientEmail__c = con.Email,
zkfedex__RecipientName__c = con.FirstName + ' ' + con.LastName,
zkfedex__RecipientPhone__c = con.Phone,
zkfedex__RecipientState__c = con.MailingState,
zkfedex__RecipientStreet__c = con.MailingStreet,
zkfedex__RecipientPostalCode__c = con.MailingPostalCode,
zkfedex__PaymentType__c = 'SENDER',
zkfedex__Contact__c = con.Id
);
insert queuedShipment;

6. The Full Code Sample

// collect record ids
Id prefId = 'a038000000hpRrN'; // a038000000cErPP - 630156343 FedEx
Id contactId = '0038000001z5bNl';
Id intlCommodityDataId = 'a0I8000000GszdF';
Id commercialInvoiceId = 'a0L8000000EA35c';
Id naftaCoId = 'a0M80000009yDq3';
Id proFormaInvoiceId = 'a0N8000000Csxcr';

zkfedex__ShipmatePreference__c shipmatePref = [
SELECT zkfedex__CompanyName__c, zkfedex__ShippingIsResidential__c, zkfedex__ShippingCity__c,
  zkfedex__ShippingCountry__c, zkfedex__SenderEMailDefault__c, zkfedex__SenderPhoneDefault__c,
  zkfedex__ShippingState__c, zkfedex__ShippingStreet__c, zkfedex__ShippingPostalCode__c,
  zkfedex__FedExAccountNumber__c, zkfedex__BillingCountry__c,
  zkfedex__DropoffTypeDefault__c, zkfedex__LabelImageTypeDefault__c
FROM zkfedex__ShipmatePreference__c
WHERE Id = :prefId];

// 1. zkfedex__BulkShipment__c object
zkfedex__BulkShipment__c bulkShipment = new zkfedex__BulkShipment__c (
zkfedex__ShipmatePreference__c = shipmatePref.Id
);
insert bulkShipment;

// Joe Collins
Contact con = [
SELECT MailingCity, Account.Name, MailingCountry,
 Email, FirstName, LastName,
Phone, MailingState, MailingStreet,
  MailingPostalCode
FROM Contact
WHERE Id = :contactId];

// 2. zkfedex__QueuedShipment__c object
List<zkfedex__QueuedShipment__c> queuedShipmentsToInsert = new List<zkfedex__QueuedShipment__c>();
zkfedex__QueuedShipment__c queuedShipment = new zkfedex__QueuedShipment__c (
zkfedex__BulkShipment__c = bulkShipment.Id,
zkfedex__ShipDate__c = Date.today(),
zkfedex__DropoffType__c = 'STATION',
zkfedex__LabelImageType__c = shipmatePref.zkfedex__LabelImageTypeDefault__c,
zkfedex__ServiceType__c = 'International: FedEx International Economy',
zkfedex__PackagingType__c = 'Your Packaging',
zkfedex__WeightDimensionUnits__c = 'LB / IN',
// international fields
zkfedex__DocumentContentType__c = 'NON_DOCUMENTS',// NON_DOCUMENTS OR DOCUMENTS_ONLY
zkfedex__DutiesPaymentType__c = 'SENDER',
// set duties
zkfedex__DutiesPayorAccount__c = shipmatePref.zkfedex__FedExAccountNumber__c, // intl info
zkfedex__DutiesPayorAccountCountry__c = shipmatePref.zkfedex__BillingCountry__c, // intl info


// sender info
zkfedex__SenderName__c = shipmatePref.zkfedex__CompanyName__c,
zkfedex__SenderIsResidential__c = shipmatePref.zkfedex__ShippingIsResidential__c,
zkfedex__SenderCity__c = shipmatePref.zkfedex__ShippingCity__c,
zkfedex__SenderCompany__c = shipmatePref.zkfedex__CompanyName__c,
zkfedex__SenderCountry__c = shipmatePref.zkfedex__ShippingCountry__c,
zkfedex__SenderEmail__c = shipmatePref.zkfedex__SenderEMailDefault__c,
zkfedex__SenderPhone__c = shipmatePref.zkfedex__SenderPhoneDefault__c,
zkfedex__SenderState__c = shipmatePref.zkfedex__ShippingState__c,
zkfedex__SenderStreet__c = shipmatePref.zkfedex__ShippingStreet__c,
zkfedex__SenderPostalCode__c = shipmatePref.zkfedex__ShippingPostalCode__c,

// recipient info
zkfedex__RecipientIsResidential__c = false,
zkfedex__RecipientCity__c = con.MailingCity,
zkfedex__RecipientCompany__c = con.Account.Name,
zkfedex__RecipientCountry__c = con.MailingCountry,
zkfedex__RecipientEmail__c = con.Email,
zkfedex__RecipientName__c = con.FirstName + ' ' + con.LastName,
zkfedex__RecipientPhone__c = con.Phone,
zkfedex__RecipientState__c = con.MailingState,
// zkfedex__RecipientState__c = 'London',
zkfedex__RecipientStreet__c = con.MailingStreet,
zkfedex__RecipientPostalCode__c = con.MailingPostalCode,
zkfedex__PaymentType__c = 'SENDER',
zkfedex__Contact__c = con.Id
);
insert queuedShipment;

zkfedex__QueuedShipment__c queuedShipment2 = new zkfedex__QueuedShipment__c (
zkfedex__BulkShipment__c = bulkShipment.Id,
zkfedex__ShipDate__c = Date.today(),
zkfedex__DropoffType__c = 'STATION',
zkfedex__LabelImageType__c = shipmatePref.zkfedex__LabelImageTypeDefault__c,
zkfedex__ServiceType__c = 'International: FedEx International Economy',
zkfedex__PackagingType__c = 'Your Packaging',
zkfedex__WeightDimensionUnits__c = 'LB / IN',
// international fields
zkfedex__DocumentContentType__c = 'NON_DOCUMENTS',// NON_DOCUMENTS OR DOCUMENTS_ONLY
zkfedex__DutiesPaymentType__c = 'SENDER',
// set duties
zkfedex__DutiesPayorAccount__c = shipmatePref.zkfedex__FedExAccountNumber__c, // intl info
zkfedex__DutiesPayorAccountCountry__c = shipmatePref.zkfedex__BillingCountry__c, // intl info


// sender info
zkfedex__SenderName__c = shipmatePref.zkfedex__CompanyName__c,
zkfedex__SenderIsResidential__c = shipmatePref.zkfedex__ShippingIsResidential__c,
zkfedex__SenderCity__c = shipmatePref.zkfedex__ShippingCity__c,
zkfedex__SenderCompany__c = shipmatePref.zkfedex__CompanyName__c,
zkfedex__SenderCountry__c = shipmatePref.zkfedex__ShippingCountry__c,
zkfedex__SenderEmail__c = shipmatePref.zkfedex__SenderEMailDefault__c,
zkfedex__SenderPhone__c = shipmatePref.zkfedex__SenderPhoneDefault__c,
zkfedex__SenderState__c = shipmatePref.zkfedex__ShippingState__c,
zkfedex__SenderStreet__c = shipmatePref.zkfedex__ShippingStreet__c,
zkfedex__SenderPostalCode__c = shipmatePref.zkfedex__ShippingPostalCode__c,

// recipient info
zkfedex__RecipientIsResidential__c = false,
zkfedex__RecipientCity__c = con.MailingCity,
zkfedex__RecipientCompany__c = con.Account.Name,
zkfedex__RecipientCountry__c = con.MailingCountry,
zkfedex__RecipientEmail__c = con.Email,
zkfedex__RecipientName__c = con.FirstName + ' ' + con.LastName,
zkfedex__RecipientPhone__c = con.Phone,
zkfedex__RecipientState__c = con.MailingState,
// zkfedex__RecipientState__c = 'London',
zkfedex__RecipientStreet__c = con.MailingStreet,
zkfedex__RecipientPostalCode__c = con.MailingPostalCode,
zkfedex__PaymentType__c = 'SENDER',
zkfedex__Contact__c = con.Id
);
insert queuedShipment2;

queuedShipmentsToInsert.add(queuedShipment);
queuedShipmentsToInsert.add(queuedShipment2);

// 3. zkfedex__QueuedPackage__c object
List<zkfedex__QueuedPackage__c> queuedPackagesToInsert = new List<zkfedex__QueuedPackage__c>();

for (zkfedex__QueuedShipment__c qs : queuedShipmentsToInsert) {
zkfedex__QueuedPackage__c queuedPackage = new zkfedex__QueuedPackage__c (
zkfedex__DeclaredValue__c = 10,
zkfedex__Weight__c = 2,
zkfedex__QueuedShipment__c = qs.Id          
);
queuedPackagesToInsert.add(queuedPackage);
}

insert queuedPackagesToInsert;

// create international commodity items
List<zkfedex__QueuedInternationalCommodity__c> queuedIntlCommodityList = new List<zkfedex__QueuedInternationalCommodity__c>();
// case 1
zkfedex__QueuedInternationalCommodity__c intlCommodity1 = new zkfedex__QueuedInternationalCommodity__c();
intlCommodity1.zkfedex__CiMarksAndNumbers__c  = null;
intlCommodity1.zkfedex__CountryOfManufacture__c  = 'US';
intlCommodity1.zkfedex__Description__c  = 'collapsible umbrella';
intlCommodity1.zkfedex__DocumentCommodityDescription__c  = null;
intlCommodity1.zkfedex__ExportLicenseExpirationDate__c  = null;
intlCommodity1.zkfedex__ExportLicenseNumber__c  = null;
intlCommodity1.zkfedex__HarmonizedCode__c  = '6601.91.00';
intlCommodity1.zkfedex__NaftaNetCostDateRangeEnd__c  = Date.today().addDays(1);
intlCommodity1.zkfedex__NaftaNetCostDateRangeStart__c  = Date.today().addDays(-1);
intlCommodity1.zkfedex__NaftaNetCostMethod__c  = 'NC';
intlCommodity1.zkfedex__NumberOfPieces__c  = 1;
intlCommodity1.zkfedex__PartNumber__c  = 'UM-12344';
intlCommodity1.zkfedex__NaftaPreferenceCriterion__c  = 'A';
intlCommodity1.zkfedex__NaftaProducerDetermination__c  = 'NO_1';
intlCommodity1.zkfedex__Quantity__c  = 1;
intlCommodity1.zkfedex__QuantityUnits__c  = 'EA';
intlCommodity1.zkfedex__UnitPrice__c  = 10;
intlCommodity1.zkfedex__Weight__c  = 2;
intlCommodity1.zkfedex__WeightUnits__c  = 'LB';
intlCommodity1.zkfedex__QueuedShipment__c = queuedShipment.Id;
intlCommodity1.zkfedex__SequenceNumber__c = 1;
queuedIntlCommodityList.add(intlCommodity1);

// case 2
zkfedex__QueuedInternationalCommodity__c intlCommodity2 = new zkfedex__QueuedInternationalCommodity__c();
intlCommodity2.zkfedex__CiMarksAndNumbers__c  = null;
intlCommodity2.zkfedex__CountryOfManufacture__c  = 'US';
intlCommodity2.zkfedex__Description__c  = 'collapsible umbrella';
intlCommodity2.zkfedex__DocumentCommodityDescription__c  = null;
intlCommodity2.zkfedex__ExportLicenseExpirationDate__c  = null;
intlCommodity2.zkfedex__ExportLicenseNumber__c  = null;
intlCommodity2.zkfedex__HarmonizedCode__c  = '6601.91.00';
intlCommodity2.zkfedex__NaftaNetCostDateRangeEnd__c  = Date.today().addDays(1);
intlCommodity2.zkfedex__NaftaNetCostDateRangeStart__c  = Date.today().addDays(-1);
intlCommodity2.zkfedex__NaftaNetCostMethod__c  = 'NC';
intlCommodity2.zkfedex__NumberOfPieces__c  = 1;
intlCommodity2.zkfedex__PartNumber__c  = 'UM-12344';
intlCommodity2.zkfedex__NaftaPreferenceCriterion__c  = 'A';
intlCommodity2.zkfedex__NaftaProducerDetermination__c  = 'NO_1';
intlCommodity2.zkfedex__Quantity__c  = 1;
intlCommodity2.zkfedex__QuantityUnits__c  = 'EA';
intlCommodity2.zkfedex__UnitPrice__c  = 10;
intlCommodity2.zkfedex__Weight__c  = 2;
intlCommodity2.zkfedex__WeightUnits__c  = 'LB';
intlCommodity2.zkfedex__QueuedShipment__c = queuedShipment2.Id;
intlCommodity2.zkfedex__SequenceNumber__c = 1;
queuedIntlCommodityList.add(intlCommodity2);


insert queuedIntlCommodityList;

// create documents
zkfedex__QueuedShipmentDocuments__c queuedShipmentDocuments = new zkfedex__QueuedShipmentDocuments__c();
queuedShipmentDocuments.zkfedex__Queued_Shipment__c = queuedShipment.Id;
queuedShipmentDocuments.zkfedex__CO__c = false;
queuedShipmentDocuments.zkfedex__CommercialInvoice__c = null;
queuedShipmentDocuments.zkfedex__CommercialInvoiceLetterHead__c = 'IMAGE_1';
queuedShipmentDocuments.zkfedex__CommercialInvoiceSignature__c = 'IMAGE_2';
queuedShipmentDocuments.zkfedex__NaftaCo__c = null;
queuedShipmentDocuments.zkfedex__NaftaCoSignature__c = 'IMAGE_1';
queuedShipmentDocuments.zkfedex__OverridePaperlessForIntlDocuments__c = true;
// queuedShipmentDocuments.zkfedex__ProFormaInvoice__c = proFormaInvoiceId;
// queuedShipmentDocuments.zkfedex__ProFormaInvoiceLetterHead__c = 'IMAGE_1';
// queuedShipmentDocuments.zkfedex__ProFormaInvoiceSignature__c = 'IMAGE_2';
queuedShipmentDocuments.zkfedex__ImporterAccount__c = null;
queuedShipmentDocuments.zkfedex__ImporterSameAsConsignee__c = true;
insert queuedShipmentDocuments;

zkfedex__QueuedShipmentDocuments__c queuedShipmentDocuments2 = new zkfedex__QueuedShipmentDocuments__c();
queuedShipmentDocuments2.zkfedex__Queued_Shipment__c = queuedShipment2.Id;
queuedShipmentDocuments2.zkfedex__CO__c = false;
queuedShipmentDocuments2.zkfedex__CommercialInvoice__c = null;
queuedShipmentDocuments2.zkfedex__CommercialInvoiceLetterHead__c = 'IMAGE_1';
queuedShipmentDocuments2.zkfedex__CommercialInvoiceSignature__c = 'IMAGE_2';
queuedShipmentDocuments2.zkfedex__NaftaCo__c = null;
queuedShipmentDocuments2.zkfedex__NaftaCoSignature__c = 'IMAGE_1';
queuedShipmentDocuments2.zkfedex__OverridePaperlessForIntlDocuments__c = false;
queuedShipmentDocuments2.zkfedex__ImporterAccount__c = null;
queuedShipmentDocuments2.zkfedex__ImporterSameAsConsignee__c = true;
insert queuedShipmentDocuments2;


zkfedex__QueuedExportDetails__c queuedExportDetails = new zkfedex__QueuedExportDetails__c();
queuedExportDetails.zkfedex__QueuedShipment__c = queuedShipment.Id;
queuedExportDetails.zkfedex__B13aFilingOption__c = '123';
// The proper format for an ITN number is AES XYYYYMMDDNNNNNN where YYYYMMDD is date and NNNNNN are numbers generated by the AES.
queuedExportDetails.zkfedex__ExportComplianceStatement__c = 'AES X20161018123456'; // 'NO EEI 30.37(f)'
queuedExportDetails.zkfedex__PermitNumber__c = '123';
insert queuedExportDetails;

zkfedex__QueuedExportDetails__c queuedExportDetails2 = new zkfedex__QueuedExportDetails__c();
queuedExportDetails2.zkfedex__QueuedShipment__c = queuedShipment2.Id;
queuedExportDetails2.zkfedex__B13aFilingOption__c = '123';
// The proper format for an ITN number is AES XYYYYMMDDNNNNNN where YYYYMMDD is date and NNNNNN are numbers generated by the AES.
queuedExportDetails2.zkfedex__ExportComplianceStatement__c = 'AES X20161018123456'; // 'NO EEI 30.37(f)'
queuedExportDetails2.zkfedex__PermitNumber__c = '123';
insert queuedExportDetails2;

// validation
// String batchId = zkfedex.BulkShipmentInterface.validateBulkShipment(bulkShipment.Id, true);
String batchId = zkfedex.BulkShipmentInterface.processBulkShipment(bulkShipment.Id);
System.debug('BATCH ID :' + batchId);
Did this answer your question?