• Francisco Corona 7
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 3
    Replies
Public class AutoConvertLeads
{
@InvocableMethod
public static void LeadAssign(List<Id> LeadIds)
{
LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true Limit 1];
List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();

List<Lead> myLeads = [Select id, name, company, Matched_Account_ID__c from Lead where id IN:LeadIds];
List<String> MatchedAccount = New List<String>();

for (Lead l:myLeads){
MatchedAccount.add(l.Matched_Account_ID__c);
}

List<Account> matchAccount = [Select id, Name from account where id IN:MatchedAccount];

Integer i=0;
for(Lead currentlead: myLeads){
for (Account a:matchAccount){
if (currentlead.Matched_Account_ID__c == a.id){
Database.LeadConvert Leadconvert = new Database.LeadConvert();
Leadconvert.setLeadId(currentlead.id);
Leadconvert.setAccountId(a.id);
Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion
MassLeadconvert.add(Leadconvert);
i++;
Break;
}
}
If (i==0)
{
Database.LeadConvert Leadconvert = new Database.LeadConvert();
Leadconvert.setLeadId(currentlead.id);
Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion
MassLeadconvert.add(Leadconvert);
}
i=0;
}

if (!MassLeadconvert.isEmpty()) {
List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
}
}
}
Hello, I have a lightning component that is working and returns data but we are trying to enable inline editing on all the fields for easy edit and save capabilities.

Below is the component, controller, and helper:

Component:

<aura:component controller="ClosePlanController"  implements="flexipage:availableForAllPageTypes" access="global">
        <aura:attribute name="closeplans" type="List" />
        <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
        <!-- Use a data table from the Lightning Design System: https://www.lightningdesignsystem.com/components/data-tables/ -->
    <div class="slds-table_edit_container slds-is-relative">    
    <table class="slds-table slds-no-cell-focus slds-table_bordered slds-table_edit slds-table_fixed-layout slds-table_resizable-cols">
          <thead>
            <tr class="slds-text-heading_label">
              <th scope="col"><div class="slds-truncate" title="ID">ID</div></th>
              <th scope="col"><div class="slds-truncate" title="Proposed Activity">Name</div></th>
              <th scope="col"><div class="slds-truncate" title="Client Owner">Type</div></th>
              <th scope="col"><div class="slds-truncate" title="Owner">Number Of Employees</div></th>
              <th scope="col"><div class="slds-truncate" title="Target Date">Ticker Symbol</div></th>
              <th scope="col"><div class="slds-truncate" title="Complete">Phone</div></th>
              <th scope="col"><div class="slds-truncate" title="Comments">Delete</div></th>
            </tr>
          </thead>
          <tbody>
            <!-- Use the Apex model and controller to fetch server side data -->
            <aura:iteration items="{!v.closeplans}" var="closeplan">
                <tr>
                    <th scope="row"><div class="slds-truncate" title="{!closeplan.Id}">{!closeplan.Id}</div></th>
                    <td><div class="slds-cell-edit" title="{!closeplan.Proposed_Activity__c}">{!closeplan.Proposed_Activity__c}</div></td>
                    <td><div class="slds-cell-edit" title="{!closeplan.Client_Owner__c}">{!closeplan.Client_Owner__c}</div></td>
                    <td><div class="slds-cell-edit" title="{!closeplan.OwnerId}">{!closeplan.OwnerId}</div></td>
                    <td><div class="slds-cell-edit" title="{!closeplan.Target_Date__c}">{!closeplan.Target_Date__c}</div></td>
                    <td><div class="slds-cell-edit" title="{!closeplan.Complete__c}">{!closeplan.Complete__c}</div></td>
                    <td><div class="slds-cell-edit" title="{!closeplan.Comments__c}">{!closeplan.Comments__c}</div></td>
                    <!--<td>
                        <form class="closeplan-form" onsubmit="{!c.deleteClosePlan}">
                          <input type="hidden" value="{!closeplan.Name}" class="closeplan-name" />
                          
                          <lightning:button
                            label="Delete"
                            iconName="utility:delete"
                            iconPosition="left"
                            variant="destructive"
                            type="submit"
                          />
                        </form>
                    </td> -->    
                </tr>
            </aura:iteration>
          </tbody>
        </table>
    </div>
      </aura:component>

Controller:

