+ Start a Discussion
Lavanya Ponniah 3Lavanya Ponniah 3 

How to update for the below situation?

I have  objects Application_Members__c and Contact.If the contact Name = App.SurName + App.FirstName,in the contact con.FirstName=App.FirstName and con.LastName=App.SurName.
How to update using developer console by code. I tried below code but i get error.

List<Contact> c = new List<Contact>();
List<contact> con = [select Name, FirstName, LastName, RecordType.name from Contact];
List<Application_Members__c> ap = [select First_name__c, Surname__c,RecordType.name from  Application_Members__c];     
    
    if(ap.size() > 0)
    {
        if(con.size() > 0)
        {
            for(Contact c2:con)
            {
                    if(c2.Name == (ap.Surname__c + ' ' +  ap.First_name__c))
                    {
                        c2.FirstName = ap.First_name__c;
                        c2.LastName = ap.Surname__c;
                        c.add(c2);
                        update c;
                    }
                }
            }
        }
    }
Vishnu VaishnavVishnu Vaishnav
Hi Lavanya,

 I don't understand your requirment, Bcoz 
1. your giving condtion is that
    if(c2.Name == (ap.Surname__c + ' ' +  ap.First_name__c))
Exa : if c2.name ='Ponniah Lavanya'
          then as your condition , it come in condtion if (ap.Surname__c + ' ' +  ap.First_name__c)
          like : if ( 'Ponniah' + ' ' +  'Lavanya')


2. After this u r update the contact by same thing :
                        c2.FirstName = ap.First_name__c;
                        c2.LastName = ap.Surname__c;
Like :
                       c2.FirstName = 'Lavanya';
                        c2.LastName = 'Ponniah';

Got it..
Your code doesn't make sense. Am i right ?

:::======================================================================:::
Qusetion Solved ? then mark as best answer to make helpful to others .....