• Leafen Sandy
  • NEWBIE
  • 55 Points
  • Member since 2016

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 12
    Replies
I want fetch all contact names of perticular account in apex class 

List<Contact > lis=[SELECT Id, Name FROM Contact where Account.Id = '0017F00000hvpw4'];
System.debug('lis'+lis); 

 
Hi,

I have a vf page which would contain a script that executes on load and displays some content after loading and this works fine.
But if I call this page using pagereference in a different controller and if I try to convert the page as a pdf using getcontentaspdf() it doesnt executes the action inside the script and so pdf doesnt has the content from the script.

Below is exactly a sample of what I tried,

Page1: mypdfpage
 
<apex:page>
  
<img id="myImg" src="img_pulpit.jpg" alt="The Pulpit Rock" width="304" height="228" />


<p id="demo"></p>

<script>
window.onload = function() {
alert('tset');
var x = document.getElementById("myImg").src;
    document.getElementById("demo").innerHTML = x;
};

</script>
</apex:page>

controller :
 
global class pdfgenerator{

    public pdfgenerator(){
       

        PageReference pageRef = Page.mypdfpage;
        pageRef.setRedirect(true);
        Blob pageContent = pageRef.getContentaspdf();
        String stringContent = EncodingUtil.base64Encode(pageContent);
        system.debug('String Content = ' + stringContent);
    }
}

So from the above code snippet, 
If I try to load the vfpage I get a image and para giving src of the image which is obtained from the script.

But if I try to call the page from my apex class pdfgenerator, and convert it as pdf using EncodingUtil.base64Encode(blob), later when I try to decode and view as pdf, I get only the image not its src.

So I guess my script is not executed when I call the page from controller.

Would like to know on how to execute the script in the page from a controller.

Thanks in Advance,
Leafen.
If there is a possiblity, then

Can I get a code sample (having @http post method) on how to upload pdf file into salesforce object (say as an attachment) sent to salesforce with a http request using multipart/from-data from some external site.

For a while I've gone through multipart/form-data in the developer forum, but I could only find the HTTP Request samples made from salesforce and not to salesforce.

Thanks,
Leafen.
@RestResource(urlMapping='/Merchandise/*')
global with sharing class MerchandiseResource {

private class Attach {
    String Body;
    String ContentType;
    String Name;
}
private class Merchandise {
    Merchandise__c merchandise;
    list<Attach> attachments;
} 

@HttpPost
global static String doPost() {
    //json will be taken directly from RestContext
    Merchandise container = (Merchandise)System.JSON.deserialize(
        RestContext.request.requestBody.tostring(), 
        Merchandise.class);

    Merchandise__c merch = container.merchandise;
    insert merch;

    list<attachment> attachmentToInsert = new list<attachment>();

    for (Attach att :container.attachments) {
        attachmentToInsert.add(
            new Attachment(parentId = merch.Id, name = att.name, 
                           ContentType = att.ContentType, 
                           Body = EncodingUtil.base64Decode(att.body)));
    }
    insert attachmentToInsert;

    return merch.id;
}}

Can anyone suggest me a test class for this above code.
I send the following json.
 
{
    "merchandise": {
        "Name": "Eraser"
    },
    "attachments": [{
        "Body": "d29ybGQ=",
        "ContentType": "text/plain",
        "Name": "hello.txt"
    }, {
        "Body": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAMSURBVBhXY3growIAAycBLhVrvukAAAAASUVORK5CYII=",
        "ContentType": "image/png",
        "Name": "picture.png"
    }]
}


I also tried the below test class,
 
@isTest
public class TesMerchandiseResource 
 {
    
     private Static testMethod void testFunction()
     {


System.RestContext.request = new RestRequest();
        System.RestContext.response = new RestResponse();
        RestContext.request.requestBody =blob.valueof('{}');

		
		 Account accountDetails = new Account();
        accountDetails.name = 'test name';
        upsert accountDetails;
		
 Attachment attachIt = new Attachment();
        attachIt.Name = 'test_attch';
        attachIt.ParentId = accountDetails.id;
        Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body');
      attachIt.body=bodyBlob;
	  
	   RestContext.request.requestBody =blob.valueof('{     "merchandise": {         "Name": "Eraser"     },     "attachments": [{         "Body": "d29ybGQ=",         "ContentType": "text/plain",         "Name": "hello.txt"     }, {         "Body": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAMSURBVBhXY3growIAAycBLhVrvukAAAAASUVORK5CYII=",         "ContentType": "image/png",         "Name": "picture.png"     }] }');
        MerchandiseResource .doPost();

}

}

