• JaimeBid
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 17
    Replies
Hi everyone!
I am a developer beginner. I have created the following class to convert all contacts into person accounts. To avoid interfere with our current implementations it will be a scheduled class.

This is one of the first classes I write, so I am still a bit lost. 
The error is "Variable does not exist" in both lines 30 and 37

My question is about the approach, being schedule class, shall I create different methods to keep on returning the values (to be reused) or shall I create a map to store everything and reuse it?
Any other approach you may consider?

Thanks a lot for your ideas... 
 
global class ConvertContactToPersonAccount Implements Schedulable{    
    public static final Id bizAccRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Cuenta_empresa').getRecordTypeId();
    public static final Id personAccRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('PersonAccount').getRecordTypeId();
    
    global void execute(SchedulableContext sc){
        ConvertContactToPersonAccount();
    }
    public void ConvertContactToPersonAccount() {
        // Query of all contacts not related to business or person account
        List <Contact> contactsToConvert = [SELECT Id, FirstName, Lastname, Birthdate, OwnerID, Email 
                                            FROM contact 
                                            WHERE IsPersonAccount = false 
                                            AND Account.Name = null];
        if (contactsToConvert.size() > 0){
            // Loop the list and generate the BIZ accounts
            List <Account> NewAccBiz = new List <Account>();
            for (Contact con : contactsToConvert){
                Account acc = new Account ();
                Acc.OwnerID = con.OwnerID;
                acc.Name = con.Firstname + ' ' + con.LastName;
                acc.RecordTypeId = bizAccRecordTypeId;
                acc.Fecha_de_nacimiento__c = con.Birthdate;
                NewAccBiz.add(acc);
            }
            Database.insert (NewAccBiz, false);    
            
            // Update the contacts with the data from the new BIZ acc cretaed
            List <Contact> associateCon = new List <Contact>();
            for (Contact con : contactsToConvert){            
                con.AccountId = acc.Id;
                associateCon.add(con);
            }
            Database.update (associateCon, false);  
            
            // Modify BIZ acc into Person Accounts
            List <Account> accBizToPaList = new List <Account>();                        
            List <Account> acctoUpdate = [SELECT Id FROM account WHERE ID = :acc.Id];
            for (Account accBizToPa : acctoUpdate){
                accBizToPa.RecordTypeId = personAccRecordTypeId;
                accBizToPaList.add(accBizToPa);
            }
            Database.update (accBizToPaList, false);             
        }
    }
}




 

Hi all!
My first question, apologies in advance if answer is clear, but I am beginning with APEX, and I am a bit stuck here.


What does "System.Assert(false);" is doing exactly here?

try{
    ContactsDML.databaseMethodDML();
    System.Assert(false);
} catch(DMLException e){
    System.assert(e.getMessage().contains('Required fields are missing: [LastName]: [LastName]'));
}
I am within a class method, calling another class for the test, which results in an error (as stated in the message).

My question is because I do not see any changes, whether I use true or false on that parameter:  System.Assert(false);

Thanks in advance!
 
So i'm about 50% into my Learning Salesforce Development with Apex: Write, Run and Deploy Apex Code with Ease (English Edition) book and I'm stuck on the below code. I provide a text version under the image. The below code has no problems. When I create a new task nothing happens though and if I create a task with a Contact it has an issue that says: TaskTrigger: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.TaskTrigger: line 14, column 1

User-added imageText version of the code from Learning Salesforce Development with Apex: Write, Run and Deploy Apex Code with Ease (English Edition):

