Skip to Content
0
Former Member
Aug 03, 2016 at 09:41 PM

Lead and Opportunity Enhancement

479 Views

Hi Experts,

Need your help, I am trying to achieve below mentioned requirement via SDK:

Business Process :

When a "New Marketing Lead" is created, later which is converted into an Opportunity, a "Prospect" and "Contact" gets created in the background from the information (Company Name) on the Lead.

The Prospect/Account which is created should have the same owner field as the Owner of the Lead.

Technical:

- Lead (Existing Account “Unchecked”) >> converted to Opportunity via Actions from the detail screen.

- In the background a Prospect and Contact record is created.

- The Owner field value from Lead should get copied over to the above created Prospect i.e. Employee responsible on Lead-Sales & Marketing tab should be copied to Employee responsible on Prospect-Account Team tab.

Code Snippet :- I am coding in "Before Save" event of "Opportunity". I am able to read all data in the event, i.e. Lead ID, Lead Owner, but the issue I am getting while trying to copy Lead Owner to Account Owner is that Account is not saved yet,due to which I cannot query the customer and hence cannot access Customer attributes while saving. Please help me in accessing buffer data of customer.

Code:-

var elLead_Root : elementsof Lead;

var lead_data : elementsof Lead;

var instLead;

var query;

var elLead_Party : elementsof Lead.Party;

var account_id; var employee;

var regex = "^0*";

var qryLead_Root_QueryByElements;

var test = this.ID;

var selParamsLead_Root_QueryByElements;

var customer_query;

var customer_selection_param;

var customer_col;

var create_employee : elementsof Customer.CurrentEmployeeResponsible;

var colQryResult;

var lead_count = this.BusinessTransactionDocumentReference.Lead.Count();

if (lead_count > 0)

{

var Lid = this.BusinessTransactionDocumentReference.Lead.GetFirst().ID; //this.BusinessTransactionDocumentReference.Lead.GetFirst( );

var res = this.BusinessTransactionDocumentReference.Lead.GetFirst().ResponsibleEmployeeParty;

var test1 = "t";

if (!this.BusinessTransactionDocumentReference.Lead.GetFirst().ID.IsInitial())

{

qryLead_Root_QueryByElements = Lead.QueryByElements;

selParamsLead_Root_QueryByElements = qryLead_Root_QueryByElements.CreateSelectionParams();

selParamsLead_Root_QueryByElements.Add(qryLead_Root_QueryByElements.ID.content, "I", "EQ", Lid.content);

colQryResult = qryLead_Root_QueryByElements.Execute(selParamsLead_Root_QueryByElements);

if (colQryResult.Count() > 0)

{

var lead_data1 = colQryResult.GetFirst();

if (lead_data1.Party.Count() > 0)

{

foreach (var party in lead_data1.Party)

{

if (party.RoleCode == "31")

{

account_id = party.PartyKey.PartyID.content;

account_id = account_id.ReplaceRegex(regex, "");

}

if (party.RoleCode == "39")

{

employee = party.PartyKey.PartyID.content;

employee = employee.ReplaceRegex(regex, "");

}

}

if (!account_id.IsInitial() && !employee.IsInitial())

{

customer_query = Customer.QueryByBusinessObjectCustomer;

customer_selection_param = customer_query.CreateSelectionParams();

customer_selection_param.Add(customer_query.InternalID, "I", "EQ", account_id);

customer_col = customer_query.Execute(customer_selection_param);

if (customer_col.Count( ) > 0)

{

var customer = customer_col.GetFirst( );

create_employee.EmployeeID.content = employee;

create_employee.PartyRoleCode = "142";

// Customer. = account_id;

customer.CurrentEmployeeResponsible.Create( create_employee );

}

}

}

}

}

}

Please suggest if any other possible approach can be used in order to achieve this requirement.

Thanks,

Aruditi