• Javwad Azeem
  • NEWBIE
  • 35 Points
  • Member since 2016
  • Developer
  • HCL Technologies


  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 12
    Replies
If I use only standard list controller then pagination is working fine, but i need to sort list so I'm using extension and when i'm querying records in extension the pagination is not working, I'm new to VF, any help would be appriciated thanx.
code:
VF page
<apex:page standardController="Campaign" recordSetVar="Campaigns" extensions="CampaignCustomContoller">
    <apex:form >

        <apex:pageBlock title="User Driven Campaign" id="campaigns_list">
            
            Filter: 
            <apex:selectList value="{! filterId }" size="1">
                <apex:selectOptions value="{! listViewOptions }"/>
                <apex:actionSupport event="onchange" action="{!updatedCampaignsList}" reRender="campaigns_list"/>
            </apex:selectList>
            <apex:commandLink style="Float:right;" action="{!URLFOR($Action.Campaign.New)}" value="New" />
            <!-- Campaigns List -->  
            
            <apex:pageBlockTable value="{! Campaigns }" var="ct">
                <apex:column >
                    <apex:commandLink action="{! $Page.CampaignDetail}?id={! ct.id}" value="{!ct.Name}"/>
                </apex:column>
                
                <apex:column value="{! ct.Status}"/>
                <apex:column value="{! ct.StartDate}"/>
                <apex:column value="{! ct.LastModifiedDate}"/>
            </apex:pageBlockTable>
            <!-- Pagination -->
            <table style="width: 100%"><tr>
                <td align="center">
                    <!-- Previous page -->
                    <!-- active -->
                    <apex:commandLink action="{! Previous }" value="« Previous"
                         rendered="{! HasPrevious }"/>
                    <!-- inactive (no earlier pages) -->
                    <apex:outputText style="color: #ccc;" value="« Previous"
                         rendered="{! NOT(HasPrevious) }"/>
                    
                    &nbsp;&nbsp;  
                    
                    <!-- Next page -->
                    <!-- active -->
                    <apex:commandLink action="{! Next }" value="Next »"
                         rendered="{! HasNext }"/>
                    <!-- inactive (no more pages) -->
                    <apex:outputText style="color: #ccc;" value="Next »"
                         rendered="{! NOT(HasNext) }"/>
                </td>
            
            </tr></table>

        </apex:pageBlock>

    </apex:form>
</apex:page>

Extension::

public with sharing class CampaignCustomContoller {
    public List<System.SelectOption> listView{get;set;}
    ApexPages.StandardSetController standardCampaignController;
    Map<String,String> mapListView = new Map<String,String>();
    public string filterListId{get;set;}
    public List<Campaign> Campaigns {get;set;}
    public Boolean flag=true;
  
  /*Constructor*/
   public CampaignCustomContoller(ApexPages.StandardSetController controller){
       standardCampaignController = controller;
       Campaigns = controller.getRecords();
       listView = controller.getListViewOptions();
       filterListId = controller.getFilterId();
       flag=true;
       
       for(System.SelectOption s: listView){
           mapListView.put(s.getLabel(),s.getValue());
       }
       controller.setFilterId(mapListView.get('Recently Modified'));
       //updatedCampaignsList();
    }
    
   /*updates campaigns list on page*/
    public void updatedCampaignsList(){
        string selectedListView = 'LastModifiedDate';
        filterListId = standardCampaignController.getFilterId();
        //Campaigns = standardCampaignController.getRecords();
        string whereClauseString = '';
        if(flag||mapListView.get('Recently Modified') == filterListId){
            selectedListView = 'LastModifiedDate';
            flag=false;
        }else if(mapListView.get('All Campaigns') == filterListId){
            selectedListView = 'StartDate';
        }else if(mapListView.get('InActive Campaign') == filterListId){
            selectedListView = 'StartDate';
            whereClauseString = ' WHERE IsActive = false ';
        }else if(mapListView.get('All Active Campaign') == filterListId){
            selectedListView = 'StartDate';
            whereClauseString = ' WHERE IsActive = true ';
        }
        string query = 'SELECT Name,Status,Type,StartDate,LastModifiedDate FROM Campaign'+whereClauseString+' ORDER BY '+selectedListView+' DESC';
        //standardCampaignController = new ApexPages.StandardSetController(Database.getQueryLocator(query));
        Campaigns = Database.query(query);
    }
}


 
Hey Team,

I need help to write a test class for the below code. I have checked developer forums stackexhnage but havent't find anything appropriate to get the code coverage.

I tried creating Mock class, calling method between Test.startTest() and Test.stopTest and even tried exception handling to catch the exception.