trigger TaskTrigger on Task (after insert, after update) {
    switch on Trigger.operationType {
        when AFTER_INSERT {
        Set<Id> contactIds = new Set<Id>();
    For(Task t: Trigger.new) {
    If(t.WhoId != null && String.valueOf(t.WhoId).startsWith('003')) {
    contactIds.add(t.WhoId);
    }
    }
    Map<Id, Contact> contactMap = new Map<Id, Contact> ([SELECT Id, No_Of_Open_Tasks__c FROM Contact WHERE Id in: contactIds]);

    For(Task t :Trigger.new) {
    If(contactMap.containsKey(t.WhoId)) {
    contactMap.get(t.WhoId).No_of_Open_Tasks__c += 1;
    }
    }
    Update contactMap.values();
    }
        when AFTER_UPDATE {            
        Set<ID> contactIds = new Set<Id>();
    For(Task t : Trigger.new) {
    If(t.IsClosed && !Trigger.oldMap.get(t.Id).IsClosed && t.WhoId != null && String.valueOf(t.WhoId).startsWith('003')) {
    contactIds.add(t.WhoId);
    }
    }
    Map<Id, Contact> contactMap = new Map<Id, Contact>([SELECT Id, No_Of_Open_Tasks__c FROM Contact WHERE Id in :contactIds]);

    For(Contact con : contactMap.values()) {
    Con.No_of_open_tasks__c = 0;
    }

    For(AggregateResult ar : [SELECT WhoId, Count(Id) total FROM Task WHERE IsClosed = false AND WhoId in :contactIds GROUP BY WhoID]) {
    String who = String.Valueof(ar.get('WhoId'));
    Decimal total = (Decimal)(ar.get('total'));
    contactMap.get(who).No_of_Open_Tasks__c = total;
    }
    update contactMap.values();
        }
        }
}

Hi all!
My first question, apologies in advance if answer is clear, but I am beginning with APEX, and I am a bit stuck here.


What does "System.Assert(false);" is doing exactly here?

try{
    ContactsDML.databaseMethodDML();
    System.Assert(false);
} catch(DMLException e){
    System.assert(e.getMessage().contains('Required fields are missing: [LastName]: [LastName]'));
}
I am within a class method, calling another class for the test, which results in an error (as stated in the message).

My question is because I do not see any changes, whether I use true or false on that parameter:  System.Assert(false);

Thanks in advance!
 
I have a Process Builder process to send a renewal email if certain fields contain specific field values and the renewal date equals today minus 30 days (I have a formula field that calculates that). My problem is this. The process will only trigger when the records are updated. What I need to happen then is for the record to auto-update to trigger the process builder process. I have a picklist field that is part of the Process Builder process. That picklist field values are True/False. So as part of the Process field values used in the Process if that field is False, the email sends. This works fine and the email sends. But as mentioned this will only happen if I update the record manually, but this isn't what I need. I need the record to update automatically so the process will send the email automatically. Is there a way to update the record automatically to trigger the process? 
Hello, I am encountering the following message Challenge Not yet complete... here's what's wrong:
The 'My Shifts Pending Approval' report does not have the correct columns. Of the two 'Volunteer Shift Worker ID' fields, include the one with the format Shift-#### so users can click through to the volunteer record.


Can anyone help me with this?

User-added image
User-added image
I'm working through the Trailhead module on Account and Contact relationships (Learn CRM Essentials for Salesforce Classic > Accounts & Contacts > Understand Account and Contact Relationships https://trailhead.salesforce.com/trails/getting_started_crm_basics/modules/admin_intro_accounts_contacts/units/admin_intro_accounts_contacts_relationships)

It walks you through adding Related Contacts to the Account page, and then creating a related Contact through it. 
User-added image

I run into an error when I create a new Contact off of that screen: "Error: You can't associate a private contact with an account.".
User-added image

