• Jyothy Lakshmy
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 1
    Replies
How can send a visualforcepdf page as attachment while insert / update a record?

I have a requrement to send a visualforce PDF as an email attachemnt on insert a record A.

I am getting the error : " Update failed. First exception on row 0 with id a8d60000000TNzVAAW; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, IDS_SOShipperTrigger: execution of AfterUpdate caused by: System.VisualforceException: Getting content from within triggers is currently not supported".

My code is given below :

trigger IDS_SOShipperTrigger on rstk__soship__c (before insert, before update, after insert, after update) {
    
    Set<Id> shipperIds = new Set<Id>();
    Set<Id> vendorShippedShipperIds = new Set<Id>();
    Map<Id, String> shipperVendorEmails = new Map<Id, String>();
    System.debug('********************777');
    if(Master_Switches__c.getInstance('00e600000017Rhf').Triggers_On__c) {
        System.debug('********************666');
        if(Trigger.isBefore) {
            for(rstk__soship__c shipper : Trigger.New) {
                if(shipper.rstk__soship_closed__c == True
                   && Trigger.oldMap.get(shipper.Id).rstk__soship_closed__c == False) {
                    shipper.Shipment_Date__c = System.Today();
                }
            }
        }        
        else if(Trigger.isAfter) {
            for(rstk__soship__c shipper : Trigger.New) {
                if(shipper.rstk__soship_closed__c == True
                   && Trigger.oldMap.get(shipper.Id).rstk__soship_closed__c == False) {
                    shipperIds.add(shipper.Id);
                }
            }
            //System.debug('********************555');      
            if(shipperIds.size() > 0) {
                //Check whether shipment is sent by a vendor or not.
                for(rstk__sydata__c sydata : [SELECT Id, rstk__sydata_soship__c
                                              FROM rstk__sydata__c
                                              WHERE rstk__sydata_soship__c IN :shipperIds]) {
                    vendorShippedShipperIds.add(sydata.rstk__sydata_soship__c);   
                }
                System.debug('********************444');
                if(vendorShippedShipperIds.size() > 0) {
                    
                    for(rstk__soshipline__c shipperLine : [SELECT Id, rstk__soshipline_shipper__c,
                                                                  rstk__soshipline_line__r.PO_Line__r.rstk__poline_ordno__r.rstk__pohdr_vendno__r.Auto_Packing_List_Email__c
                                                           FROM rstk__soshipline__c
                                                           WHERE rstk__soshipline_shipper__c IN :vendorShippedShipperIds]) {
                        if(shipperLine.rstk__soshipline_line__r.PO_Line__r.rstk__poline_ordno__r.rstk__pohdr_vendno__r.Auto_Packing_List_Email__c != null) {
                            shipperVendorEmails.put(shipperLine.rstk__soshipline_shipper__c,
                                    shipperLine.rstk__soshipline_line__r.PO_Line__r.rstk__poline_ordno__r.rstk__pohdr_vendno__r.Auto_Packing_List_Email__c);
                        }
                    }
                    System.debug('********************333');
                    if(shipperVendorEmails.size() > 0) {
                        //Send emails as pdf attachment
                        Boolean successSend = True;
                        String emailResult = '';
                        List<String> selContactEmails = new List<String>();
                        List<Messaging.SingleEmailMessage> emailList = new List<Messaging.SingleEmailMessage>();
                        transient Messaging.EmailFileAttachment [] pdfAttachmentList = new List<Messaging.EmailFileAttachment> () ;
                        PageReference invoicePage = null;
                        invoicePage = Page.IDS_PackingSlip;
                        selContactEmails.add('jyothy@qburst.com');
                        System.debug('********************222');
                        for(String shipperIdValue : shipperVendorEmails.keySet()){                         
                            invoicePage.getParameters().put('Id', shipperIdValue);
                            invoicePage.setRedirect(true);   
                            Blob invoiceContent = !Test.isRunningTest() ? invoicePage.getContent() : Blob.ValueOf('dummy text');
                            Messaging.EmailFileAttachment pdfAttachment = new Messaging.EmailFileAttachment();
                            pdfAttachment.setFileName('Packing Slip ' + ' - ' + shipperIdValue + '.pdf');
                            pdfAttachment.setBody(invoiceContent);
                            pdfAttachment.setContentType('application/pdf');
                            pdfAttachmentList.add(pdfAttachment);  
                                              
                            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();  
                            selContactEmails.add(shipperVendorEmails.get(shipperIdValue));
                            email.setToAddresses(selContactEmails);
                            email.setSubject('Packing Slip '+ ' - ' + shipperIdValue );
                            email.setPlainTextBody(Label.Invoice_Email_Body);
                            if(pdfAttachmentList != null) {
                                email.setFileAttachments(pdfAttachmentList) ;
                            }
                            emailList.add(email);
                            System.debug('********************111');
                        }
                        if(emailList.size() > 0){
                            Messaging.SendEmailResult[] sendResults = Messaging.sendEmail(emailList);
                            //Get error message if any
                            for(Messaging.SendEmailResult result : sendResults) {
                                if(!result.isSuccess()) {
                                    emailResult = result.getErrors()[0].getMessage();
                                }
                            }
                            if(String.isBlank(emailResult)){
                                emailResult = Label.IDS_Invoice_Sent_Successful_Message;
                                successSend = false;
                            }
                        }    
                    }
                }
            }
        }
    }
}