Booh, Stuck Now!!! 

I would really appreciate if anyone can help me to write test class for the below code.
 
@future(callout = true)
    public static void getResultTestRun() {
        
        Integer intTotalPercentageCovered = 0;
        String objectIdQuery = 'SELECT PercentCovered FROM ApexOrgWideCoverage';

        String environmentURL = URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v37.0/tooling/query/?q=' + EncodingUtil.urlEncode(objectIdQuery, 'UTF-8');
        
        String username = 'shasahu@hcl.com';
        String password = 'Myhcl12#';

        partnerSoapSforceCom.Soap sp = new partnerSoapSforceCom.Soap();

        partnerSoapSforceCom.LoginResult loginResult = sp.login(username, password);
        //sessionId = loginResult.sessionId;
        //system.debug('sessionId: '+sessionId);
        
        HttpRequest req = new HttpRequest();
        req.setHeader('Authorization', 'Bearer ' + loginResult.sessionId);
        req.setHeader('Content-Type', 'application/json');
        req.setEndpoint(environmentURL);    
        req.setMethod('GET');
        
        Http h = new Http();
        HttpResponse res = h.send(req);
        system.debug('==1==' + res.getBody());
        
        for(JSON2Apex2.Records objRec : JSON2Apex2.parse(res.getBody()).records) {
             System.debug(objRec.PercentCovered );
             if(objRec.PercentCovered != null)
                 intTotalPercentageCovered = objRec.PercentCovered;
             else 
                 intTotalPercentageCovered = 0;
        }
        
        List<ApexTestResult> lstART = [select ApexClassId , MethodName , Id, ApexClass.Name ,Outcome, Message from ApexTestResult];
        string header = 'Class Name, MethodName, Message \n';
        string finalstr = header ;
        for(ApexTestResult a: lstART) {
            if(a.Outcome != 'Pass') {
                string recordString = a.ApexClass.Name+','+a.MethodName+','+a.Message.normalizeSpace()+'\n';
                finalstr = finalstr +recordString;
            }
        }
        
        // Callout #2
        HttpRequest req2 = new HttpRequest();
        req2.setHeader('Authorization', 'Bearer ' + loginResult.sessionId);
        req2.setHeader('Content-Type', 'application/json');
        req2.setEndpoint(URL.getSalesforceBaseURL().toExternalForm()+'/services/data/v33.0/tooling/query/?q=Select+id,ApexClassorTrigger.Name,NumLinesCovered,NumLinesUncovered+from+ApexCodeCoverageAggregate');
        req2.setMethod('GET');
        Http h2 = new Http();
        HttpResponse res2 = h2.send(req2);
        System.debug('response: '+res2.getBody());

        Map<String, Integer > clsVsCov = new Map<String, Integer>();

        Integer totalCovered = 0;
        Integer totalUnCovered = 0;
        
        for(JSON2Apex.Records objRec : JSON2Apex.parse(res2.getBody()).records) {
            System.debug(objRec.ApexClassOrTrigger.Name);
            System.debug(objRec.ApexClassOrTrigger.attributes);
            if(objRec.NumLinesCovered != null && objRec.NumLinesUncovered != null) {
                System.debug('AAAA: '+objRec.NumLinesCovered + objRec.NumLinesUncovered );
                if(objRec.NumLinesCovered + objRec.NumLinesUncovered != 0 ) {
                    totalCovered = totalCovered+objRec.NumLinesCovered;
                    totalUnCovered = totalUnCovered+objRec.NumLinesUncovered;
                    Double totalNOLines  = objRec.NumLinesCovered + objRec.NumLinesUncovered;
                    System.debug('Total Number of Lines: '+totalNOLines);
                    System.debug('objRec.NumLinesCovered: '+objRec.NumLinesCovered);
                    Double coveredPercent = (objRec.NumLinesCovered/totalNOLines)*100;
                    System.debug('coveredPercent: '+coveredPercent);
                    clsVsCov.put(objRec.ApexClassOrTrigger.Name , integer.valueOf(Math.round(coveredPercent)));
                }
                else
                    clsVsCov.put(objRec.ApexClassOrTrigger.Name , 0);
            }
        }
        
        Integer totalCovered2 = 0;
        Integer totalClass = 0;
        
        String header1 = 'Classe Name , Percentage Covered \n';
        String finalstr1 = header1 ;
        for(String strKey : clsVsCov.keySet()) {
            string recordString = strKey+','+clsVsCov.get(strKey)+'\n';
            finalstr1 = finalstr1 +recordString;
        }
        Messaging.EmailFileAttachment csvAttc = new Messaging.EmailFileAttachment();
        blob csvBlob = Blob.valueOf(finalstr);
        string csvname= 'Failed Classes Status.csv';
        csvAttc.setFileName(csvname);
        csvAttc.setBody(csvBlob);
        
        Messaging.EmailFileAttachment csvAttc1 = new Messaging.EmailFileAttachment();
        blob csvBlob1 = Blob.valueOf(finalstr1);
        string csvname1= 'Pass Classes Status.csv';
        csvAttc1.setFileName(csvname1);
        csvAttc1.setBody(csvBlob1);
        
        List<Run_Test__c> RunTestCS = Run_Test__c.getall().values();
            System.debug(RunTestCS[0].Org_Name__c);
            String orgName = RunTestCS[0].Org_Name__c;
            
            String email = RunTestCS[0].Recipient__c;
            
            
        Messaging.SingleEmailMessage email1 =new Messaging.SingleEmailMessage();
        String[] toAddresses1 = new list<string> {email};
        String subject1 ='Code Coverage Result : ' + Datetime.now().format('dd MMMM YYYY');
        email1.setSubject(subject1);
        email1.setToAddresses(toAddresses1);
        
        
            
        //email1.setPlainTextBody('Total Percentage covered of org is : ' + intTotalPercentageCovered);
        String messageBody='<html><body><p>Hi All, <br><br> As of today, overall code coverage of '+orgName+' Org is Below  </p><table border=1 cellpadding=10  style=border-collapse:collapse; >  <tr>    <th>SL No.</th>    <th>Instance</th>    <th>Code Coverage in %</th>  </tr>  <tr>    <td align=center>1</td>    <td align=center>'+orgName+'</td>    <td align=center>'+ intTotalPercentageCovered +'</td>  </tr></table> <p> Thanks & Best Regards,<br>HCL Managed Service Team </p></body></html>';
        email1.setHtmlBody(messageBody);
        email1.setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttc, csvAttc1});
        Messaging.SendEmailResult [] r1 = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email1});
        
        //Below code addere to remover the test checker job
        
        List<CronTrigger> crt = [SELECT id FROM CronTrigger where CronJobDetail.Name like '%Test Run Job Checker%'];
        if(crt.size()>0){
            for(CronTrigger cr:crt){
            System.abortJob(cr.id);
            }
        }
    }

