You need to sign in to do that
Don't have an account?
Taresh Pandey
How to retrieve records from sObject without using Apex controller and trigger ?
Hello all,
I'm new on salesforce technology.I wanna retrieve some records from sObject and I wanna insert those retrieved records into a custome object. without using Apex controller and trigger. How can I perform this task. I'll eagerly wait for yours' reply.
thank you all in advance
I'm new on salesforce technology.I wanna retrieve some records from sObject and I wanna insert those retrieved records into a custome object. without using Apex controller and trigger. How can I perform this task. I'll eagerly wait for yours' reply.
thank you all in advance
Please find below your required script :
List<Opportunity> allOps = new List<Opportunity>([Select Address__c,Contact__c,Email_ID__c,Employee_ID__c,Employee_Name__c,Field_Type__c from Opportunity]);
List<Aplite_work__c> insertApliteWorkList = new List<Aplite_work__c>();
Aplite_work__c apliteWork;
for(Opportunity opp : allOps){
apliteWork = new Aplite_work__c();
apliteWork.Address__c = opp.Address__c;
apliteWork.Contact__c = opp.Contact__c;
apliteWork.Email_ID__c = opp.Email_ID__c;
apliteWork.Employee_ID__c = opp.Employee_ID__c;
apliteWork.Employee_Name__c = opp.Employee_Name__c;
apliteWork.Field_Type__c = opp.Field_Type__c;
insertApliteWorkList.add(apliteWork);
}
if(insertApliteWorkList.size() > 0){
insert insertApliteWorkList;
}
Copy and paste this code into Execute Anonymous Window in Developer Console of your salesforce org.
Note : If you have large number of opportunity records than please avoid using this script and go with the suggestion provided by Lukasz.
Please let me know if you need more help on this.
Thanks,
Abhishek Bansal.
All Answers
If you do not want to use any apex class and trigger than this should be a one time process.
You can achieve this by writing a script and running that script on Developer Console.
Please specify the Sobject from which you want to retrieve the records and also the Custom Object in which you want to insert the records.
Also specify the fields which should be populated in custom object records from retreived Sobejct.
Let me know the answers so that i can help you in writing a script.
Thanks,
Abhishek
You can use Data Loader to export rows from object to csv file.
Next, when exported, adjust rows and columns in csv file by using i.e. Notepad++ or other editor to import into new object, by using Data Loader also.
You can read about Data Loader more here (https://developer.salesforce.com/page/Data_Loader#Other_loading_options).
Hope that helps,
Lukasz
Thank you for your quick reply. sObject is opportunity and my custom object is Aplite_work__c and fields in this object are [Address__c(data type 'text'), Contact__c(data type 'phone'), Email_ID__c(data type 'Email'), Employee_ID__c (data type 'auto number'), Employee_Name__c (data type 'text'), Field_Type__c (data type 'text') ].
thank you. I'll definatly use your idea while performing tasks.
Please find below your required script :
List<Opportunity> allOps = new List<Opportunity>([Select Address__c,Contact__c,Email_ID__c,Employee_ID__c,Employee_Name__c,Field_Type__c from Opportunity]);
List<Aplite_work__c> insertApliteWorkList = new List<Aplite_work__c>();
Aplite_work__c apliteWork;
for(Opportunity opp : allOps){
apliteWork = new Aplite_work__c();
apliteWork.Address__c = opp.Address__c;
apliteWork.Contact__c = opp.Contact__c;
apliteWork.Email_ID__c = opp.Email_ID__c;
apliteWork.Employee_ID__c = opp.Employee_ID__c;
apliteWork.Employee_Name__c = opp.Employee_Name__c;
apliteWork.Field_Type__c = opp.Field_Type__c;
insertApliteWorkList.add(apliteWork);
}
if(insertApliteWorkList.size() > 0){
insert insertApliteWorkList;
}
Copy and paste this code into Execute Anonymous Window in Developer Console of your salesforce org.
Note : If you have large number of opportunity records than please avoid using this script and go with the suggestion provided by Lukasz.
Please let me know if you need more help on this.
Thanks,
Abhishek Bansal.
Now how to write testclass for the same program ??
Test classes are written for either Apex Classes or Apex trigger and in your case there is neither a trigger nor a class.
So please let me know how can we write a test class for a component which does not exist.
Please consult with your senior and clear all your doubts.
https://community.dev.hp.com/t5/First-Time-Here-Learn-How-to/How-to-Mark-Your-Question-as-Solved/td-p/82