• JD68
  • NEWBIE
  • 50 Points
  • Member since 2015
  • Technical Director
  • System Partners


  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 14
    Replies

Hi,
 
I wonder if someone could help please. I know very little about APEX…I probably need a developer but trying this first.

We use Salesforce for giving out grants – the main part being Organisations & Opportunities (Accounts renamed to Organisations and Opportunities renamed to Grant Requests). Opportunities have two custom fields: Grant Amount and a Decision Date. EG £5,000 12/07/2005

Organisations can apply every year and the Apex code we have had written, lists in a rich text field on the latest grant request the previous grants (ie previous to this grant on the same account) and updates a currency field named: Total of Previous Grants. Eg:
 
£2,500  2004-2005
£1,500  2010-2011
£3,400  2014-2015
 
Total of Previous Grants: £7,400
 
As far as I can tell the code is triggered in two ways:
When a new Grant Request (Opportunity) is created – Works perfectly
When the “Populate Previous Grants” button on a Grant Request is clicked – this has an issue...
 
 The issue with the button seems to be that if an old grant request is added (we are entering old ones) that it does not picked if the “Populate Previous Grants” is clicked. However if I just clone the new grant request, the old grant is picked up. If I then clear down the lists of previous grants and total, save, and then click the button it works fine, which I find a bit odd.
 
I can therefore reproduce the problem but cannot work out what the issue may be. I have put the code below.

Any pointers/suggestiosn would be helpful, thanks, Rob

Button Code
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
var accId="{!Opportunity.AccountId}";
if( accId != null && accId != '') {
var result = sforce.apex.execute("PopulatePreviousGrantsController","populatePreviousGrants",{oppId:"{!Opportunity.Id}"});
if(result=="Success") {
alert("Previous Grants value updated successfully");
}else {
alert(result);
}
location.reload();
} else {
alert('Opportunity must be associated with a Account');
}

Opportunity Trigger
trigger PopulatePreviousGrants on Opportunity (before insert) {

    Set<Id> accIdSet=new Set<Id>();
    Map<Id,List<Opportunity>> oldAccIdAndOppMap=new Map<Id,List<Opportunity>>();
     Map<Id,List<Opportunity>> newAccIdAndOppMap=new Map<Id,List<Opportunity>>();
    List<Opportunity> updateOppList=new List<Opportunity>();
    List<String> args = new String[]{'0','number','###,###,##0.00'};

    
    for(Opportunity opp:Trigger.New) {
        
        accIdSet.add(opp.AccountId);
        if( opp.AccountId != NULL && !newAccIdAndOppMap.containsKey(opp.AccountId)) {
            
            newAccIdAndOppMap.put(opp.AccountId,new List<Opportunity>());
        } 
        newAccIdAndOppMap.get(opp.AccountId).add(opp);
    }
    
    for(Opportunity opp:[SELECT Id,AccountId,Grant_Amount__c,Grant_Payment_Period__c,Previous_Grants_Total__c,Decision_Date__c From Opportunity WHERE AccountId IN :accIdSet ORDER BY Decision_Date__c ]) {
    
        if( opp.AccountId != NULL && !oldAccIdAndOppMap.containsKey(opp.AccountId)) {
            
            oldAccIdAndOppMap.put(opp.AccountId,new List<Opportunity>());
        } 
        oldAccIdAndOppMap.get(opp.AccountId).add(opp);   
    }
    for(Id accId :newAccIdAndOppMap.keySet()) {
        
        for(Opportunity newOpp:newAccIdAndOppMap.get(accId)) {    
            
            if(oldAccIdAndOppMap.containsKey(accId)) {
                
                String previousGrants='';
                Decimal previousGrantsTotal=0;
                for(Opportunity oldOpp:oldAccIdAndOppMap.get(accId)) {
                    
                    if(oldOpp.Grant_Amount__c > 1) {
                        
                        String period=oldOpp.Grant_Payment_Period__c==NULL?'':oldOpp.Grant_Payment_Period__c;
                        previousGrants+=period+'&nbsp;&nbsp;&nbsp;&pound;'+String.format(oldOpp.Grant_Amount__c.format(), args)+'<br>';
                        previousGrantsTotal+=oldOpp.Grant_Amount__c;
                    }        
                }
               newOpp.Previous_Grants__c=previousGrants;
               newOpp.Previous_Grants_Total__c=previousGrantsTotal; 
            }
            if(!oldAccIdAndOppMap.containsKey(accId)) {
                
                oldAccIdAndOppMap.put(accId,new List<Opportunity>()); 
                oldAccIdAndOppMap.get(accId).add(newOpp);   
            } else {
            
                List<Opportunity> tempOldOpp=new List<Opportunity>();
                boolean flag=false;
                for(Opportunity oldOpp:oldAccIdAndOppMap.get(accId)) {
                    
                    if(newOpp.Decision_Date__c<oldOpp.Decision_Date__c && flag == false) {
                    
                        tempOldOpp.add(newOpp);
                        flag=true;
                    }  
                     
                    tempOldOpp.add(oldOpp);  
                }
                if(flag==false) {
                     
                    tempOldOpp.add(newOpp);    
                }
                oldAccIdAndOppMap.get(accId).clear();
                oldAccIdAndOppMap.get(accId).addAll(tempOldOpp);
                System.debug('<--------------------------------->'+tempOldOpp.size());
            }
            
        }
    }    
}
 