({
      doInit: function(component, event, helper) {
        // Fetch the account list from the Apex controller
        helper.getClosePlanList(component);
      }
    })


Helper:

({
      // Fetch the accounts from the Apex controller
      getClosePlanList: function(component) {
        var action = component.get('c.getClosePlans');
        // Set up the callback
        var self = this;
        action.setCallback(this, function(actionResult) {
         component.set('v.closeplans', actionResult.getReturnValue());
        });
        $A.enqueueAction(action);
      }
    })


Can you please help. Thank you,

Francisco
This is what we are trying to achieve: 

User-added image

Below you will see the component, controller and helper. 

Component:

<aura:component controller="ClosePlanController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
    
    <!-- attributes -->
    <aura:attribute name="data" type="Object"/>
    <aura:attribute name="columns" type="List"/>
    <aura:attribute name="errors" type="Object" default="[]"/>
    <aura:attribute name="draftValues" type="Object" default="[]"/>

    <!-- Imports -->
   <!-- <aura:import library="lightningcomponentdemo:mockdataFaker" property="mockdataLibrary"/>-->

    <!-- handlers-->
    <aura:handler name="init" value="{! this }" action="{! c.init }"/>

    

    <!-- the container element determine the height of the datatable -->
    <div style="height: 300px">
        <lightning:datatable
            columns="{! v.columns }"
            data="{! v.data }"
            keyField="id"
            errors="{! v.errors }"
            draftValues="{! v.draftValues }"
            onsave="{! c.handleSaveEdition }"
        />
    </div>


</aura:component>


Controller:

({
    init: function (cmp,helper) {
        cmp.set('v.columns', [
            {label: 'Proposed Activity', fieldName: 'Proposed_Activity__c ', type: 'text', editable: true, typeAttributes: { required: true }},
            {
                label: 'Target Date', fieldName: 'Target_Date__c ', type: 'date', editable: true,
                typeAttributes: {
                    year: 'numeric',
                    month: 'short',
                    day: 'numeric',
                    hour: '2-digit',
                    minute: '2-digit'
                }
            },
            {label: 'Comments', fieldName: 'Comments__c', type: 'text', editable: true }
            
        ]);
        helper.getData(cmp);
        helper.initServer().then($A.getCallback(function () {
            helper.fetchData(cmp)
        }));
    }
   /* handleSaveEdition: function (cmp, event, helper) {
        var draftValues = event.getParam('draftValues');

        helper.saveEdition(cmp, draftValues);
    },
    handleCancelEdition: function (cmp) {
        // do nothing for now...
    }*/
})


Helper:

({
    getData : function(cmp) {
        var action = cmp.get('c.getClosePlans');
        action.setCallback(this, $A.getCallback(function (response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                cmp.set('v.mydata', response.getReturnValue());
            } else if (state === "ERROR") {
                var errors = response.getError();
                console.error(errors);
            }
        }));
        $A.enqueueAction(action);
    }
})


They all save, but we get the following error message when we are trying to paste it on the lightning record page.

User-added image


Can you please help. We are trying to create a component that will allow us to create multiple records from a single screen, similar to Manage Contact Roles.

Francisco
Public class AutoConvertLeads
{
@InvocableMethod
public static void LeadAssign(List<Id> LeadIds)
{
LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true Limit 1];
List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();

List<Lead> myLeads = [Select id, name, company, Matched_Account_ID__c from Lead where id IN:LeadIds];
List<String> MatchedAccount = New List<String>();

for (Lead l:myLeads){
MatchedAccount.add(l.Matched_Account_ID__c);
}

List<Account> matchAccount = [Select id, Name from account where id IN:MatchedAccount];

Integer i=0;
for(Lead currentlead: myLeads){
for (Account a:matchAccount){
if (currentlead.Matched_Account_ID__c == a.id){
Database.LeadConvert Leadconvert = new Database.LeadConvert();
Leadconvert.setLeadId(currentlead.id);
Leadconvert.setAccountId(a.id);
Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion
MassLeadconvert.add(Leadconvert);
i++;
Break;
}
}
If (i==0)
{
Database.LeadConvert Leadconvert = new Database.LeadConvert();
Leadconvert.setLeadId(currentlead.id);
Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion
MassLeadconvert.add(Leadconvert);
}
i=0;
}

if (!MassLeadconvert.isEmpty()) {
List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
}
}
}