You need to sign in to do that
Don't have an account?
priya.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.
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
Execute Anonymous or
'Developer Console' (under 'Your Name' -> 'Developer Console')
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.
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.