There is no standard way to convert sObject to XML, You need to write a custom logic to prepare this file. Follow below steps - 1.Iterate over Trigger.new 2.Convert a sObject to Map<String,Object> by serializing and deserializing the sObject record from Trigger.new list
/* @param sObjInstance : is one of the instance of sObject from the Trigger.new*/
Map<String,Object> objMap = (Map<String,Object>)JSON.deserializeUntyped(JSON.serialize(sObjInstance));
system.debug('objMap====\n'+objMap);
3.Now iterate over objMap and create a XML String 4.Insert the attachment assigning parentId as sObject instance's Id and set a body as Blob.valueOf(<xmlString>)
It would be better if you keep logic for XML conversion in Salesforce because if you do it through APIs then It will impact on performance and It is not a necessary callout.
Prepare HTTP Request at Salesforce end and only invoke API call for service integration.
How to invoke APIs from Salesforce? => Checkout @future annotation in Trigger.
There is no standard way to convert sObject to XML, You need to write a custom logic to prepare this file. Follow below steps -
1.Iterate over Trigger.new
2.Convert a sObject to Map<String,Object> by serializing and deserializing the sObject record from Trigger.new list 3.Now iterate over objMap and create a XML String
4.Insert the attachment assigning parentId as sObject instance's Id and set a body as Blob.valueOf(<xmlString>)
Do let me know if you need any more help.
Thanks,
Amit Shingavi
Whenever you will use trigger, the Trigger.new will give you the LIST with manipulated data.
Whenever any record is changed or added in Salesforce, the updated record should be sent to our .NET API as XML.
As you said there is no straight-forward way to create XML, so I am thinking of a Trigger based approach.
The Trigger will return List object to an APEX class. This APEX class will invoke the API and pass LIST object as parameter to the API.
The XML conversion will be done in .NET itself.
Please advise.
Prepare HTTP Request at Salesforce end and only invoke API call for service integration.
How to invoke APIs from Salesforce?
=> Checkout @future annotation in Trigger.
Happy Coding!
Can you please help me with iterating ObjMap and forming XMLString.
Thanks,