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
priya.ax1493priya.ax1493 

apex

the following Apex code shows how an account and a contact can be associated with one another, and then how the contact can be used to modify a field on the account: Account a = new Account(Name = 'Acme'); insert a; // Inserting the record automatically assigns a // value to its ID field Contact c = new Contact(LastName = 'Weissman'); c.AccountId = a.Id; // The new contact now points at the new account insert c; // A SOQL query accesses data for the inserted contact, // including a populated c.account field c = [SELECT Account.Name FROM Contact WHERE Id = :c.Id]; // Now fields in both records can be changed through the contact c.Account.Name = 'salesforce.com'; c.LastName = 'Roth'; // To update the database, the two types of records must be // updated separately update c; // This only changes the contact's last name update c.Account; // This updates the account name The question is how to implement this code.i am trying to implement this in trigger class but iam not able to do so.tell me where to write this code and how to execute.
Best Answer chosen by Admin (Salesforce Developers) 
Vishal KashyapVishal Kashyap

You can try writing the whole logic in an apex class function and call the apex class function which implements the whole logic from trigger.

All Answers

SeAlVaSeAlVa

Execute Anonymous or

'Developer Console' (under 'Your Name' -> 'Developer Console')

Chris42Chris42

You can also do the same thing from inside Eclipse as long as you've installed the Force.com Plugin and have created a Force.com project. You get basically the same information by running it both ways though.

Vishal KashyapVishal Kashyap

You can try writing the whole logic in an apex class function and call the apex class function which implements the whole logic from trigger.

This was selected as the best answer
priya.ax1493priya.ax1493
thanks dude
priya.ax1493priya.ax1493
hey thanks
priya.ax1493priya.ax1493
thanks