Through this blog, I will be sharing simple apex code through which you can fetch the attachment from another org and save it in your current org as attachments. This process includes 2 API calls as mentioned below:
- First API call to fetch attachment details like attachment name etc.
- Second API call to fetch attachment body. Attachment body will be returned in binary format so get the response body as blob and then use it to insert attachment in your current org.
Below is code snippet which you can use to migrate attachment:
In order to test above script, run below mentioned script in developer console:
string sourceOrgUrlAttachmentId='00P0K00001ZvWpe';
string sourceOrgURL='https://sk02-dev-ed.my.salesforce.com';
string access_Token='0XXXXXXXXXXXXXXXXXX8ADac';
string currOrgParentRecid='00190000004Awot';
string result=SK_AttachmentMigrationHelper.findAttachmentDetails(sourceOrgUrlAttachmentId,sourceOrgURL,access_Token,currOrgParentRecid);
system.debug('***attachment Id after migration:'+result);
Instead of access_token, you can also use sessiond of user from source Org.
Refer below URL to understand how to get access token from salesforce:
ACCESS TOKEN USING OAUTH 2.0 IN SALESFORCE
Instead of access_token, you can also use sessiond of user from source Org.
Refer below URL to understand how to get access token from salesforce:
ACCESS TOKEN USING OAUTH 2.0 IN SALESFORCE
How to get all attachments related to parent record Id
Specify endpoint URL as mentioned below while performing callout:
string parentRecId='001xxxxxxxxxxx';
EndPointURL= EndPointURL +'/services/data/v45.0/query/?q=select+id,parentid,ContentType,+name+from+attachment+where+parentid=\''+parentRecId+'\'';
How to migrate bulk attachments from one salesforce org to another
Before migrating the attachments, you will be migrating the parent records from source org to target org. So while migrating store the source org record Id in new custom field in target org.
Now write a batch class in target org and take references from above code to process records one by one. Execute the batch class with 1 batch size.
Hope this will help!!
Enjoyed reading the article above, really explains everything in detail, the article is very interesting and effective. Thank you and good luck for the upcoming articles. OSB Online Training
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteWithout a doubt, it won't be easy to perform this action properly without extra knowledge in this field. What will be the curriculum in such a case?
ReplyDeleteI wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post. dubai islamic bank car loan | ubl car loan
ReplyDeleteThis is really good, I love this content also visit Google Search Api. Thanks for sharing.
ReplyDeleteNice blog, it’s so knowledgeable, informative, and good looking site. I appreciate your hard work. Good job. Thank you for this wonderful sharing with us. Keep Sharing.
ReplyDeleteTours and Travels in Madurai | Best tour operators in Madurai
Best travel agency in Madurai | Best Travels in Madurai
can you post the test class for this code
ReplyDeleteWeb and Pro Infomedia is Best Digital Marketing Agency in Lucknow
ReplyDeleteThanks for this Useful Information
ReplyDeleteRegards
Best Varicose Vein Treatment in Lucknow
Amazing Article, Really useful information to all So, I hope you will share more information to be check and share here.
ReplyDeletePygame Tutorial
Pygame Download
Pygame Install
Matplotlib Python
Matplotlib Tutorial
Matplotlib install
PouchDB Tutorial
What is PouchDB
PouchDB Installation
pouchdb server
In mumbai gateway of india is a hstorical place and this gateway height is 26 meters. this is made by yellow basalt and rainforced concrete. The gate way of india mumbai is also famous for its street food. This monument built in twentieth century and this monument completed in 1924.
ReplyDeleteInteresting stuff to read. Keep it up.
ReplyDeleteAdidas showroom in madurai | Skechers showroom in Madurai
Puma showroom in madurai | Crocs showroom in Madurai
nauman.hanaif@kics.edu.pk
ReplyDeleteertugrul story
children based on the real-life story of About Real-Life Kids Who Changed the World.
Hi, Welcome to Our Channel " my kid's tube " We are making interesting and entering videos.
Especially Detailed and Beautiful Review of Ertugrul Ghazi with Complete Exploration in Easy
Language So please subscribe to Our Channel For my kids' tube.
Have a Nice Day
https://www.youtube.com/watch?v=Eft0LQ7t9M4&t=44s
We are making interesting and entertaining videos for kids.
ReplyDeleteNow, you can watch the cartoon series of the most popular and historic tv show "Ertugrul Ghazi" in urdu.
only on our Youtube Channel "My Kids Tube".
https://www.youtube.com/watch?v=duLVQsYj_Eo
Do you need Finance? Are you looking for Finance? Are you looking for finance to enlarge your business? We help individuals and companies to obtain finance for business expanding and to setup a new business ranging any amount. Get finance at affordable interest rate of 3%, Do you need this finance for business and to clear your bills? Then send us an email now for more information contact us now via (financialserviceoffer876@gmail.com) whats-App +918929509036 Dr James Eric Finance Pvt Ltd Thanks
ReplyDeletehttps://www.youtube.com/watch?v=byGJN5eHWH4
ReplyDeleteComment: Go and Watch the Latest Episode of Kurulus Osman Season 3 in Urdu. Only on our youtube channel.
yeezy shoes
ReplyDeletegolden goose
paul george shoes
supreme shirt
yeezy boost 500
yeezy
golden goose
supreme new york
yeezy boost 350 v2
yeezy