function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sandeep Reddy 288Sandeep Reddy 288 

Write an apex program, to Transfer all the Independent Contacts, to the Account "Edge Communications."

Best Answer chosen by Sandeep Reddy 288
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Sandeep,

The apex class can be as below.
 
public class IndependantContact {

    public static void relateAccount(){
        List<Contact> tobeupdated= new List<Contact>();
        List<Contact> contactlist=[select id,name, accountid from contact where accountid=null ];
        
       List<Account> acc=[select id, name from Account where Name='Edge Communications'];
        
        for(Contact con :contactlist){
            
            con.accountid=acc[0].id;
            tobeupdated.add(con);
        }
        if(tobeupdated.size()>0)
            update tobeupdated;
    }
}

from anonomous window call this method as below.
 
IndependantContact.relateAccount();

This should relate the independent  contacts with "Edge Communications" Account.

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Sandeep,

The apex class can be as below.
 
public class IndependantContact {

    public static void relateAccount(){
        List<Contact> tobeupdated= new List<Contact>();
        List<Contact> contactlist=[select id,name, accountid from contact where accountid=null ];
        
       List<Account> acc=[select id, name from Account where Name='Edge Communications'];
        
        for(Contact con :contactlist){
            
            con.accountid=acc[0].id;
            tobeupdated.add(con);
        }
        if(tobeupdated.size()>0)
            update tobeupdated;
    }
}

from anonomous window call this method as below.
 
IndependantContact.relateAccount();

This should relate the independent  contacts with "Edge Communications" Account.

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
This was selected as the best answer
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

Did you try the above code using apex class or do you need the code in anonomous block only?

Thanks,
 
Sandeep Reddy 288Sandeep Reddy 288
No, It did not worked Thanks
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Sandeep,

Are you getting any errors in the code or while executing.

Thanks,
 
Sandeep Reddy 288Sandeep Reddy 288
Thanks
It worked sai praveen
Betty mills 10Betty mills 10
One of the biggest issues with students is that they seek for urgent and custom essay writing services to complete their assignments. They enquire and look for "can someone do my essay for me" online. No longer, as we are available to answer all of your urgent do my essay requests. Get the most out of your money when you pay us to (https://royalbritishessaywriters.co.uk/write-my-essay-uk)essay help online (https://royalbritishessaywriters.co.uk/write-my-essay-uk) (https://royalbritishessaywriters.co.uk/write-my-essay-uk)because we have the top British essay writers who can provide an unique essay for a reasonable fee. Consequently, we provide a cost-effective alternative without charging exorbitant prices for custom essays. As we all know, excellent essay writing assistance combines originality and high-caliber writing. By quality, we imply the subsequent.