Cancelado

Apex class function modification needed

Apex class function requires modification and proper structure. We have the baseline for an Apex class used in Salesforce on an inbound email service. The inbound email service uses this class to parse the email subject and email message body. From the parsing, the class then needs to determine which custom object to write the new record to. The challenge is to clean up this baseline function and make it work. The issue it has at the moment is to determine how many products are ordered and quantities ordered in the inbound email message. Since this email is somewhat dynamic, the class needs to determine if there are more line items in the email body or not... and depending on that result, process it accordingly. The function code is almost there, just needs an experienced programmer..

## Deliverables

Here is a sample of the inbound email and what the program needs to parse:

* Also note that we have control (somewhat) on the email template sent to the apex class:

This is the email:

[store_name]

[oemail]

[ofirstname]

[olastname]

[oaddress]

[ocity]

[ostate]

[ozip]

[ocountry]

[ophone]

<!--START: pass-->[pass]<!--END: pass-->

<!--START: product-->[numitems]

[itemid]

<!--END: product-->Stop

This is a subset of the code. IT is where I think the problem is at the moment. This is coded in Eclipse with the [url removed, login to view] plugin. We currently have as a baseline that will need the modifications listed in the attachment.

/*

* This is our PDA Inbout Email Service Class

* It serves to capture incoming Shopping Cart emails

* Converts the email to analyze which object

* a new record will be created in.

* Email services are automated processes that use Apex classes

* to process the contents, headers, and attachments of inbound

* email.

*/

global class EmailtoApexInboundOrder implements [url removed, login to view]

{

public static String getFieldValue(String plainTextBody, String pLabel)

{

Integer startPos = [url removed, login to view](pLabel);

Integer endPos = [url removed, login to view]('\n');

return [url removed, login to view](startPos+[url removed, login to view](), endPos);

}

global [url removed, login to view] handleInboundEmail([url removed, login to view] email,

[url removed, login to view] envelope)

{

[url removed, login to view] result = new [url removed, login to view]();

// Decided not to use this portion for testing.

//String email_subject = [url removed, login to view](getFieldValue([url removed, login to view],':'));

//Double mileageInt = [url removed, login to view](getFieldValue([url removed, login to view], 'Mileage:'));

//List<Contact> contactResult = new List<Contact>();

//contactName = '%'+contactName+'%';

String order_no = [url removed, login to view];

String[] emailBody = [url removed, login to view]('\n', 0);

String ref_selling_site = emailBody[0].substring(0);

String email_address = emailBody[1].substring(0);

String first_name = emailBody[2].substring(0);

String last_name = emailBody[3].substring(0);

String street_address = emailBody[4].substring(0);

String city = emailBody[5].substring(0);

String province = emailBody[6].substring(0);

String zip = emailBody[7].substring(0);

String country = emailBody[8].substring(0);

String phone = emailBody[9].substring(0);

String password = emailBody[10].substring(0);

String quantity1 = emailBody[11].substring(0);

String sku1 = emailBody[12].substring(0);

String quantity2 = null;

String sku2 = null;

String quantity3 = null;

String sku3 = null;

String quantity4 = null;

String sku4 = null;

String quantity5 = null;

String sku5 = null;

String quantity6 = null;

String sku6 = null;

String quantity7 = null;

String sku7 = null;

String quantity8 = null;

String sku8 = null;

String quantity9 = null;

String sku9 = null;

String quantity10 = null;

String sku10 = null;

// The Apex class can consume up to 10 different ordered products for now. This should

// be the maximum amount of skus one order can place for now. This code needs revision if we

// are going to permit more than 10 different products to be purchased and processed by SF.

Integer counterI = 13;

Integer counterII = 14;

// Interger counterIII = 2;

// String counterStringValue = [url removed, login to view](counterIII);

String stopString = 'Stop';

String nextQuantity = emailBody[counterI].substring(0);

Boolean myresult = [url removed, login to view](stopString);

while (myresult!=true)

{

if (counterI = 13)

{

quantity2 = emailBody[13].substring(0);

sku2 = emailBody[14].substring(0);

}

else if (counterI = 15)

{

quantity3 = emailBody[15].substring(0);

sku3 = emailBody[16].substring(0);

}

else if (counterI = 17)

{

quantity4 = emailBody[17].substring(0);

sku4 = emailBody[18].substring(0);

}

else if (counterI = 19)

{

quantity5 = emailBody[19].substring(0);

sku5 = emailBody[20].substring(0);

}

else if (counterI = 21)

{

quantity6 = emailBody[21].substring(0);

sku6 = emailBody[22].substring(0);

}

else if (counterI = 23)

{

quantity7 = emailBody[23].substring(0);

sku7 = emailBody[24].substring(0);

}

else if (counterI = 25)

{

quantity8 = emailBody[25].substring(0);

sku8 = emailBody[26].substring(0);

}

else if (counterI = 27)

{

quantity9 = emailBody[27].substring(0);

sku9 = emailBody[28].substring(0);

}

else if (counterI = 29)

{

quantity10 = emailBody[29].substring(0);

sku10 = emailBody[30].substring(0);

}

counterI = counterI + 2;

counterII = counterII + 2;

nextQuantity = emailBody[counterI].substring(0);

myresult = [url removed, login to view](stopString);

}

Habilidades: Engenharia, MySQL, PHP, Gestão de projetos, Arquitetura de software, Teste de Software

Ver mais: apex class, which country need programmer, what is substring, substring in c, substring c, substring 0 2, static salesforce, shopping cart 6.0.14, sample apex code salesforce, salesforce one, salesforce inbound email, salesforce attachments, salesforce 15 to 18, php eclipse, order salesforce, i force com, how to write apex code in salesforce, how to use substring, function - 1 to 1, force.com eclipse, email message salesforce, eclipse for php, c template function, c substring, c string substring

Acerca do Empregador:
( 9 comentários ) Canada

ID do Projeto: #3024374