Thanks & Regards,
Javwad Azeem
Hi Team,

Does anyone else getting this error(Please refer the attachment)? While accessing the account records in Lightning Experience where as its working in Salesforce classic.

The error ID and gack ID is attached, if anyone can track the reason why i am getting this error.

User-added image
There is one custom object, which has lookup to Account object. On creating new event in Account object, the same record should get updated in Custom object.
How can this be acheived?
Hi Team,

Does anyone else getting this error(Please refer the attachment)? While accessing the account records in Lightning Experience where as its working in Salesforce classic.

The error ID and gack ID is attached, if anyone can track the reason why i am getting this error.

User-added image
Create a custom object with 'Trail' with resulting API name to be 'Trail__c'. Try to enter the Object name as Trail__c.  It give error as:" The Object Name field can only contain underscores and alphanumeric characters. It must be unique, begin with a letter, not include spaces, not end with an underscore, and not contain two consecutive underscores. Please suggest

Error_Screenshot
 
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.
If I use only standard list controller then pagination is working fine, but i need to sort list so I'm using extension and when i'm querying records in extension the pagination is not working, I'm new to VF, any help would be appriciated thanx.
code:
VF page
<apex:page standardController="Campaign" recordSetVar="Campaigns" extensions="CampaignCustomContoller">
    <apex:form >

        <apex:pageBlock title="User Driven Campaign" id="campaigns_list">
            
            Filter: 
            <apex:selectList value="{! filterId }" size="1">
                <apex:selectOptions value="{! listViewOptions }"/>
                <apex:actionSupport event="onchange" action="{!updatedCampaignsList}" reRender="campaigns_list"/>
            </apex:selectList>
            <apex:commandLink style="Float:right;" action="{!URLFOR($Action.Campaign.New)}" value="New" />
            <!-- Campaigns List -->  
            
            <apex:pageBlockTable value="{! Campaigns }" var="ct">
                <apex:column >
                    <apex:commandLink action="{! $Page.CampaignDetail}?id={! ct.id}" value="{!ct.Name}"/>
                </apex:column>
                
                <apex:column value="{! ct.Status}"/>
                <apex:column value="{! ct.StartDate}"/>
                <apex:column value="{! ct.LastModifiedDate}"/>
            </apex:pageBlockTable>
            <!-- Pagination -->
            <table style="width: 100%"><tr>
                <td align="center">
                    <!-- Previous page -->
                    <!-- active -->
                    <apex:commandLink action="{! Previous }" value="« Previous"
                         rendered="{! HasPrevious }"/>
                    <!-- inactive (no earlier pages) -->
                    <apex:outputText style="color: #ccc;" value="« Previous"
                         rendered="{! NOT(HasPrevious) }"/>
                    
                    &nbsp;&nbsp;  
                    
                    <!-- Next page -->
                    <!-- active -->
                    <apex:commandLink action="{! Next }" value="Next »"
                         rendered="{! HasNext }"/>
                    <!-- inactive (no more pages) -->
                    <apex:outputText style="color: #ccc;" value="Next »"
                         rendered="{! NOT(HasNext) }"/>
                </td>
            
            </tr></table>

        </apex:pageBlock>

    </apex:form>