Still I get error "Attempt to de-reference a null object" in the line ​"for (Attach att :container.attachments) {"

Thanks in Advance,
Leafen.
 
Hi,

I want to have lookup field in vf page that has to be with lightning view and the way it works should be exactly how it works in lightning i.e., should drop down the record list with filtering and not like opening a new window as in classic view.

For this I tried with the code got from http://aljs.appiphony.com/#!/lookups

 
<apex:page showHeader="false" standardStylesheets="false">

<apex:stylesheet value="{!URLFOR($Resource.slds, 'assets/styles/salesforce-lightning-design-system.css')}"/>
<apex:stylesheet value="{!URLFOR($Resource.slds, 'assets/styles/salesforce-lightning-design-system.min.css')}"/>
<apex:includeScript value="https://code.jquery.com/jquery-2.2.4.min.js" /> 
<apex:form >


<!--
<apex:repeat value="{!directors}" var="dirKey">
        <apex:outputText value="{!dirKey}" /> -- 
        <apex:outputText value="{!directors[dirKey]}" /><br/>
</apex:repeat> 

--->

<script>

$(document).ready(function() {
    $('#lookup-01').calllist({
        items: [
            {
                id: 'result-1',
                label: 'Result1',
                metaLabel: 'Optional' 
            },
            {
                id: 'result-2',
                label: 'Result2',
                metaLabel: 'Optional'
            },
            {
                id: 'result-3',
                label: 'Result3',
                metaLabel: 'Optional' 
            },
            {
                id: 'result-4',
                label: 'Result4',
                metaLabel: 'Optional'
            },
            
        ],
    });

    var resultsForSecondLookup = [
        {
            id: 'ajax-result-1',
            label: 'AJAX Result 1',
            metaLabel: 'Optional meta description'
        },
        {
            id: 'ajax-result-2',
            label: 'AJAX Result 2',
            metaLabel: 'Optional meta description'
        },
        {
            id: 'ajax-result-3',
            label: 'AJAX Result 3',
            metaLabel: 'Optional meta description'
        },
        {
            id: 'ajax-result-4',
            label: 'AJAX Result 4',
            metaLabel: 'Optional meta description'
        }
    ];

    $('#lookup-02').againnow({
        items: resultsForSecondLookup,
        objectPluralLabel: 'Things',
        objectLabel: 'Thing',
        useImgTag: false,
        objectIconUrl: '/assets/icons/standard-sprite/svg/symbols.svg#account',
        objectIconClass: 'slds-icon-standard-account',
        initialSelection: { id: 'ajax-result-1', label: 'AJAX Result 1' },
        onClickNew: function() {
            console.log('redirect or run something');
        }
    });
});

</script>

<div class="slds-form-element slds-lookup" data-select="single" data-scope="single">
    <label class="slds-form-element__label" for="lookup-01">Objects</label>
    <div class="slds-form-element__control slds-input-has-icon slds-input-has-icon--right">
        <svg aria-hidden="true" class="slds-input__icon slds-icon-text-default">
     <!--        <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#search"></use>-->
           <use href="{!URLFOR($Resource.sldssc,'/assets/icons/utility-sprite/svg/symbols.svg#search')}"></use>
        </svg>
        <input id="lookup-01" class="slds-lookup__search-input slds-input" type="text" aria-autocomplete="list" role="combobox" aria-expanded="false" aria-activedescendant="" placeholder="Search Objects"/>
    </div>
</div>
<div class="slds-form-element slds-lookup" data-select="single" data-scope="single">
    <label class="slds-form-element__label" for="lookup-02">Things</label>
    <div class="slds-form-element__control slds-input-has-icon slds-input-has-icon--right">
        <svg aria-hidden="true" class="slds-input__icon slds-icon-text-default">
          <!--  <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#search"></use>-->
            <use href="{!URLFOR($Resource.sldssc, '/assets/icons/utility-sprite/svg/symbols.svg#search')}"></use>
        </svg>
        <input id="lookup-02" class="slds-lookup__search-input slds-input" type="text" aria-autocomplete="list" role="combobox" aria-expanded="false" aria-activedescendant="" placeholder="Search Things"/>
    </div>
</div>
</apex:form>
</apex:page>


The above is as such taken from the site(values statically given).

For which I'm getting script errors like lookup function not defined.

Kindly someone let me know is there anything that has to be changed here.