How to check my values using debug logs statement in Test class..Here is my test class code

Test class:
static testmethod void test_1(){
           Account acc= new Account();
           acc.Name='Test';
           acc.Type='Customer';
           insert acc;
           
           Contact con = new Contact();
           con.LastName='TestUser';
           con.Email='testUser@test.com';
           con.AccountId=acc.id;
           insert con ; 
           
           opportunity opty = new opportunity();
           opty.Name='test';
           opty.CloseDate=system.today();
           opty.StageName='Advanced';
           opty.AccountId=acc.id;
           opty.Customer_Contact__c=con.id;
           insert opty;
           system.debug('opp' +opty);
        Test.startTest();
        ApexPages.StandardController sc = new ApexPages.StandardController(opty);
        oppexstn testoppexstn = new oppexstn(sc);
        Test.stopTest();
        }

I cant find this debug log text 'opp' in my debug logs statement.

Thanks
Raj
  • July 23, 2015
  • Like
  • 0
I'm using SLDS in a Lightning component, and I'm sure I've read somewhere that the page header can be made to stay fixed whilst the rest of the screen is vertically scrolled.

My page header looks like this:
<div class="slds-page-header">
    <p class="slds-text-heading--label">Contacts</p>
    <h1>My Contacts</h1>
 </div>

Is there a class that I'm missing?
 
  • September 10, 2015
  • Like
  • 0
I'm using SLDS in a Lightning component, and I'm sure I've read somewhere that the page header can be made to stay fixed whilst the rest of the screen is vertically scrolled.

My page header looks like this:
<div class="slds-page-header">
    <p class="slds-text-heading--label">Contacts</p>
    <h1>My Contacts</h1>
 </div>

Is there a class that I'm missing?
 
  • September 10, 2015
  • Like
  • 0