So, the steps are:
1: Account page
2: Click [Add Relationship] button in Related Contacts section
3: On the 'New Account Contact Relationship' click the Contact search icon
4: Click the [New] button
5: Enter the Contact info and click [Save]. The pop-up closes. (note: there is NOT an 'Account' field on this page.
6: Click [Save] button on the 'New Account Contact Relationship' page. The error is displayed. 

The only thing I've been able to do is exit these screens, go find the newly created Contact, edit it and add an Account, then go back and add the relationship.

How do I prevent this situation?

Thank you!



 
Hello,

One of the lines in this code is using a kind of syntax that I do not know. See line 13:  Account acct = accts[j]
On the left of the = it is declaring the object acct of the Class Account, that is clear.
On the right of the = I do not know what it is doing, I have not used this syntax before. The object accts is a List that is declared on line 04 and [j] here is limiting the frecuency of iterations in the loop on line 14. But, I do not understand (yet) what this (= accts[j]) is doing .
@isTest
public class TestDataFactory {
    public static List<Account> createAccountsWithOpps(Integer numAccts, Integer numOppsPerAcct) {
        List<Account> accts = new List<Account>();
        
        for(Integer i=0;i<numAccts;i++) {
            Account a = new Account(Name='TestAccount' + i);
            accts.add(a);
        }
        insert accts;
        
        List<Opportunity> opps = new List<Opportunity>();
        for (Integer j=0;j<numAccts;j++) {
            Account acct = accts[j];
            // For each account just inserted, add opportunities
            for (Integer k=0;k<numOppsPerAcct;k++) {
                opps.add(new Opportunity(Name=acct.Name + ' Opportunity ' + k,
                                         StageName='Prospecting',
                                         CloseDate=System.today().addMonths(1),
                                         AccountId=acct.Id));
            }
        }
        // Insert all opportunities for all accounts.
        insert opps;
        
        return accts;
    }
}
Could you possibly explain what is = accts[j] actually doing?

Thank you very much.

 
  • November 29, 2017
  • Like
  • 0
I tried deleting a record from the object by following below steps.

Queried in Dev console using Record Id , then using delete row.
Like this is there any way to delete the specific field value from the DEV console.

Please share your views.

Thank you
Paluri
how can I assign set & list values to map? and map values to set and list?
One of the challenges was to return names from leads and contacts. 
Code looks like this:
public class ContactAndLeadSearch {
    public static List<List<SObject>> searchContactsAndLeads(String FindName)
    {
        list<list<sObject>> ReturnName = [find :FindName IN ALL FIELDS Returning lead(FirstName, LastName), contact(firstname, lastname)];
        
        return ReturnName;
    }
}
When looking at the return ReturnName, how can you determine from what object the First/Last Name was retrieved? Lead?Contact?
Other examples used the  [0] and [1] in their examples when they were traversing multiple object but they only had one "find" in each object. 
Just curious as I do  understand the [x][y] notation in list<list> concepts.
Hi guys, I'm trying to create a new field that take the information from another field and removes certain words. The SUBSTITUTION funtion works fine for one word, however there's a few different values that I want to remove.

This formula works fine for one value:
SUBSTITUTE(Site_Name__c, "Site ", "")

The Site Name field has been set up by multiple people and has become rather messy, so the same information has been entered in multiple ways. As such I need to be able to remove entries similar to the following:

"Site "
"SITE "
"Site Name "

I've tried mutiple variations of the SUBSTITUTE function (see below for examples) but cannot get the formula to look for multiple values and replace them with the same thing. Does anyone have any idea what I might be able to use to get the desired result?

Formulas I've tried and failed with:
OR
(SUBSTITUTE(Site_Name__c, "Site ", ""),
SUBSTITUTE(Site_Name__c, "SITE ", ""),
SUBSTITUTE(Site_Name__c, "Site Name", ""))))

SUBSTITUTE(Site_Name__c, "Site ", "")&SUBSTITUTE(Site_Name__c, "Site ", "")&SUBSTITUTE(Site_Name__c, "Site Name ", "")

SUBSTITUTE(Site_Name__c, "Site ", ""),(Site_Name__c, "SITE ", ""),(Site_Name__c, "Site Name ", "")






 

55) Object X has a lookup to Object Y. What among the following statements are TRUE Please choose two (2). Please choose two (2).

  • a) Fields of both X and Y are accessible from Object Y.
  • b) Fields of Object Y can be accessed from Object X.
  • c) Fields of both Y and X are accessible from Object X.
  • d) Fields of Object X can be accessed from Object Y.

Ans: b,c

 

Any body explain this scenario

Hi guys,

 

my problem is there are two strings with some value i need to remove the zeros before the number and add both the strings .

 

Ex:-

String S=000578;

String j=080554321;

String k=s+j    ( not addition);

k                                 =  s    +     j;

57880554321        =   578+ 80554321;

 

it means it shoul remove all the zeros before the number.

Some times s=0578;

                        j=00080554321;

 

then also the out put should be same as above "k"

 

 

 

Thanks

frank

 

 

Hello. I want to know how can i create a Map<String, CustomObject> where the key will not be the Id of the custom field but the Name field and without using a list and going through each record and puting in the map a pair.

If I use Map<String, CustomObject__c> myMap = new Map<String, CustomObject__c>([Select z.Name, z.Id From CustomObject__c z]); i have a map where the key is my CustomObject.Id and I want it to be CustomObject.Name.