Thanks,
Leafen Sandy.
Hi, I want to upload and preview an excel file in my visualforce page (preferably without using a controller). I got a website which does the same work as I want. Attaching for reference ( http://oss.sheetjs.com/ ) And when I tried to replicate a same kind in my visualforce page using the same page's source (I uploaded and referred all script and other css files), excel file is just keeps loading in the drop zone but its unable to display the preview of the file.

User-added image


Following is my entire modified code.  
 
<apex:page showHeader="false" contentType="text/html" docType="html-5.0">


<html>
    <head>
        <title>SheetJS Live Grid Demo</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <link rel="icon" type="image/png" href="{!URLFOR($Resource.upload, '/upload/logo.png')}" />
        <link rel="stylesheet" href="{!URLFOR($Resource.upload, '/upload/sheetjs.css')}"/>
    </head>
    <body>
        <script src="{!URLFOR($Resource.upload, '/upload/alertify.js')}"></script>
        <script src="{!URLFOR($Resource.upload, '/upload/jquery.min.js')}"></script>
        <script src="{!URLFOR($Resource.upload, '/upload/jquery.handsontable.full.js')}"></script>

        <link rel="stylesheet" media="screen" href="{!URLFOR($Resource.upload, '/upload/jquery.handsontable.full.css')}"/>
        <link rel="stylesheet" media="screen" href="{!URLFOR($Resource.upload, '/upload/samples.css')}"/>
        <link rel="stylesheet" media="screen" href="{!URLFOR($Resource.upload, '/upload/alertify.css')}"/>

        <div id="body">
            <div id="left">
                <div id="logo">
                    <a href="http://sheetjs.com"><img src="{!URLFOR($Resource.upload, '/upload/logo.png')}" class="logo" alt="SheetJS Logo" width="128px" height="128px" /></a>
                </div>
            <div id="drop">Drop a file here</div>
            <h3> Choose a worksheet:</h3>
            <div id="buttons"></div>
        </div>
        <div id="right">
            <div id="header">
                <pre id="out"></pre>
                <h2>SheetJS In-Browser Live Grid Demo</h2>
                <h3>
                    Drop a spreadsheet in the box to the left to see a preview.<br/>
                    Need a file?  Why not the <a href="https://obamawhitehouse.archives.gov/sites/default/files/omb/budget/fy2014/assets/receipts.xls">OMB FY 2014 Federal Receipts?</a>
                </h3>
                <table id="tt">
                  <tr><td colspan="6"><a href="http://github.com/SheetJS/SheetJS.github.io">View This Page Source</a>; <a href="http://github.com/SheetJS/js-xlsx">XLSX Library</a> (for parsing)</td></tr>
                  <tr>
                    <th>File Formats</th>
                    <td><a href="http://github.com/SheetJS/js-xlsx">Library Source</a></td>
                    <td><a href="http://SheetJS.github.io/js-xlsx">Interactive Demo</a></td>
                    <td><a href="http://npm.im/xlsx">"xlsx" on npm</a></td>
                    <td><a href="https://travis-ci.org/SheetJS/js-xlsx">node CI status</a></td>
                    <td><a href="stress.html">browser stress test</a></td>
                  </tr>
                </table>
            </div>
            <div id="hot" style="overflow: scroll" class="handsontable"></div>
            <div id="footnote">
                <h3>
                    This particular parser assumes that <b>the first row of the table is a header.</b><br/>
                    For parsing a more general file, check the Interactive Demos
                </h3><br/>
                <h3>The entire process occurs within your browser <br />
                    <b>NO SPREADSHEET DATA IS SENT TO ANY SERVER (parsing and rendering done in your browser)</b><br/></h3>
                <h3>This is a work in progress.  Every bit helps.  Please email <a href="mailto:dev@sheetjs.com">dev@sheetjs.com</a> with your feedback.</h3>
                <h3>Follow us on Twitter <a href="https://twitter.com/SheetJS">@SheetJS</a></h3>
            </div>
        </div>

        <script src="{!URLFOR($Resource.upload, '/upload/shim.js')}"></script>
        <script src="{!URLFOR($Resource.upload, '/upload/xlsx.full.min.js')}"></script>
        <script src="{!URLFOR($Resource.upload, '/upload/dropsheet.js')}"></script>
        <script src="{!URLFOR($Resource.upload, '/upload/main.js')}"></script>

        <script src="{!URLFOR($Resource.upload, '/upload/spin.js')}"></script>

        <script type="text/javascript">
          var _gaq = _gaq || [];
          _gaq.push(['_setAccount', 'UA-36810333-1']);
          _gaq.push(['_setDomainName', 'sheetjs.com']);
          _gaq.push(['_setAllowLinker', true]);
          _gaq.push(['_trackPageview']);

          (function() {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
          })();
        </script>
        </div>
    </body>
</html>
</apex:page>



Kindly let me know if anything is missed out or where exactly I'm going away. Thanks, Leafen. 
Hi,

I have a page where I have to show the list of all objects in a drop down menu.

But the challenge here is that I'm not using any controller, so I have to do query the objects in the page possibly within the javascript.

Or is there any other simpler way that I can bring out the names of all available objects....

Thanks,
Leafen.
Hi,

Is there any way that I can insert record using a visaulforce page, but not using any controller.

To be even more clear - I have my custum page which looks like the standard record create page (say any object), from here I have to insert new records which should complete the insertion just with the vf page.

Thanks,
Leafen.
Hi,

My exact requirement is as follows,

I have a custom object, say myreports__c, where in each record user will choose a report name in a lookup field and will have a time field, an email field and a date field.

So, now I've to query these records each day which has the today's date in the date field and need to run and email the selected report in those records at the mentioned time.

Even a sample or suggestive code will be greatly helpful.

Thanks,
Leafen Sandy
I want to scan document without installing any desktop applications or salesforce packages, and to save that directly scanned document as an attachment in an object.
Is there a way to do this?
I need to insert image as a signature in email template in lightning experience. There is a option for insert a template but it doesn't show the template from the email templates. Previously I tried it in classic by getting the image from the documents and inserting it as html link in the email template and it worked well there, but when switched to lightning the saved templates doesn't show here when browsed from the email composer and also came to know from the salesforce releasenotes that templates stored in the classic will not be available in the lightning and vice versa. I even tried created template in lightning, even that is not available when tried to insert from the email.
So is there any way that I can add images as a signature and can save that as a template, if possible it should by default appear whenever try to compose email.
Hii.
Using apex:repeat tag i have created table to display two radio buttons and a text field which is dependent on the selection of one of these radio buttons.Using Command link i am adding new row. Only the last row text field is responding for radio button selection but not for the previous rows.I want each row text field to respond to its corresponding radio button. Thank you.....
If there is a possiblity, then

Can I get a code sample (having @http post method) on how to upload pdf file into salesforce object (say as an attachment) sent to salesforce with a http request using multipart/from-data from some external site.

For a while I've gone through multipart/form-data in the developer forum, but I could only find the HTTP Request samples made from salesforce and not to salesforce.

Thanks,
Leafen.
I want fetch all contact names of perticular account in apex class 

List<Contact > lis=[SELECT Id, Name FROM Contact where Account.Id = '0017F00000hvpw4'];
System.debug('lis'+lis); 

 
@RestResource(urlMapping='/Merchandise/*')
global with sharing class MerchandiseResource {

private class Attach {
    String Body;
    String ContentType;
    String Name;
}
private class Merchandise {
    Merchandise__c merchandise;
    list<Attach> attachments;
} 

@HttpPost
global static String doPost() {
    //json will be taken directly from RestContext
    Merchandise container = (Merchandise)System.JSON.deserialize(
        RestContext.request.requestBody.tostring(), 
        Merchandise.class);

    Merchandise__c merch = container.merchandise;
    insert merch;

    list<attachment> attachmentToInsert = new list<attachment>();

    for (Attach att :container.attachments) {
        attachmentToInsert.add(
            new Attachment(parentId = merch.Id, name = att.name, 
                           ContentType = att.ContentType, 
                           Body = EncodingUtil.base64Decode(att.body)));
    }
    insert attachmentToInsert;

    return merch.id;
}}

Can anyone suggest me a test class for this above code.
I send the following json.
 
{
    "merchandise": {
        "Name": "Eraser"
    },
    "attachments": [{
        "Body": "d29ybGQ=",
        "ContentType": "text/plain",
        "Name": "hello.txt"
    }, {
        "Body": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAMSURBVBhXY3growIAAycBLhVrvukAAAAASUVORK5CYII=",
        "ContentType": "image/png",
        "Name": "picture.png"
    }]
}


I also tried the below test class,
 
@isTest
public class TesMerchandiseResource 
 {
    
     private Static testMethod void testFunction()
     {


System.RestContext.request = new RestRequest();
        System.RestContext.response = new RestResponse();
        RestContext.request.requestBody =blob.valueof('{}');

		
		 Account accountDetails = new Account();
        accountDetails.name = 'test name';
        upsert accountDetails;
		
 Attachment attachIt = new Attachment();
        attachIt.Name = 'test_attch';
        attachIt.ParentId = accountDetails.id;
        Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body');
      attachIt.body=bodyBlob;
	  
	   RestContext.request.requestBody =blob.valueof('{     "merchandise": {         "Name": "Eraser"     },     "attachments": [{         "Body": "d29ybGQ=",         "ContentType": "text/plain",         "Name": "hello.txt"     }, {         "Body": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAMSURBVBhXY3growIAAycBLhVrvukAAAAASUVORK5CYII=",         "ContentType": "image/png",         "Name": "picture.png"     }] }');
        MerchandiseResource .doPost();

}

}

Still I get error "Attempt to de-reference a null object" in the line ​"for (Attach att :container.attachments) {"

Thanks in Advance,
Leafen.
 
Hi,

I have a page where I have to show the list of all objects in a drop down menu.

But the challenge here is that I'm not using any controller, so I have to do query the objects in the page possibly within the javascript.

Or is there any other simpler way that I can bring out the names of all available objects....

Thanks,
Leafen.
Hi,

My exact requirement is as follows,

I have a custom object, say myreports__c, where in each record user will choose a report name in a lookup field and will have a time field, an email field and a date field.

So, now I've to query these records each day which has the today's date in the date field and need to run and email the selected report in those records at the mentioned time.

Even a sample or suggestive code will be greatly helpful.

Thanks,
Leafen Sandy
I want to scan document without installing any desktop applications or salesforce packages, and to save that directly scanned document as an attachment in an object.
Is there a way to do this?
Hii.
Using apex:repeat tag i have created table to display two radio buttons and a text field which is dependent on the selection of one of these radio buttons.Using Command link i am adding new row. Only the last row text field is responding for radio button selection but not for the previous rows.I want each row text field to respond to its corresponding radio button. Thank you.....
Hi, 

I created an APEX controller which in theory should pull the data given by the report. Unfortunatly I dont think it's pulling the report at all. Here is the Controller Code.
 
public class reportData{


private static Integer LOWER = 4;
    private static Integer MID = 8;

    public String gaugeColor {
        get;
        set;
    }

    public class GaugeData {
        public String name {
            get;
            set;
        }

        public Integer size {
            get;
            set;
        }

        public GaugeData(String name, Integer size) {
            this.name = name;
            this.size = size;
        }
    }

    public List<GaugeData> data {
        get;
        set;
    }

    public reportData() {
        this.data = new List<GaugeData>();

        List<Report> reportList = [
            select Id, DeveloperName 
            from Report
            where DeveloperName = 'Active_Solution_Hawks'
        ];
        String reportId = (String)reportList.get(0).get('Id');


        Reports.ReportResults results = Reports.ReportManager.runReport(reportId, true);
        Reports.Dimension dim = results.getGroupingsDown();

        Integer numberOfCases = 0;

        for (Reports.GroupingValue groupingVal : dim.getGroupings()) {
            String factMapKey = groupingVal.getKey() + '!T';
            Reports.ReportFactWithDetails factDetails = (Reports.ReportFactWithDetails)results.getFactMap().get(factMapKey);
            Reports.SummaryValue sumVal = factDetails.getAggregates()[0];
            numberOfCases += Integer.valueOf(sumVal.getLabel());
        }

        this.data.add(new GaugeData('Cases', numberOfCases ));

        if (numberOfCases < LOWER) {
            this.gaugeColor = '#093, #ddd';
        } else if (numberOfCases < MID) {
            this.gaugeColor = '#ff6, #ddd';
        } else {
            this.gaugeColor = '#c00, #ddd';
        }
    }
}

I know it doesnt work because numberOfCases stays at zero even though the report has data in it. 

Hello All I want to upload files to my external system using SOAP APIs. My requirements - 

 

1. upload large files to third party system using SOAP API.

2. File size can be of 250GB.

 

Limitation that can restrict me - 

 

1. maximum file size that can be uploaded - 5MB

2. maximum Heap size - 6MB. even if i want to upload usign  SOAP API i will still need to hold blob value in controller.

3. maximum web service reqquest limit - one of the main issues that i feel is 3MB limit on webservice call out, in this case i can not send SOAP request of more than 3MB.

 

Please help me out on this tricky solution. let me know if any further details required.

 

Thanks,

Ray