• SF API 9
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
I used the below apex class as an invokable method to work with process builder. The code will fire when a certain field on the Lead record is populated. 

The class works perfectly:
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>();
        for(id currentlead: LeadIds){
                Database.LeadConvert Leadconvert = new Database.LeadConvert();
                Leadconvert.setLeadId(currentlead);                
                Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
                Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion 
                MassLeadconvert.add(Leadconvert);
        }
        
        if (!MassLeadconvert.isEmpty()) {
            List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
        }
    }
}

The test class below (that i found online) is not giving me the coverage that I need.  Can someone help me??


@IsTest (SeeAllData=true) private class AutoConvertLead_Test{

    /* This is a basic test which simulates the primary positive case for the 
       Conversion method of a Lead. */

public static testMethod void myUnitTest() {

// create a Lead
Lead lead=new Lead(LastName='TestDoe',FirstName='TestJane',Company='TestUnknown',Status='Warm Prospect',Addy_Account_id__c='1234566');

insert lead;


Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(lead.id);
lc.setDoNotCreateOpportunity(true);
lc.setConvertedStatus('User');

Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
}}

 
What is the best way for me to update mass update all contacts/accounts/etc. that match some form of shared criteria? For example, changing the industry type of all Contacts that live in New York, or something like that.

Right now the marketing workflow I'm working on is:

1. Pull 200 individual contacts from SF
2. Use each contact's ZIP and industry to create a specific marketing offer URL via 3rd party API
3. Create an array of contact objects using the SF ID and new marketing offer field data
4. Batch update() the contacts back into SF

It works great, but I'm realizing that there's a lot of overlap of API calls for me processing multiple contacts with the same ZIP and industry. Is there any way for me to refactor this pipeline to look more like this?

1. Query SF for all possible combinations of ZIP and industry
2. Find new corresponding marketing offer URL via 3rd party
3. Update all Contacts' offer URL to be that value, for all contacts that have matching ZIP and industry

If it were feasible to do this in SOQL, it'd basically look something like this:
UPDATE Contact
SET OfferUrl = "http://offerurl.com/123"
WHERE Contact.ZIP = '11215' AND Contact.Industry = 'Aerospace';
but I know that won't work. Is there some equivalent functionality to mass update without a SOQL query?

 
What is the best way for me to update mass update all contacts/accounts/etc. that match some form of shared criteria? For example, changing the industry type of all Contacts that live in New York, or something like that.

Right now the marketing workflow I'm working on is:

1. Pull 200 individual contacts from SF
2. Use each contact's ZIP and industry to create a specific marketing offer URL via 3rd party API
3. Create an array of contact objects using the SF ID and new marketing offer field data
4. Batch update() the contacts back into SF

It works great, but I'm realizing that there's a lot of overlap of API calls for me processing multiple contacts with the same ZIP and industry. Is there any way for me to refactor this pipeline to look more like this?

1. Query SF for all possible combinations of ZIP and industry
2. Find new corresponding marketing offer URL via 3rd party
3. Update all Contacts' offer URL to be that value, for all contacts that have matching ZIP and industry

If it were feasible to do this in SOQL, it'd basically look something like this:
UPDATE Contact
SET OfferUrl = "http://offerurl.com/123"
WHERE Contact.ZIP = '11215' AND Contact.Industry = 'Aerospace';
but I know that won't work. Is there some equivalent functionality to mass update without a SOQL query?