You need to sign in to do that
Don't have an account?
tsalb
JS Onclick - Attachment on Object (VFpage PDF)
I was wondering if something like this is possible through S controls and a JS button?
The attachment would need to be on the Service_Request__c object, but the Id for the visualforce page references a different object (Proposal__c)
I'm getting the error (Expected ';' ) and I can't tell where i'm going wrong...
{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")} sforce.connection.serverUrl = '{!$Site.Prefix}/services/Soap/u/24.0'; try { var strQuery="Select Id from Proposal__c where Status__c = 'Awarded' and Service_Request__c = '"+'{!Proposal__c.Service_RequestId__c}'+"'"; var LoeID = sforce.connection.query(strQuery); PageReference savePDF = new PageReference('/apex/vendorloe?rfpId='+LoeID); Blob pdfBlob = savePDF.getContent(); var thisOb = new sforce.SObject("Service_Request__c"); thisOb.Id = "{!Service_Request__c.Id}"; var Atch = new sforce.SObject("Attachment"); Atch.ParentId = thisOb.Id; Atch.Name = 'Letter of Engagement'+'.pdf'; Atch.ContentType = 'pdf'; ATch.Body = pdfBlob; result = sforce.connection.insert([Atch]); } catch(er) { alert(er); }
PageReference object will not available in Javascript.
But we have a solution for your problem. We can create apex webservice [ Which will contain logic to insert attachment ]
Call this webservice from Javascript code
Done
Below are the steps you need to do
1) Create a apex webservice , below is code
This will contain atcual code for attachment
2) Call this webservice from button code
Below is button code
If you need any more assistance , feel free to post
Cheers,
Bala
All Answers
PageReference object will not available in Javascript.
But we have a solution for your problem. We can create apex webservice [ Which will contain logic to insert attachment ]
Call this webservice from Javascript code
Done
Below are the steps you need to do
1) Create a apex webservice , below is code
This will contain atcual code for attachment
2) Call this webservice from button code
Below is button code
If you need any more assistance , feel free to post
Cheers,
Bala
Thanks for your solution - I've implemented it and it's working - but I was wondering if we can take it a step further and automate it completely?
I'll likely start a new post for this - but i was wondering if you could assist me first. Instead of having this through a button - I've modified a trigger to perform this functionality.
However, I realized that i can't use the PageReference and getContent methods in a trigger. How would I be able to automate a pickval change (srf.Status__c = 'Appraisal Contracted') and then programatically call a method and provide it the variables needed to do the attachment creation?