+ Start a Discussion
RajbharathRajbharath 
I wrote the following code for Lead conversion, but I know that it is not properly bulkified. I have tried to bulkify it, but facing some issues.  Please guide me on how to bulkify this code, so that I can use it as reference in the future.
 
public class LeadInsertTriggerHandler {

public static void AfterInsert(List<Lead> lstLeads)
{
    LeadStatus convertStatus = [select MasterLabel from LeadStatus where IsConverted = true limit 1];
    List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();

    for (Lead lead: lstLeads) {
        if (!lead.isConverted) {
            Database.LeadConvert lc = new Database.LeadConvert();

            lc.setLeadId(lead.Id);
            lc.setConvertedStatus(convertStatus.MasterLabel);
            lc.setDoNotCreateOpportunity(TRUE);

            List<account> obj_account = [select id from account where 
                                         Email_and_SiteID__c= :lead.Email_and_SiteID__c];
            if(obj_account.size()>0)
            {
                lc.setAccountId(obj_account[0].id);
            }
                leadConverts.add(lc);
            }
            }

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

}

 
Best Answer chosen by Rajbharath
Vikash GoyalVikash Goyal
Hi Rajbharath, 

You can try with this :
 
public class LeadInsertTriggerHandler {

public static void AfterInsert(List<Lead> lstLeads){   
    
    List<String> lstEmailSiteIds = new List<String>();
    for (Lead lead: lstLeads) {
        lstEmailSiteIds.add(lead.Email_and_SiteID__c);
    }

    List<Account> lstAccounts = new List<Account>([SELECT Id, Email_and_SiteID__c FROM Account WHERE Email_and_SiteID__c IN : lstEmailSiteIds]);
    Map<String, List<Account>> accountMap = new Map<String, List<Account>>();

    for(Account acc : lstAccounts){
        if(!accountMap.containsKey(acc.Email_and_SiteID__c)){
            accountMap.put(acc.Email_and_SiteID__c, new List<Account>());
        }
        accountMap.get(acc.Email_and_SiteID__c).add(acc);
    }

    LeadStatus convertStatus = [select MasterLabel from LeadStatus where IsConverted = true limit 1];
    List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();

    for (Lead lead: lstLeads) {
        if (!lead.isConverted) {
            Database.LeadConvert lc = new Database.LeadConvert();

            lc.setLeadId(lead.Id);
            lc.setConvertedStatus(convertStatus.MasterLabel);
            lc.setDoNotCreateOpportunity(TRUE);

            List<account> obj_account = accountMap.get(lead.Email_and_SiteID__c);
            
            if(obj_account != null && obj_account.size()>0)
            {
                lc.setAccountId(obj_account[0].id);
            }
                leadConverts.add(lc);
            }
            }

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

}

 
Emily soaresEmily soares 
HI, i am practicing for Salesforce developer 1.  I came across this question and the answer offered didnt make any sense to me.

The operation manager at a construction company uses a custom object called Machinery to manage the usage and maintenance of its cranes and other machinery. The manager wants to be able to assign machinery to different construction jobs, and track the dates and cost associated with each job. More than one piece of machinery can be assigned to one construction job. What should a developer do to meet these requirements?
  1. Create a lookup field on the machinery object to the construction job object
  2. Create a junction object with Master-Detail Relationship to both the machinery object and the construction job object.
  3. Create a lookup field on the construction job object to the machinery object
  4. Create a Master-Detail lookup field on the machinery object to the construction job object

The answer provided was n.3.  I would have gone with n.2.

Would you be able to help me with this and explain the answer to this by any chance

Many thanks
 
Best Answer chosen by Emily soares
Niraj Kr SinghNiraj Kr Singh
Hi Emlly,

Answer should be n.2 only, because according to this scenario "More than one piece of machinery can be assigned to one construction job" we have to gowith M-M relationship which can be possible through junction object approah only.
Mujahid Islam KhanMujahid Islam Khan 
I had my actual Gmail on Webassessor.com. I am doing Trailhead using Myname@companyname.com(not Actual email just a login name). But I verified Myname@companyname.com account using actual Gmail id(Which  I use on Webassessor).  So, I have question

1. Whatever I will complete on  Myname@companyname.com trailhead then It must show on my webassessor account then What I have to do.
2. Before using Myname@companyname account, I had done many badges using an old Email address which is not exist so can I merge that account on here.
Best Answer chosen by Mujahid Islam Khan
Santosh Reddy MaddhuriSantosh Reddy Maddhuri
Hi MIK,

Your question & anwers
1. You have to wait for an email from Trailhead team to link your trailhead account to  webassessor account. That email contains all the necesary steps and you dont have to have same email ids for Trailhead and Webassessor.

2. Refer this link about merging trailhead accounts  https://force.desk.com/customer/portal/articles/2418878-merging-trailhead-accounts?b_id=13478.

Mark this as answer if it helps you, so others can benefit from it.
srinivas vanaparthisrinivas vanaparthi 
String jsonText = '{"Data": [{"attributes": {"type": "Contact","url":"/services/data/v35.0/sobjects/Contact/0036100000JUXKkAAP"},"Email":"positi@gmail.com","Description": "","Phone":"9999999","LastName": "sasumi"},{"attributes": {"type": "Contact","url":"/services/data/v35.0/sobjects/Contact/0036100000JUXKkAAP"},"Email":"edge@gmail.com","Description": "","Phone":"88888","LastName": "pavanTL"}]}';

Map<String, Object> deserialized = (Map<String, Object>)JSON.deserializeUntyped(jsonText);
List<Map<String, Object>> data = new List<Map<String, Object>>();
for (Object instance : (List<Object>)deserialized.get('Data')){
    data.add((Map<String, Object>)instance); 
}

String dataSerialize=JSON.serialize(data);
System.debug('dataSerialize...'+dataSerialize);
try
{
   SObject customObject = (SObject)JSON.deserialize(dataSerialize, Sobject.class);
    Database.upsert(customObject);
    System.debug(' customObject...: '+customObject);
}
catch(Exception ex)
{
    System.debug(' @@@@@ Don\'t visible '+ex.getMessage());
}

 
Best Answer chosen by srinivas vanaparthi
Sampath SuranjiSampath Suranji
Hi,
Try below code.
String jsonText = '{"Data": [{"attributes": {"type": "Contact","url":"/services/data/v35.0/sobjects/Contact/0036100000JUXKkAAP"},"Email":"positi@gmail.com","Description": "","Phone":"9999999","LastName": "sasumi"},{"attributes": {"type": "Contact","url":"/services/data/v35.0/sobjects/Contact/0036100000JUXKkAAP"},"Email":"edge@gmail.com","Description": "","Phone":"88888","LastName": "pavanTL"}]}';

Map<String, Object> deserialized = (Map<String, Object>)JSON.deserializeUntyped(jsonText);
List<string > finalJsonString = new List<string>();
List<Map<String, Object>> data = new List<Map<String, Object>>();
for (Object instance : (List<Object>)deserialized.get('Data')){
    finalJsonString.add(JSON.serialize(instance)); 
}

try
{
    for(string s: finalJsonString){
        SObject customObject = (SObject)JSON.deserialize(s, Sobject.class);
        System.debug('customObject '+ customObject);
        Database.upsert(customObject);
        System.debug(' customObject...: '+customObject);
    }
    
}
catch(Exception ex)
{
    System.debug(' @@@@@ Don\'t visible '+ex.getMessage());
}

regards
Beatriz MinguezBeatriz Minguez 
Dear all, 
I am trying to solve one of the Trailhead Challenges in the unit: Creating Test Data for Apex Tests and is giving me the following error:

Challenge Not yet complete... here's what's wrong: 
Executing the 'generateRandomContacts' method failed. Either the method does not exist, is not static, or did not return the correct set of Contact records.

The following is the code; 
public class RandomContactFactory {