Any help? Thanks in advance :)
Script to show Account in map is not showing all recods when there is a large number of Accounts. Can anybody help me?
Code :
<apex:page standardController="Account" sidebar="false" recordSetVar="Accounts">

    <html>
        <head>
            <title>Google Maps JavaScript API v3 Example: Geocoding Simple</title>
            <style type="text/css">
                html { width:100%;height: 100% }
                body { width:100%;height: 100%; margin: 0; padding: 0 }
                #map-canvas { width:1000;height:1000;margin:0 auto; }
                div{vertical-align:middle;}
                .wrapper{max-width:1200px;margin:auto;}
                .legend-container{width:200px;margin-left:5px;display:inline-block}
                .legend-tile{color:#777;font-size:10px;padding:5px; width:195px; max-height:50px; display:inline-block; margin:10px; border:4px solid; border-radius:4px;}
                .legend-tile img{ width:20px;}
            </style>
            <script type="text/javascript" src="https://maps.google.com/maps/api/js?v=3&key=AIzaSyDD1LnFxjvmx06ik9HlRtk5jW2wPY_XvPY&sensor=false&callback=initialize"></script>
            <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
            <script>
                
                function initialize(){
                    var map = new google.maps.Map(document.getElementById('map_canvas'), {
                        zoom: 2,
                        minZoom:2,
                        center: new google.maps.LatLng(43.253205,-80.480347),
                        mapTypeId: google.maps.MapTypeId.ROADMAP
                    });
                    var infowindow = new google.maps.InfoWindow();
                    var geocoder = new google.maps.Geocoder();
                    var marker, i=0;
                    var rating;
                    var type;
                    var markercolor;
                    var address="";
                    var shippingstreet;
                    var shippingcity;
                    var shippingstate;
                    var shippingpostalcode;
                    var shippingcountry;
                    
                    <apex:repeat value="{!Accounts}" var="accnt">
                        rating = "{!accnt.Active__c}";
                        type = "{!accnt.Type}";
                        i = i+1;
                        alert("{!accnt.BillingLatitude}");
                        alert("{!accnt.BillingLongitude}");
                      
                        if( rating == "true" &&  type == "Competitor/Chemical Supplier"){
                            markercolor = "{!URLFOR($Resource.VianceMapPin,'VianceMap/red.png')}";
                        }
                        else if ( rating == "true" && type == "Treater"){
                            markercolor = "{!URLFOR($Resource.VianceMapPin,'VianceMap/yellow.png')}";
                        }
                        else if( rating == "false" &&  type == "Competitor/Chemical Supplier"){
                            markercolor = "{!URLFOR($Resource.VianceMapPin,'VianceMap/blue.png')}";
                        }
                        else if ( rating == "false" && type == "Treater"){
                            markercolor = "{!URLFOR($Resource.VianceMapPin,'VianceMap/green.png')}";
                        }
                        
                        shippingstreet = "{!accnt.ShippingStreet}";
                        shippingcity = "{!accnt.ShippingCity}";
                        shippingstate = "{!accnt.ShippingState}";
                        shippingpostalcode = "{!accnt.ShippingPostalCode}";
                        shippingcountry = "{!accnt.ShippingCountry}";
                        
                        if(shippingstreet != "undefined"){
                            address = address + shippingstreet +",";    
                        }
                        if(shippingcity != "undefined"){
                            address = address + shippingcity +",";    
                        }
                        if(shippingstate != "undefined"){
                            address = address + shippingstate +",";    
                        }
                        if(shippingpostalcode != "undefined"){
                            address = address + shippingpostalcode +",";    
                        }
                        if(shippingcountry != "undefined"){
                            address = address + shippingcountry;    
                        }
                        
                        
                        geocodeAddress("{!accnt.Name}, "+address ,markercolor,i);
                        setInterval(geocodeAddress, 2000);
                        address = "";
                    </apex:repeat>
                    function geocodeAddress(location,markercolor,i) {
                        //alert(location);
                        
                        geocoder.geocode( { 'address': location}, function(results, status) {
                            //alert(status);
                            if (status == google.maps.GeocoderStatus.OK) {
                                //alert(results[0].geometry.location);
                                map.setCenter(results[0].geometry.location);
                                createMarker(results[0].geometry.location,"<b>"+location+"</b>",markercolor);
                            }
                            else
                            {
                                //alert("some problem in geocode" + status);
                                if (status == "OVER_QUERY_LIMIT"){
                                    //    sleep(1000);
                                    //startTimer();
                                   // setTimeout(function(){ geocodeAddress(location,markercolor,i),2000 });
                                }     
                            }
                        });
                    }
                    
                    function createMarker(latlng,html,markercolor){
                        var marker = new google.maps.Marker({
                            position: latlng,
                            map: map,
                            icon: new google.maps.MarkerImage(markercolor)
                        });
                        
                        google.maps.event.addListener(marker, 'mouseover', function() {
                            infowindow.setContent(html);
                            infowindow.open(map, marker);
                        });
                        
                        google.maps.event.addListener(marker, 'mouseout', function() {
                            infowindow.close();
                        });
                    }
                }
            </script>
        </head>
        <body style="margin:0px; padding:0px;">
          <div class="wrapper">
            <div id="map_canvas" style="width: 990px; height: 400px; display:inline-block;"/>
            <script>initialize();</script>
            <div class="legend-container">  
                <div class="legend-tile" style="border-color:#EDB6B6;">
                    <div style="display:inline-block;"><apex:image url="{!URLFOR($Resource.VianceMapPin,'VianceMap/red.png')}"/></div><div style="display:inline-block;/*width:213px;*/">Active Competitor/Chemical Supplier</div>
                </div>
                <div class="legend-tile" style="border-color:#BFD5EC;">
                    <div style="display:inline-block;"><apex:image url="{!URLFOR($Resource.VianceMapPin,'VianceMap/blue.png')}"/></div><div style="display:inline-block;/*width:213px;*/">Inactive Competitor/Chemical Supplier</div>
                 </div>
                <div class="legend-tile" style="border-color:#F1F5A8;">
                    <div style="display:inline-block;"><apex:image url="{!URLFOR($Resource.VianceMapPin,'VianceMap/yellow.png')}"/></div><div style="display:inline-block;/*width:213px;*/">Active Treater</div>
                 </div>
                <div class="legend-tile" style="border-color:#CCEBAF;">
                    <div style="display:inline-block;"><apex:image url="{!URLFOR($Resource.VianceMapPin,'VianceMap/green.png')}"/></div><div style="display:inline-block;/*width:213px;*/">Inactive Treater</div>
                </div>
            </div>
           </div>
        </body>
    </html>
    
</apex:page>
Hi all,

        I have a custom object?(card)  in salesforce with field (service order) . I would like to get information from oracle db that match this service order.

What approach would be better?
What about service calls?
I am baby on this case of integration?
Can anybody help me?
If i do REST api,
i have some questions.
I could find a blog :-
https://developer.salesforce.com/blogs/developer-relations/2013/08/integrating-force-com-using-xml-in-apex.html
Can i do something like this?
1. When the call is made to the XML server, is the web browser on the user's PC making the call or is the SalesForce.com server making the call?  
2. Is it makes a difference in how we will need to navigate around the firewall issue?
3. Which is good to use SOAP / REST?
4. What is difference between them?

 Thanks in advance.
Hi all,

        I have a custom object?(card)  in salesforce with field (service order) . I would like to get information from oracle db that match this service order.

What approach would be better?
What about service calls?
I am baby on this case of integration?
Can anybody help me?
If i do REST api,
i have some questions.
I could find a blog :-
https://developer.salesforce.com/blogs/developer-relations/2013/08/integrating-force-com-using-xml-in-apex.html
Can i do something like this?
1. When the call is made to the XML server, is the web browser on the user's PC making the call or is the SalesForce.com server making the call?  
2. Is it makes a difference in how we will need to navigate around the firewall issue?


 Thanks in advance.

Can i remove availability a Forecast category value 'Commit' for a particular recordtype where there is 'Open' type stages ?
Can i generate a popup with c button for confirmation(like javascript implementation for custom button in detail page ) for 'Chatter' tab and 'File' in Chatter ?
Hi all,
    I am using a custom button in event page layout for some interrnam pupose. I have used the code given below to populate the 'Add attachemnt page' from custom button


Code:
URL.getSalesforceBaseUrl().toExternalForm() + '/p/attach/ActivityAttach?relatedListId=' + eventID +'_RelatedActivityAttachmentList&retURL=%2F'+eventID+'%2Fe%3FretURL%3D%252F'+eventID+'&pid='+eventID+'&type=00U';

Link retrieved :
https://cs10.salesforce.com/p/attach/ActivityAttach?relatedListId=00UJ0000009yQ2F_RelatedActivityAttachmentList&retURL=%2F00UJ0000009yQ2F%2Fe%3FretURL%3D%252F00UJ0000009yQ2F&pid=00UJ0000009yQ2F&type=00U


But the issue is after attachement return to 'Edit page ' of event simply like standared functionalty. Instead, i have to return to the view page after saving the attachment. What change i should made for it?

Thanks in advance.
Hi all,

        I have a custom object?(card)  in salesforce with field (service order) . I would like to get information from oracle db that match this service order.

What approach would be better?
What about service calls?
I am baby on this case of integration?
Can anybody help me?
If i do REST api,
i have some questions.
I could find a blog :-
https://developer.salesforce.com/blogs/developer-relations/2013/08/integrating-force-com-using-xml-in-apex.html
Can i do something like this?
1. When the call is made to the XML server, is the web browser on the user's PC making the call or is the SalesForce.com server making the call?  
2. Is it makes a difference in how we will need to navigate around the firewall issue?
3. Which is good to use SOAP / REST?
4. What is difference between them?

 Thanks in advance.
Hi all,

        I have a custom object?(card)  in salesforce with field (service order) . I would like to get information from oracle db that match this service order.

What approach would be better?
What about service calls?
I am baby on this case of integration?
Can anybody help me?
If i do REST api,
i have some questions.
I could find a blog :-
https://developer.salesforce.com/blogs/developer-relations/2013/08/integrating-force-com-using-xml-in-apex.html
Can i do something like this?
1. When the call is made to the XML server, is the web browser on the user's PC making the call or is the SalesForce.com server making the call?  
2. Is it makes a difference in how we will need to navigate around the firewall issue?
3. Which is good to use SOAP / REST?
4. What is difference between them?

 Thanks in advance.