I am trying to setup these 2 things. I am an Apex newbie so it might be obvious to an experienced developer.
1 below creates an attachment in an opportunity record. Only after it is done I need #2 to run which gets the attachment info and store it in a second object. It just store the docID, parentID of the attachment and a checkbox.
This code works. The only issue is that without flex queue, #2 run before #1 is finished and it can't get the info to store in the second object.
Thanks
G
1) This is a working call out. I just run it as you see it. doco.RenderAPI.renderCreateFileAsync(3, oppID, doco.RenderAPI.Mode.Attachment, doco.RenderAPI.Format.PDF,'filename ' + datetime.now());
2) This is a method that needs to run only after #1 completes.
public Boolean addAttachmentToDAIObject (String oppID)
{
// Create new attachment document in new Document_Additional_Info__c() Object
List<Document_Attachment_Info__c> listToUpdate = new List<Document_Attachment_Info__c>();
List<Attachment> allAttachments = new List<Attachment>();
allAttachments = [Select ID, ParentID, Name from Attachment Where ParentID = :oppID AND Name LIKE '%filename%'];
if(allAttachments.size() > 0)
{
for (Attachment att : allAttachments)
{
String docID = String.valueof(att.id);
Document_Attachment_Info__c daiField = new Document_Attachment_Info__c(Attachment_ID__c = docID, Parent_ID__c = att.ParentId, Is_Portal__c = True);
listToUpdate.add(daiField);
}
try
{
insert listToUpdate;
// Integer iRet = Database.insert(listToUpdate,true);
}
catch (Exception e)
{
System.debug('ERROR:' + e);
Opportunity[] opps;
for( Opportunity opp : opps)
{
opp.AddError('DEBUG: Error in code' + e);
}
}
}
else System.debug('DEBUG: Error in code');
return True;
}