You need to sign in to do that
Don't have an account?
Insert Account
Hey i'm trying to clone an account.
There are no errors in my code but he wont insert the copied account.
My second step is to edit some fields so it wont be exactly the same account.
Does someone know what i need to do?
My code is:
Public class InsertClass{
Public string InsertAccount{
Get{
Database.DMLOptions dmo = new database.DMLOptions();
dmo.AssignmentRuleHeader.UseDefaultRule= true;
///list<Account> WillBeClonedAccount = new list<Account>();
Account IsClonedAccount = [SELECT Account.Name, Account.Billing_Term__c FROM Account WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
Account CopiedAccount = new Account();
CopiedAccount.Name = IsClonedAccount.Name;
CopiedAccount.Phone = '020384732';
CopiedAccount.Billing_Term__c = IsClonedAccount.Billing_Term__c;
///WillBeClonedAccount.add(CopiedAccount);
CopiedAccount.SetOptions(dmo);
insert(CopiedAccount);
/// insert(WIllbeClonedAccount);
return CopiedAccount.name ;
}
}
}
Nothing happens.
No errors and No records are created.
Someone who could help me? (Bump)
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_sobject.htm
Please check if all the following conditions are met:
1) InsertClass is the controller for a visualforce page
2) InsertAccount is a accessed in the page (for getter to fire)
3)If id of the account to be cloned is passedin the URL while accessing the page.
If all the above is checked, then check the debug logs which is created when the page is accessed. Check if any issue in the log.
- Anand
Hey Anand,
Al conditions are met!
Could you explain me where i can find the debug logs?
Go to Administration Setup - > Monitoring -> Debug logs. Add yourself in the mointored users list, then access the visualforce page. A log will be created in your name.
- Anand
in salesforce
Setup menu -> search : debug log (It's under monitoring)
Add the user you're running the code, you can do this by clicking the new button on the monitored users section. This will provide 20 logs, if you want more, reset the user monitoring (you'll see this once you've added one).
Thnx!
This is what i get! But i cant find any error:
That is because there is no error. Congrats !! :) Your code works fine and the record is inserted. Please go to accounts tab, get the latest account which was inserted from the list view (sort by created date in header), you will find the record which got inserted.
-Anand
Had you by any chance been looking at the recent accounts, and not the all accounts view ?
The account doesnt exist.
Maybe there is some trigger which deletes the record or some field that needs to be filled in.
Add a debug statement System.debug(CopiedAccount.id);
This will give you the id of the record inserted. Take the id and copy paste in the browser url: https://instance(eg: cs13).salesforce.com/copyidhere. If the record exists it should be loaded.
One thing is certain the record is getting inserted.
-Anand
Does anyone know how i can copy the account owner, created by and last modified date fields?
If this aint possible does anyone know in which format i need to insert these fields?
These three fields are lookups to users.
Anand,
The records doesn't exist.
The fields owner, createdby and last modified date aren't filled in.
These fields are required. These fields are also a lookup to an user!
I cant query these fields.
Any idea how i can fix this?
Gr,
Sergio
The field which you mentioned are non-writeable (except for owner) system fields. They are populated by Salesforce on insert/update of the record.
Owner - Generally contains the user creating the record [Unless there is an assignment rule to assign it to a different user/quere]
CreatedBy - Contains the user who creates the record [non-writeable]
Last Modified Date - Contains the date in which the record was last updated [non-writeable]
So these fields should be filled in automatically when i insert a record?
Thats right.
Oke this is weird.
The account is inserted and an ID is created.
But i cant find the account after this.
It is probably deleted.
any idea how this can be possible?
What happens when you do what I asked previously :
Add a debug statement System.debug(CopiedAccount.id);
This will give you the id of the record inserted. Take the id and copy paste in the browser url: https://instance(eg: cs13).salesforce.com/copyidhere. If the record exists it should be loaded.
One thing is certain the record is getting inserted.
Do you get a error?
When i paste the id i get this error:
"Data Not AvailableThe data you were trying to access could not be found. It may be due to another user deleting the data or a system error. If you know the data is not deleted but cannot access it, please look at our support page."
Weird. I hope you also tried querying [SOQL] for the record using the id.
Also please check in your debug logs if there is any delete statement being called. If nothing works out, I'd say - call Salesforce Support.
Is it possible to see the database logs somewhere?
With everything the database has done? Maybe i can see there why the records are deleted or not inserterd.
Debug logs are the only logs I know of. You can check for deleted records in Recycle Bin.
Where can i find the recycle bin?
Below the Sidebar (extreme left on the page) in the Home page.
Thnx for all the help!
But i'm still unable to fix this problem.
Ill contact SF one of these days.
Ill keep you all posted!
Gr,
Sergio
A few things that I wanted to point out.
I posted the debug logs already a few days ago.
You can see them at page one.
Could you have a look at them and tell me if you can see something wrong at them?
Thanks. I do not see anything untoward in the debug logsEspecially, this section of the debug log confirms the insert.
Also, this section of the debug log confirms that only the account insert happened and only 1 account was inserted. I also do not see any future calls being made which should confirm that the record was inserted properly.
I do not see anything that can cause problems with the record insert.
I'm still not able to fix this!
Is there someone who got a working sample code which works for me?
It would of help me much!