• ForceWave
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
I'm working on a method to take a phile of ContentDocumentLinks, find those that are linked to Expense__c, and then put those Expense__c records into a list. The bold line below won't compile with the error: Method does not exist or incorrect signature: void add(Id) from the type List<Expense__c>
I know this must be a simple fix, but help, please?

    //First attempted method:
    public list<Expense__c> Transformer(List<ContentDocumentLink> incomingcdls){
        //1. instantiate a list to hold the Expenses
        list<Expense__c> returnedexpenses = new list<Expense__c>();
        
        //2. Loop through the incoming CLDs. If the LinkedEntityID is that of an expense, add it to the list.
        for(ContentDocumentLink currentcdl : incomingcdls){
            if(currentcdl.LinkedEntityId.getSObjectType() == Schema.Expense__c.getSObjectType()){
               System.debug(currentcdl + ' was linked to a ' + currentcdl.LinkedEntityId.getSObjectType() + ' so it should go in the list.');
               //Now how to add it to the list? The below doesn't work
               returnedexpenses.add(currentcdl.LinkedEntityId);

            } else {
                System.debug(currentcdl + ' was linked to a ' + currentcdl.LinkedEntityId.getSObjectType() + ' so it should NOT go in the list.');
            }

    }
            
        //3. return the list of Expenses
        return returnedexpenses;
}

I'm using skyvia to update fields on Leads in job that runs once a day. That job locates the lead to update using a custom unique field that corresponds to the lead's ID in our external database. I also have an apex trigger called AutoConvertLeads that runs after updates that converts leads if they have MRR_c > 0.

/* 
After a lead is updated or inserted, it adds the lead to a list if that lead has started paying.
Then, we call convertLead on that list, converting all qualified leads. 
*/
trigger AutoConvertLeads on Lead (after update, after insert) {

    Database.LeadConvert[] leadsToConvert = new List<Database.LeadConvert>();
	LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE Id='01J1a00000DO8hfEAD' LIMIT 1];
    
    for(Lead l: Trigger.new) { //iterate through array of leads
        if(!l.isConverted && l.MRR__c > 0) {
			Database.LeadConvert lc = new Database.LeadConvert();
            lc.setLeadId(l.Id);
            lc.setDoNotCreateOpportunity(false);
            lc.setOpportunityName(l.Company + ' - self serve');
            lc.setConvertedStatus(convertStatus.MasterLabel);
            leadsToConvert.add(lc);
        }
    }
    
    if (!leadsToConvert.isEmpty()) {
	    List<Database.LeadConvertResult> lcr = Database.convertLead(leadsToConvert);
    }
    
    // This for loop updates the opportunities that were created above with more information
    for (Database.LeadConvert l: leadsToConvert) {
        Lead lead = new Lead();
        Account acc = new Account();
        Opportunity opp = new Opportunity();
        lead = [SELECT ConvertedAccountId, LeadSource, MRR__c FROM Lead WHERE Id = :l.getLeadId()][0];
        if (lead != null) {
            acc = [SELECT Id FROM Account WHERE Id = :lead.ConvertedAccountId][0];
            if (acc != null) {
		        opp = [SELECT Id FROM Opportunity WHERE AccountId = :acc.Id and Name like '% - self serve'][0];
		        opp.CloseDate = date.today();
		        opp.LeadSource = lead.LeadSource;
		        opp.Amount = lead.MRR__c;
		        opp.StageName = 'Closed Won';
		        opp.Type = 'New Business';
                opp.Renewal_Date__c = date.today().addMonths(1);
                opp.OwnerId = '0051a000002d9h7AAA';
		        update opp;
            }
        }
    }
}


This system was working just fine, but now it seems to be broken because most Leads that skyvia tries to update end up failing with the following error:

AutoConvertLeads: execution of AfterUpdate

caused by: System.DmlException: ConvertLead failed. First exception on row 3; first error: DUPLICATE_VALUE, duplicate value found: []

()
Some of the errors say "First exception on row 0"  instead of "row 3" but I can't figure out why. One of the thing I changed around the time when this stopped working was the duplicate roles in the salesforce instance, however, the message above is not the Alert Text for any of the duplicate rules.

The above error appears for both leads that have MRR_c > 0 as well as leads that don't, which doesn't make any sense because the trigger should only be calling convertLead on leads that have MRR_c > 0. Another thing that doesn't make any sense is there aren't any duplicates. I've searched our Salesforce and can't find any objects that have the same IDs as the leads that this error occurs with.

I would really appreciate it if someone could help me with both of these unexpected behaviors.
Contacts have a lookup relationship to a custom Worker__c object.

Whenever a new Worker__c record is created, I want to create an associated (child) Contact.

My code is as follows:

trigger NewContactforWorker on Worker__c (after insert) {
	List<Contact> conList = new List<Contact>;
    for (Worker__c wkr : trigger.new) {
        a = new Contact(Worker__c = wkr.Id, FirstName = wkr.First_Name__c, 
                        LastName = wkr.Last_Name__c, QSAC_external_id__c = wkr.Worker_External_ID__c);
        conList.add(a);
    }
    insert conList;
}

But I get an error in between the second and third lines.  Can anyone help?

Thank you.
  • September 23, 2014
  • Like
  • 0

I have a custom field defined in an Activity. What I would like to do is to update this custom field when the "Send An Email" button is pressed (or after the email is sent). Essentially, this field is used to track the type of activity and I want to have this "activity type" updated when the email is sent.

 

Any ideas on how I can accomplish this?

 

Thanks in advance.