    public static List<Contact> generateRandomContacts (integer nNumContacts, string sLastName)
    {
        List<Contact> lContactList = new List<Contact>();
        
        for(integer i=0; i<nNumcontacts; i++)
        {
            Contact c = new Contact(LastName= sLastName + ' ' +i);
            lContactList.add(c);

        }    
        return lContactList;
    }
    
}

What I need to solve is the following:

 Create an Apex class that returns a list of contacts based on two incoming parameters: one for the number of contacts to generate, and the other for the last name. The list should NOT be inserted into the system, only returned. The first name should be dynamically generated and should be unique for each contact record in the list.The Apex class must be called 'RandomContactFactory' and be in the public scope.
The Apex class should NOT use the @isTest annotation.
The Apex class must have a public static method called 'generateRandomContacts' (without the @testMethod annotation).
The 'generateRandomContacts' method must accept an integer as the first parameter, and a string as the second. The first parameter controls the number of contacts being generated, the second is the last name of the contacts generated.
The 'generateRandomContacts' method should have a return type of List<Contact>.
The 'generateRandomContacts' method must be capable of consistently generating contacts with unique first names.
For example, the 'generateRandomContacts' might return first names based on iterated number (i.e. 'Test 1','Test 2').
The 'generateRandomContacts' method should not insert the contact records into the database.

Can anyone help me? 

Thanks!

Bea

 
Best Answer chosen by Beatriz Minguez
Clint Majors (Personal)Clint Majors (Personal)
It looks like you are missing the unique First Name when you create your Contacts. You are generating unique Last Names, but are not setting a value for First Name. Maybe something like this would work?

Contact c = new Contact(LastName= sLastName, FirstName = 'Test ' +i);
Synthia BeauvaisSynthia Beauvais 
I am trying to create a data quality score on the Contact object for the fields listed in the chart below. I am not quite sure how to calculate the weight. I have started the formula but I am not getting the correct "Actual Value".
 
IF( 
OR( 
ISBLANK(Phone), 
OR( 
CONTAINS(Phone, '000-0000') , 
CONTAINS(Phone, '111-1111') , 
CONTAINS(Phone, '222-2222') , 
CONTAINS(Phone, '333-3333') , 
CONTAINS(Phone, '444-4444') , 
CONTAINS(Phone, '555-5555') , 
CONTAINS(Phone, '666-6666') , 
CONTAINS(Phone, '777-7777') , 
CONTAINS(Phone, '888-8888') , 
CONTAINS(Phone, '123-4567') , 
CONTAINS(Phone, '456-7890')
) 
), 0, 1 
) 

+ 
IF( ISBLANK( MailingStreet ), 0, 1)+ 
IF( ISBLANK( MailingCity ), 0, 1)+ 
IF( ISBLANK( MailingState ), 0, 1)+ 
IF( ISBLANK( MailingCountry ), 0, 1)+ 
IF( ISBLANK( MailingPostalCode ), 0, 1) +
IF( ISBLANK(FirstName ) ,0,1) + 
IF( ISBLANK( LastName ) , 0, 1)+ 
IF( ISBLANK( Email ) , 0, 1)
/9



User-added image

MAX SCORE: 5
MIN SCORE: 0


Thanks in advance! 


 
Best Answer chosen by Synthia Beauvais
Rajan Patel 8Rajan Patel 8
Try something like this.

((IF( 
OR( 
ISBLANK(Phone), 
OR( 
CONTAINS(Phone, '000-0000') , 
CONTAINS(Phone, '111-1111') , 
CONTAINS(Phone, '222-2222') , 
CONTAINS(Phone, '333-3333') , 
CONTAINS(Phone, '444-4444') , 
CONTAINS(Phone, '555-5555') , 
CONTAINS(Phone, '666-6666') , 
CONTAINS(Phone, '777-7777') , 
CONTAINS(Phone, '888-8888') , 
CONTAINS(Phone, '123-4567') , 
CONTAINS(Phone, '456-7890')

), 0, 1 

* (20))

(IF( ISBLANK( MailingStreet ), 0, 1) * (3.333))+ 
(IF( ISBLANK( MailingCity ), 0, 1)* (3.333)) + 
(IF( ISBLANK( MailingState ), 0, 1)*(5))+ 
(IF( ISBLANK( MailingCountry ), 0, 1)*(5))+ 
(IF( ISBLANK( MailingPostalCode ), 0, 1)*(3.333)) +
(IF( ISBLANK(FirstName ) ,0,1) *(10))+ 
(IF( ISBLANK( LastName ) , 0, 1) *(25))+ 
(IF( ISBLANK( Email ) , 0, 1) *(25))
)/20
Aakanksha Singh 11Aakanksha Singh 11 
Hello Everyone,

I'm trying to use force:navigateToComponent, but its not working. Here is my code:
<pre>
({
    NavigatetoComp : function(component, event, helper) {
        
        console.log('Enter Here');
        var evt = $A.get("e.force:navigateToComponent");
        console.log('evt'+evt);
        evt.setParams({
            componentDef: "c:MyComponent2",
            //componentAttributes :{ }
        });
       
        evt.fire();
    }
})
</pre>

It throws following error:
User-added image

Can any body tell why is it so?

Thanks In Advance
Aakanksha Singh
Best Answer chosen by Aakanksha Singh 11
{!Piyush_soni__c}{!Piyush_soni__c}
hi Aakanksha Singh 
maybe you are try it with lightning app.app, its support only with salesforce1 or Lightning Experience.
so add your component to the salesforce1 or Lightning Experience.tab
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_add_cmp_lex.htm
and then try this again
thanks let me inform if it helps you 
http://sfdcmonkey.com
DJ 367DJ 367 
Hello All,

I have made two lightning component my example is when I select Account Rating it should display related Account record, I am not sure where I am doing mistake , can someone please help me.
My code is below:
// class
public with sharing class AccountRating {
	
    @AuraEnabled
    public static List<Account> AccMethod(RatParam){
        return [select Id,name,site,Rating from Account where Rating = : RatParam];        
    }
}
Lightning Component:
<aura:component >
    
    <aura:attribute name ="Acc" type="Account" />
    
    <div class="demo-only" style="width: 30rem;">
      <article class="slds-tile">
        <h3 class="slds-tile__title slds-truncate" title="Account Name"><a href="javascript:void(0);">{!v.Acc.Name}</a></h3>
        <div class="slds-tile__detail">
          <dl class="slds-list_horizontal slds-wrap">
            <dt class="slds-item_label slds-text-color_weak slds-truncate" title="First Label">Rating:</dt>
            <dd class="slds-item_detail slds-truncate" title="Description for first label">{!v.Acc.Rating}</dd>
            <dt class="slds-item_label slds-text-color_weak slds-truncate" title="Second Label">Site:</dt>
            <dd class="slds-item_detail slds-truncate" title="Description for second label">{!v.Acc.Site}</dd>
          </dl>
        </div>
      </article>
    </div>
</aura:component>

Component: 2
 
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:attribute Name = "Rating" type = "List" />
    
    <div class="slds-form-element">
      <label class="slds-form-element__label" for="select-01">Select Label</label>
      <div class="slds-form-element__control">
        <div class="slds-select_container">
          <select class="slds-select" id="select-01">
            <option value="selVal">Please select</option>
            <option>Hot</option>
            <option>Warm</option>
            <option>Cold</option>
          </select>
        </div>
      </div>
    </div>
    
    <aura:iteration items = "{!Rating}" var = "Rat" >
        <c:AccountRatingTile Acc = "{!Rat}" />
    </aura:iteration>
    
</aura:component>
Clientside Controller:
 
({
	AccRating : function(AccCom, event, helper) {
		var selValVal = AccCom.find("v.selVal");
        console.log(selValVal);
        var RatParam = selValVal.get("v.value");
        
        var searchAction =AccCom.get("c.AccMethod");
         searchAction.setParam("RatParam",RatParam);
        searchAction.setCallback(this,function(resp){
            AccCom.set("v.Acc",resp.getReturnValue());
            
        });
        $A.enqueueAction(searchAction);
	}
})

App:
<aura:application extends = "force:slds">
    <c:AccountRating />
</aura:application>


​Thanks.
 
Best Answer chosen by DJ 367
Sampath SuranjiSampath Suranji
Hi,
Try like below,
AccountRating cmp,
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" controller="AccountRating" >
    <aura:attribute Name = "Ratings" type = "List" />
    <aura:attribute name="selectedVal" type="string"/>
    
    
    <div class="slds-form-element">
        <label class="slds-form-element__label" for="select-01">Select Label</label>
        <div class="slds-form-element__control">
            <div class="slds-select_container">
                <ui:inputselect aura:id="input_select" class="slds-select" change="{!c.AccRating}" value="{!v.selectedVal}">
                    <ui:inputselectoption text="--select--" label="" />
                    <ui:inputselectoption text="Hot" label="" />
                    <ui:inputselectoption text="Warm" label="" />
                    <ui:inputselectoption text="Cold" label="" />
                    
                </ui:inputselect>
                
            </div>
        </div>
    </div>
    
    <div id="divAccDetails">
        <aura:iteration items = "{!v.Ratings}" var ="Rat" >
            <c:AccountRatingTile Acc="{!Rat}" />
        </aura:iteration>
    </div>
    
    
</aura:component>
controller
({
    AccRating : function(component, event, helper)  {
        var selValVal = component.get("v.selectedVal");
        
        var searchAction =component.get("c.AccMethod");
        searchAction.setParam("RatParam",selValVal);
        searchAction.setCallback(this,function(resp){
            var s = resp.getState(); 
            if(s == "SUCCESS"){
                component.set("v.Ratings",resp.getReturnValue());
                
            }
            
            
        });
        $A.enqueueAction(searchAction);
    }
})
AccountRatingTile
<aura:component access="global">
    
    <aura:attribute name ="Acc" type="Account" />
    
    
    <div class="demo-only" style="width: 30rem;">
      <article class="slds-tile">
        <h3 class="slds-tile__title slds-truncate" title="Account Name"><a href="javascript:void(0);">{!v.Acc.Name}</a></h3>
        <div class="slds-tile__detail">
          <dl class="slds-list_horizontal slds-wrap">
            <dt class="slds-item_label slds-text-color_weak slds-truncate" title="First Label">Rating:</dt>
            <dd class="slds-item_detail slds-truncate" title="Description for first label">{!v.Acc.Rating}</dd>
            <dt class="slds-item_label slds-text-color_weak slds-truncate" title="Second Label">Site:</dt>
            <dd class="slds-item_detail slds-truncate" title="Description for second label">{!v.Acc.Site}</dd>
          </dl>
        </div>
      </article>
    </div>
</aura:component>

regards


 
Sean ClarkSean Clark 
I have created a Apex Trigger to create a task on the MVP object when the Last Contacted On date is 30 days old.

Is there anyway i can make it so that the task will only be created on a weekday? (Monday - Friday)



trigger OldMVPTrigger on MVP__c (after insert) {
    
    List<Task> taskListToInsert = new List<task>();
    
    for(MVP__c mvp:Trigger.new)
    {
        if(mvp.Last_Contacted_On__c == Date.Today().addDays(-30)) 
        {
           task t = new Task();
           t.Subject = 'Call [MVP__c].MVP__c.FirstName Today';
           t.OwnerId = '[MVP__c].MVP_Owner__c';
           t.WhatId = mvp.Id;
           taskListToInsert.add(t);
        }
    }
    if(taskListToInsert.size() > 0)
    {
        insert taskListToInsert;
    }
}
Best Answer chosen by Sean Clark
Nishant Prajapati 10Nishant Prajapati 10
Hi Sean 
Please try following code.
trigger OldMVPTrigger on MVP__c (after insert) {
    
    List<Task> taskListToInsert = new List<task>();
    
    for(MVP__c mvp:Trigger.new)
    {
        if(mvp.Last_Contacted_On__c == Date.Today().addDays(-30) && system.today() <=    system.today().toStartOfWeek().addDays(5) ) 
        {
           task t = new Task();
           t.Subject = 'Call [MVP__c].MVP__c.FirstName Today';
           t.OwnerId = '[MVP__c].MVP_Owner__c';
           t.WhatId = mvp.Id;
           taskListToInsert.add(t);
        }
    }
    if(taskListToInsert.size() > 0)
    {
        insert taskListToInsert;
    }
}
Wei Keong KhooWei Keong Khoo 
Hi everyone,

I am developing a Custom Lightning Component and it suppose to be a dynamic component.

But I do not seems to be able to create additional filter to be used on Lightning App Builder setup page.

I wanted to do something like standard Lightning Components:
User-added image

Anyone have any experience in creating filter for Custom Lightning Component?
Best Answer chosen by Wei Keong Khoo
Nishant Prajapati 10Nishant Prajapati 10
Hi Wei
Use a design resource to control which attributes are exposed to  the Lightning App Builder.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_config_for_app_builder_design_files.htm