</apex:page>

Extension::

public with sharing class CampaignCustomContoller {
    public List<System.SelectOption> listView{get;set;}
    ApexPages.StandardSetController standardCampaignController;
    Map<String,String> mapListView = new Map<String,String>();
    public string filterListId{get;set;}
    public List<Campaign> Campaigns {get;set;}
    public Boolean flag=true;
  
  /*Constructor*/
   public CampaignCustomContoller(ApexPages.StandardSetController controller){
       standardCampaignController = controller;
       Campaigns = controller.getRecords();
       listView = controller.getListViewOptions();
       filterListId = controller.getFilterId();
       flag=true;
       
       for(System.SelectOption s: listView){
           mapListView.put(s.getLabel(),s.getValue());
       }
       controller.setFilterId(mapListView.get('Recently Modified'));
       //updatedCampaignsList();
    }
    
   /*updates campaigns list on page*/
    public void updatedCampaignsList(){
        string selectedListView = 'LastModifiedDate';
        filterListId = standardCampaignController.getFilterId();
        //Campaigns = standardCampaignController.getRecords();
        string whereClauseString = '';
        if(flag||mapListView.get('Recently Modified') == filterListId){
            selectedListView = 'LastModifiedDate';
            flag=false;
        }else if(mapListView.get('All Campaigns') == filterListId){
            selectedListView = 'StartDate';
        }else if(mapListView.get('InActive Campaign') == filterListId){
            selectedListView = 'StartDate';
            whereClauseString = ' WHERE IsActive = false ';
        }else if(mapListView.get('All Active Campaign') == filterListId){
            selectedListView = 'StartDate';
            whereClauseString = ' WHERE IsActive = true ';
        }
        string query = 'SELECT Name,Status,Type,StartDate,LastModifiedDate FROM Campaign'+whereClauseString+' ORDER BY '+selectedListView+' DESC';
        //standardCampaignController = new ApexPages.StandardSetController(Database.getQueryLocator(query));
        Campaigns = Database.query(query);
    }
}


 
Hi,
scenario is I created a button ,
on click of button I need to open VF page along with parameters
if I hard code url in button for community users not working
bcz of  community name in not there URL
is this any way to form URL dynamically

I tried URLFOR in Formula
{!URLFOR($Page.ProcurementDetailsPage, null, [Id=SomeId])}
I am getting Error Page.ProcurementDetailsPage does not Exist
Can any one help on this


Thanks,
raghu
Hi,
When I'm trying to install Lightning Partner Management package into my salesforce developer account but it does not get installed and shows few permission related message;

Lightning Partner Management
This app can't be installed.
There are problems that prevent this package from being installed.

Lightning Community Themes(communityThemeDefinitions/Partner_Management.communityThemeDefinition) Missing feature. Installing this package requires the following feature and its associated permissions: Lightning Community Themes
Lightning Bolt Solutions(communityTemplateDefinitions/Partner_Management.communityTemplateDefinition) Missing feature. Installing this package requires the following feature and its associated permissions: Lightning Bolt Solutions


I did not find any permissions related to above message, hence I need suggestion for the same.

Thanks in advance!
<apex:page standardController="Contract" recordSetVar="contracts"  readOnly="true" language="en-US" contentType="application/vnd.ms-excel#test.xls" >
<!---- My Code --->
</apex:page>
This is the code of my visual force page ,And I have added a list view  button on 'Contract' with this page.I click on this button first time after login ,it redirect me to ' /visualforce/recsession'.For second time and after  that it works just fine.
It redirect first time I click on this button after login.
Please let me know if this is a know issue which is not resolved yet,or any solution that can work.