Hi
I have the following piece of code in an Apex Class
 
    public class LineItem {
        public String productCode {get; set;}
        public String productName {get; set;}
        public Decimal quantity {get; set;}
        public Decimal unitPrice {get; set;}
        public Decimal ListEX {get; set;}
        public Decimal ListSubtotal {get; set;}
        public Decimal VAT {get; set;}
        public Decimal subTotal {get; set;}
        public Decimal totalWithVAT {get; set;}
        
        
        public LineItem(String productCode, String productName, Decimal quantity, Decimal unitPrice, Decimal VAT , Decimal ListEX, Decimal ListSubtotal) {
            this.productCode = productCode;
            this.productName = productName;
            this.quantity = quantity;
            this.unitPrice = unitPrice;
            this.ListEX = ListEX ;
            this.ListSubtotal = ListSubtotal ;
            if ( VAT == null ) {
                this.VAT = 0.0;
            } else {
                this.VAT = VAT;
            }
            this.subTotal = (this.quantity * this.unitPrice).setScale(2);
            this.totalWithVAT = (this.quantity * (this.unitPrice + this.VAT)).setScale(2);
        }

I want to change how subTotal is calculated , I want to use a new field instead of unitPrice - how do I do that 
Hi, 

About early last year, we decided to purchase additonal data storage to store millions of data records. We were considering if we should go with regular relational database hosted in SQL server or put them into Salesforce. We opted for 2nd option because we tought we can take advantage Salesforce reporting/dashboard, build additional custom logic with APEX, etc.

Unforunately after spending days of integration, data clean up, ETL to bring the data into our Salesforce, we discovered that Salesforce keeps timing out when we try to view the data with View list, when we try to build reports, or when we try to perform SOQL. The thing is, we are not trying to query all the data. We were just trying to pull subset of data with filter by specific zip code or city. However, no matter what, we kept getting system times out error message.

We logged a ticket and got escalated to tier 3. Support Tier 3 said that this is Salesforce limitation. We were told to download the data somewhere else to view or perform reporting. I feel this is a very unacceptable answer. If this is a real limitation, I feel that Salesforce should have disclosed this info before we purchased the additional data storage.

I am out of luck right now. I am working with our Account Execetive, hoping we can get some refund.  Now, I am considering about storing the data in Postgrees / Heroku and use Heroku Connect to have the data exposed in our Salesforce.

What do you think? Should I go further with this idea, or should I just go with traditional database & web services? 

Thanks for your help in advance.
 
I want to implement a registration process in salesforce site where a person can go and register himself. After then when he login, his uid & password will get authenticated and allow him to enter.

Can anyone help me how to take a approach to this solution.

What i thought.

I will have a custom object. When the user will register, his uid & password will get stored in fields of the object.

When he login, his uid & password will be queried and if match is successful he will able to login.

Please let me know if there is any other approach.

Regards
Our app currently supports users to login with their Salesforce.com accounts.

Now we are trying to integrate Force.com accounts in our app as well.
We use SOAP API for all the communication.

So for Force.com is the login procedure same? Do we use the same API endpoint as Salesforce.com or do we use some other endpoint.
I cannot find this in the docs.

Hi,
 
I wonder if someone could help please. I know very little about APEX…I probably need a developer but trying this first.

We use Salesforce for giving out grants – the main part being Organisations & Opportunities (Accounts renamed to Organisations and Opportunities renamed to Grant Requests). Opportunities have two custom fields: Grant Amount and a Decision Date. EG £5,000 12/07/2005

Organisations can apply every year and the Apex code we have had written, lists in a rich text field on the latest grant request the previous grants (ie previous to this grant on the same account) and updates a currency field named: Total of Previous Grants. Eg:
 
£2,500  2004-2005
£1,500  2010-2011
£3,400  2014-2015
 
Total of Previous Grants: £7,400
 
As far as I can tell the code is triggered in two ways:
When a new Grant Request (Opportunity) is created – Works perfectly
When the “Populate Previous Grants” button on a Grant Request is clicked – this has an issue...
 
 The issue with the button seems to be that if an old grant request is added (we are entering old ones) that it does not picked if the “Populate Previous Grants” is clicked. However if I just clone the new grant request, the old grant is picked up. If I then clear down the lists of previous grants and total, save, and then click the button it works fine, which I find a bit odd.
 
I can therefore reproduce the problem but cannot work out what the issue may be. I have put the code below.

Any pointers/suggestiosn would be helpful, thanks, Rob

Button Code
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
var accId="{!Opportunity.AccountId}";
if( accId != null && accId != '') {
var result = sforce.apex.execute("PopulatePreviousGrantsController","populatePreviousGrants",{oppId:"{!Opportunity.Id}"});
if(result=="Success") {
alert("Previous Grants value updated successfully");
}else {
alert(result);
}
location.reload();
} else {
alert('Opportunity must be associated with a Account');
}

Opportunity Trigger
trigger PopulatePreviousGrants on Opportunity (before insert) {

    Set<Id> accIdSet=new Set<Id>();
    Map<Id,List<Opportunity>> oldAccIdAndOppMap=new Map<Id,List<Opportunity>>();
     Map<Id,List<Opportunity>> newAccIdAndOppMap=new Map<Id,List<Opportunity>>();
    List<Opportunity> updateOppList=new List<Opportunity>();
    List<String> args = new String[]{'0','number','###,###,##0.00'};

    
    for(Opportunity opp:Trigger.New) {
        
        accIdSet.add(opp.AccountId);
        if( opp.AccountId != NULL && !newAccIdAndOppMap.containsKey(opp.AccountId)) {
            
            newAccIdAndOppMap.put(opp.AccountId,new List<Opportunity>());
        } 
        newAccIdAndOppMap.get(opp.AccountId).add(opp);
    }
    
    for(Opportunity opp:[SELECT Id,AccountId,Grant_Amount__c,Grant_Payment_Period__c,Previous_Grants_Total__c,Decision_Date__c From Opportunity WHERE AccountId IN :accIdSet ORDER BY Decision_Date__c ]) {
    
        if( opp.AccountId != NULL && !oldAccIdAndOppMap.containsKey(opp.AccountId)) {
            
            oldAccIdAndOppMap.put(opp.AccountId,new List<Opportunity>());
        } 
        oldAccIdAndOppMap.get(opp.AccountId).add(opp);   
    }
    for(Id accId :newAccIdAndOppMap.keySet()) {
        
        for(Opportunity newOpp:newAccIdAndOppMap.get(accId)) {    
            
            if(oldAccIdAndOppMap.containsKey(accId)) {
                
                String previousGrants='';
                Decimal previousGrantsTotal=0;
                for(Opportunity oldOpp:oldAccIdAndOppMap.get(accId)) {
                    
                    if(oldOpp.Grant_Amount__c > 1) {
                        
                        String period=oldOpp.Grant_Payment_Period__c==NULL?'':oldOpp.Grant_Payment_Period__c;
                        previousGrants+=period+'&nbsp;&nbsp;&nbsp;&pound;'+String.format(oldOpp.Grant_Amount__c.format(), args)+'<br>';
                        previousGrantsTotal+=oldOpp.Grant_Amount__c;
                    }        
                }
               newOpp.Previous_Grants__c=previousGrants;
               newOpp.Previous_Grants_Total__c=previousGrantsTotal; 
            }
            if(!oldAccIdAndOppMap.containsKey(accId)) {
                
                oldAccIdAndOppMap.put(accId,new List<Opportunity>()); 
                oldAccIdAndOppMap.get(accId).add(newOpp);   
            } else {
            
                List<Opportunity> tempOldOpp=new List<Opportunity>();
                boolean flag=false;
                for(Opportunity oldOpp:oldAccIdAndOppMap.get(accId)) {
                    
                    if(newOpp.Decision_Date__c<oldOpp.Decision_Date__c && flag == false) {
                    
                        tempOldOpp.add(newOpp);
                        flag=true;
                    }  
                     
                    tempOldOpp.add(oldOpp);  
                }
                if(flag==false) {
                     
                    tempOldOpp.add(newOpp);    
                }
                oldAccIdAndOppMap.get(accId).clear();
                oldAccIdAndOppMap.get(accId).addAll(tempOldOpp);
                System.debug('<--------------------------------->'+tempOldOpp.size());
            }
            
        }
    }    
}
 


 

I have a button in Opportuinty page which calls myclass, i am trying to show the contracts in visual force page, my controler is Opportunity type so now i am getting error when i try to access the "ContractNumber" in SObject Opportunity, But i need to use Opportunity controler.  NOw how should i access ContractNumber and Status in Visual force page. 
Here is my Visual force page. 

<apex:page standardController="Opportunity"
 extensions="myclass"
 action="{!autoRun}">
  
<apex:pageBlock title="My  Contracts"> 
        <apex:pageBlockTable value="{!Records}"  var="Record"> 
            <apex:column > 
                <apex:facet name="header">Contract Name</apex:facet> 
                <apex:outputText value="{!Record.Name}"/> 
            </apex:column> 
             <apex:column > 
                <apex:facet name="header">Contract Number</apex:facet> 
                <apex:outputText value="{!Record.ContractNumber}"/> 
            </apex:column> 
           <apex:column > 
                <apex:facet name="header">Contract Status</apex:facet> 
                <apex:outputText value="{!Record.Status"/> 
            </apex:column> 
          </apex:pageBlockTable> 
    </apex:pageBlock> 
</apex:page>
Here is my class.
public class  myclass {
 
    
    String theId = ApexPages.currentPage().getParameters().get('id');
    public List<Contract> Records {get; set;}

   public myclass(ApexPages.StandardController stdController) {
        this.o = (Opportunity)stdController.getRecord();
    }
     
    public PageReference autoRun() {
 Records = [select Name, AccountId, StartDate, Status, ContractNumber from Contract where Status='Pending']; 
 return null;
 }
I am new to salesforce , may be its too easy but for me its difficult. Guys any Help ! 
How to check my values using debug logs statement in Test class..Here is my test class code

Test class:
static testmethod void test_1(){
           Account acc= new Account();
           acc.Name='Test';
           acc.Type='Customer';
           insert acc;
           
           Contact con = new Contact();
           con.LastName='TestUser';
           con.Email='testUser@test.com';
           con.AccountId=acc.id;
           insert con ; 
           
           opportunity opty = new opportunity();
           opty.Name='test';
           opty.CloseDate=system.today();
           opty.StageName='Advanced';
           opty.AccountId=acc.id;
           opty.Customer_Contact__c=con.id;
           insert opty;
           system.debug('opp' +opty);
        Test.startTest();
        ApexPages.StandardController sc = new ApexPages.StandardController(opty);
        oppexstn testoppexstn = new oppexstn(sc);
        Test.stopTest();
        }

I cant find this debug log text 'opp' in my debug logs statement.

Thanks
Raj
  • July 23, 2015
  • Like
  • 0
I have 2 visualforce pages :
  • refugee_main_tfi
  • refugee_dash_tfi
To make them available to public ( without salesforce login ) I have created a site and added these pages through  "Enable Visualforce Page Access" to site.

now when i access the site I face two issues:  http://tfifellows-refugeetransition.cs17.force.com/tfihome 
  1. my static resources are not loaded. ( logo image is missing)
  2. The second page after redirect from the first gives me "Authorization error"  --> http://tfifellows-refugeetransition.cs17.force.com/tfihome/refugee_dash_tfi?Id=003g000000X2CwhAAF  ( this is how the url looks after redirect)
This is snippet of my controller for first page that redirects to the second. First page is accessible but not the second (authorization error)
// if validated everything, redirect to detail page for found HBT ID
            String strNewUrl = '/apex/refugee_dash_tfi?Id=' + lstContacts[0].Id;
            PageReference pr = new PageReference (strNewUrl);
            pr.setRedirect (true);
            return pr;

I am new to salesforce and trying to build a site from where contacts can edit objects related to them.
Any guidance will be highly appreciated.