• llisa
  • NEWBIE
  • 90 Points
  • Member since 2015
  • Gyansys

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 21
    Questions
  • 54
    Replies
Hello Everyone,

i am trying to make a validation rule for a text field with 2 decimal values just like 20/30,40/50,1/2,12/4 and single numbers.
It should give error message if it is like 122/22 or 299/349.

Here i wrote a validation rule :
NOT(REGEX(Edited_Discount__c,"[0-9]+[/]{1}[0-9]{2}"))

It will Validate 20/30,40/50 but when i give single it throws validation exception.
Please help me on this .

Thanks
Lisa
  • September 16, 2016
  • Like
  • 0
Hi,

I have a weird issue in my sand box.
I had wrote a javascript custom button to open a tab in primary tab.But the weird  thing is this code only works in my Login only,for others in the same sandbox it throws error

 "Unable to Access Page
You are missing information needed by the page you have attempted to access. If you believe this is an error, please refresh your screen. If the error persists, please report it to our Customer Support team and provide the URL of the page you were requesting as well as any other related information. "

Javascript code :

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!requireScript("/soap/ajax/29.0/apex.js")} 
{!REQUIRESCRIPT("/xdomain/xdomain.js")} 
{!REQUIRESCRIPT("/support/console/33.0/integration.js")} 

var url = "{!$Setup.Product_Complaints_ObjectId__c.ObjectID__c}"; 
if (typeof(srcSelf) == 'function') { 

sforce.console.openPrimaryTab(null, '/setup/ui/recordtypeselect.jsp?ent='+url+'&q_lkid={!Case.Id}&retURL=/a6z/o&save_new_url=/a6z/e?retURL=/a6z/o', true, 'New Product Complaint', openSuccess, 'salesforceTab');
var openSuccess = function openSuccess(result) {};  
}else{ 
window.open("/setup/ui/recordtypeselect.jsp?ent=01IM0000000A31h&q_lkid={!Case.Id}&retURL=/a6z/o&save_new_url=/a6z/e?retURL=/a6z/o","_blank"); 
}

In If part i fetch the id from a custom setting (didn't work for other user in sandbox except me),in else part id is hardcoded (Works for all the users in sandbox).
  • July 23, 2016
  • Like
  • 0
Hi All,

I have creates a custom button "New Test" of list type with Behaviour "Execute Javascript" and Content Source "Onclick Javascript" .

Requirement is to - By clicking this button it will open in console primary tab.
But with this code it will open in console subtab.
Kindly help me on this.

if (typeof(srcSelf) == 'function') { 
srcUp("/a0a/e?isdtp=vw","_blank"); 
}else{ 
window.open("/a0a/e?isdtp=vw","_blank"); 
}
  • July 20, 2016
  • Like
  • 0
Hello Everyone,

I wrote my function currectly .Functionality was to save the pdf and email it with the respective attachment.
Here it saved but not attached in my email page .

public PageReference attachPdfandEmail() 
    {
        PageReference pdf;
        pdf= Page.Quote_PDF;
        pdf.getParameters().put('id', selectedQuote);
        Blob pdfBlob = Test.isRunningTest() ? Blob.valueOf('UNIT.TEST') : pdf.getContent();
        Attachment myAttach = new Attachment();
        myAttach.Parentid = quotes.id;
        myAttach.name = 'Quote_v'+(totalRecords_Attachment+1)+'.pdf';
        myAttach.body = pdf.getContentAsPdf();
        insert myAttach;
        system.debug(myattach.id);
        PageReference ref=new PageReference('/_ui/core/email/author/EmailAuthor?p2_lkid='+acc.id+'&rtype=003&p3_lkid='+quotes.id+'&doc_id='+myattach.id+'&retURL='+quotes.id);
        ref.setRedirect(true);
        return ref;
    }

But while returning the valur the URL changes by itself like :
https://ap2.salesforce.com/_ui/core/email/author/EmailAuthor?doc_id=00P28000006CB6ZEAW&p2_lkid=0012800000EHkmRAAT&p3_lkid=a092800000DdH7ZAAV&retURL=a092800000DdH7ZAAV&rtype=003
Doc id comes firct by itselt and rtype=003 comes last.

please help on this.
    
  • May 17, 2016
  • Like
  • 0
Hii Everyone,

Here i am tried to redirect the button to standard Task page after saving.
It displays an error that EmailAuthor page not found Plz help on this .

public PageReference attachPdfandEmail() 
   {
        PageReference pdf;
        pdf= Page.Quote_PDF;
        pdf.getParameters().put('id', selectedQuote);
        Blob pdfBlob = Test.isRunningTest() ? Blob.valueOf('UNIT.TEST') : pdf.getContent();
        Attachment myAttach = new Attachment();
        myAttach.Parentid = quotes.id;
        myAttach.name = 'Quote_v'+(attachments.size()+1)+'.pdf';
        myAttach.body = pdf.getContentAsPdf();
        insert myAttach;
        system.debug(myattach.id);
        PageReference ref=new PageReference('/apex/_ui/core/email/author/EmailAuthor?p2_lkid='+acc.id+'&rtype=003&p3_lkid='+quotes.id);
          ref.setRedirect(true);
          return ref;
        
        
    }
  • May 16, 2016
  • Like
  • 0
Here Freight is a field from Account object,i create a pdf for this along with other data objects.
The Requirement is like if  there is some value in the Freight field then only its row appear in the Pdf else the row is not at all present.
User-added image
here the Freight value field is Empty so the whole row Freight along with value must be hidden.

I wrote this code but it gives the Error --PDF generation failed. Check the page markup is valid.
Give me some idea about this.


<tr>
<apex:outputPanel rendered="{!if(Account.freight__c!=null,true,false)}">
      <td style="text-align: center; border-right:solid 1px; border-top: 1px solid #000000; width:80%" >
           Freight 
      </td>
     <td style="text-align: center; border-top: 1px solid #000000; width:20%">
          <apex:param value="{!Account.freight__c}" />
     </td>
</apex:outputPanel>
</tr>
  • November 11, 2015
  • Like
  • 0
Here i am trying to write a test class this class,which work is to upload large amount of records in a custom object.
Help me to write its test class please.

public class MassUpload{
    transient public Blob M_Body{get;set;}
    public String emailToalert{get;set;}
    public String retURL{get;set;}
    
    
    public MassUpload(){
    emailToalert='';
    retURL = ApexPages.currentPage().getParameters().get('retURL');
    }
    public void massUpload(){
        if(M_Body==null || M_Body.size()==0){
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select a file to attach.'));
        return;
        }
        try{
        List<String> csvFileLines=M_Body.toString().split('\n');
        csvFileLines.remove(0);
        if(csvFileLines!=null && csvFileLines.size()>0){
        MassUpload mass=new MassUpload(csvFileLines,emailToalert);
        Database.executeBatch(mass,26);
        }
        }catch(Exception e){
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importin data Please make sure input csv file is correct');
            ApexPages.addMessage(errorMessage);
        }
    }
}
  • November 09, 2015
  • Like
  • 0
Hello ,

i want to add a method in test class,but since it contain getContent(), it is giving an error.Methods defined as TestMethod do not support getContent call.
Please suggest me if there any way to call this getContent() method.

This is my method - 

public PageReference attachPdf() {
     if(common.NVL(Acc.Tier__c)<>''){
        PageReference pdf;
        if(Acc.Tier__c.equalsIgnoreCase('Distributor')){  
        pdf= Page.Doc_TD;
        }
        else if(Acc.Tier__c.equalsIgnoreCase('Wholesale')){  
        pdf= Page.Doc_WholeSale;
        }
        else if(Acc.Tier__c.equalsIgnoreCase('SMD')){  
        pdf= Page.Doc_SMD;
        }
        else{
        ApexPages.Message myMsg = new ApexPages.Message(ApexPages.severity.Error, 'Not supported now. Please select a tier.');
        ApexPages.addMessage(myMsg); 
        return null;
        }
        pdf.getParameters().put('id', documentId);
        Blob pdfBlob = pdf.getContent();
        Attachment a = new Attachment(parentId = Acc.id, name=Acc.SMS_Customer__r.name + '_'+ Acc.SMS_Date__c.year()+'_v'+(attachments.size()+1)+ '.pdf', body = pdfBlob, Description='Generate Version');
        PageReference finalPage=new PageReference('/'+documentId);
        insert a;
        return finalPage;
        }else{
        ApexPages.Message myMsg = new ApexPages.Message(ApexPages.severity.Error, 'Please Select Tier for Account ');
        ApexPages.addMessage(myMsg); 
        return null; 
        }
        
    }
  • October 27, 2015
  • Like
  • 0
Hello,

I an a new learner to Email Inbound class.So please Help me on this code.

global class RebateMailService implements Messaging.InboundEmailHandler{
public SMS_bit_A__c bitA; 
 public List<Attachment> attachments;

  global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
    Messaging.InboundEnvelope envelope) {
        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
        String bitAName,comments,status;
       
        
        String[] subjectSplit=email.Subject.split(' ');
            if(!subjectSplit.isEmpty()){
                bitAName=subjectSplit[subjectSplit.size()-2];
                status=subjectSplit[subjectSplit.size()-1];
            }
            
        String[] bodySplit= email.plainTextBody.split('\n');
            if(!bodySplit.isEmpty()){
                   comments=bodySplit[0];
            }    
        bitA=[select id,name,SMS_Contact_Email__c,SMS_Status__c,SMS_VP_sales_email__c,SMS_Legal_person_email__c,Owner.Name from SMS_bit_A__c where name=:bitAName Limit 1];
        attachments=[select id,name,Body,CreatedDate from Attachment where parentId=: bitA.Id Order By CreatedDate Desc LIMIT 1];
        
        if(bitA!=null){           
        if(bitA.SMS_Status__c.equalsIgnoreCase('Draft') || bitA.SMS_Status__c.equalsIgnoreCase('Customer Reject') 
            || bitA.SMS_Status__c.equalsIgnoreCase('In Process')){
            Customer_Email__c custEmail=new Customer_Email__c();
            custEmail.Name=email.Subject;
            custEmail.Email_Content__c=email.htmlBody;
            custEmail.From__c=email.fromAddress;
            custEmail.bit_A__c=bitA.Id;
            insert custEmail;
            if (email.binaryAttachments !=null && email.binaryAttachments.size() > 0)
            {
                for (integer i = 0 ; i < email.binaryAttachments.size() ; i++)
                {
                    Attachment a = new Attachment(ParentId = custEmail.Id,
                    Name = email.binaryAttachments[i].filename,
                    Body = email.binaryAttachments[i].body);
                    insert a;
                }
            }
            
            if(email.textAttachments!=null && email.textAttachments.size() > 0)
            {
                for (integer i = 0 ; i < email.textAttachments.size() ; i++)
                {
                    Attachment a = new Attachment(ParentId = custEmail.Id,
                    Name = email.textAttachments[i].filename,
                    Body = Blob.valueOf(email.textAttachments[i].body));
                    insert a;
                }
            }   
    }
    }
    return result;
 }   
    void sendEmailtoNextApproverfinal(String sendTo){
        List<String> sendToAdds=new List<String>();
        sendToAdds.add(sendTo);
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setToAddresses(sendToAdds);
        
        mail.setReplyTo('noreply@salesforce.com');
        mail.setSenderDisplayName(bitA.Owner.Name);
        //List<String> ccTo = new List<String>();
        //mail.setCcAddresses(ccTo);
        String subject = 'Final Rebate Program ' + bitA.name;
        mail.setSubject(subject);
        String body = getEmailrebateprogram(subject);
        mail.setHtmlBody(body);
         // Create the email attachment
        if(attachments.size()>0){
        Messaging.EmailFileAttachment efa1 = new Messaging.EmailFileAttachment();
        efa1.setFileName(attachments[0].name);
        efa1.setBody(attachments[0].Body);
        mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa1});
        }
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
    }
    
    String getEmailrebateprogram(String subject){
        String strBody = '';        
        strBody+='Dear Customer.';
        strBody+='<BR/>';
        strBody+='<BR/>';
        strBody+= 'This is our Rebate';
        strBody+='<BR/>';
        strBody+='<BR/>';
        strBody+= 'Find the attachment below ';
        strBody+='<BR/>';
        strBody+='<BR/>';
        strBody+='Regards,';
        strBody+='<BR/>';
        strBody+='<BR/>';
        strBody+='abc Solutions, Inc.';
        strBody+='<BR/>';
        strBody+=' Security Division';
        strBody+='<BR/>';
        strBody+='<BR/>';
        strBody+='<BR/>';
        strBody+='Thanks ';
return strBody;    
    } 
    
}
  • October 14, 2015
  • Like
  • 0
Hello,
Here i am tried to write a test class for importing csv file.THere is no code coverage.Plese help me on this.

public class adminPriorSale {
    public list<Distributor_Prior_Sales__c> accon{get;set;}
    public Distributor_Prior_Sales__c agnt{get;set;}
    public Integer PriorSale{set;get;}
    public id tobeEdited{get; set;} 
    public string deleteid{get;set;}
    public boolean editSection {get;set;}
    public ApexPages.StandardController stand;
    Public String retURL{get;set;}
    //To import file
    public Blob csvFileBody{get;set;}
    public string csvAsString{get;set;}
    public String[] csvFileLines{get;set;}
    
    public adminPriorSale(apexpages.standardcontroller controller )
   {
     
     retURL = ApexPages.currentPage().getParameters().get('retURL');
     this.stand=controller;
     tobeEdited = controller.getId();
     agnt = new Distributor_Prior_Sales__c();
     accon = New List<Distributor_Prior_Sales__c>(); 
     accon= [select id,Name,SMS_sales_amount__c,SMS_Year__c,Customer__c,Calculation_Type__c from Distributor_Prior_Sales__c]; 
     
     csvFileLines = new String[]{};
     
     }


public PageReference EdittheSection()
     {
       PageReference ref=new PageReference('/apex/adminPriorSale1?retURL=/apex/Admin');
       ref.setRedirect(true);
       update accon;
       return ref;
       }
    
   private void LoadData()
       {
           accon= [select id,Name,SMS_sales_amount__c,SMS_Year__c,Customer__c,Calculation_Type__c from Distributor_Prior_Sales__c WHERE (owner.id =: userinfo.getuserid())];
       }
        
       // Import CSV file to list of record
       
        public void importCSVFile(){
        
       try{
           csvAsString = csvFileBody.toString();
           csvFileLines = csvAsString.split('\n'); 
           for(Integer i=0;i<csvFileLines.size();i++){
               Distributor_Prior_Sales__c prisale = new Distributor_Prior_Sales__c () ;
               string[] csvRecordData = csvFileLines[i].split(',');
               prisale.SMS_Year__c= csvRecordData[0] ;             
               prisale.SMS_sales_amount__c= Decimal.valueof(csvRecordData[1]);
               prisale.Customer__c= csvRecordData[2];
               prisale.Calculation_Type__c = csvRecordData[3];   
               accon.add(prisale); 
             
           }
        upsert accon;
        
        }
        catch (Exception e)
        {
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,e.getMessage());
            ApexPages.addMessage(errorMessage);
        } 
        
  }    
        
        
    public void save1()
        {
         update accon;
        }
     public void DeleteSale()
       {

        Distributor_Prior_Sales__c del_task=new Distributor_Prior_Sales__c(id=deleteid);
        delete del_task;
        accon=[select id,Name,SMS_sales_amount__c,SMS_Year__c,Customer__c,Calculation_Type__c from Distributor_Prior_Sales__c];
        
        }
        
        
     public pagereference saveRecord()
     {
        List<Distributor_Prior_Sales__c> discLocal=accon.clone() ;
        List<Distributor_Prior_Sales__c> discLocal2=new List<Distributor_Prior_Sales__c>(accon);
         integer i=0;
        for(Distributor_Prior_Sales__c sale:accon){
        
               if(sale.SMS_sales_amount__c==null && sale.SMS_Year__c ==null && sale.Customer__c ==null && sale.Calculation_Type__c==null  )
               { discLocal2.remove(i); }
               
               else if(sale.SMS_sales_amount__c==null || sale.SMS_Year__c ==null || sale.Customer__c ==null || sale.Calculation_Type__c==null )
               {
               ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR,'You must enter all required fields');
               ApexPages.addMessage(msg);
               return null;
              }
              i++;
           }
          upsert discLocal2; 
        PageReference pageRef = new PageReference('/apex/adminPriorSale?retURL=/apex/Admin');
        pageref.setRedirect(true);
        return pageref; 
      }
    
     public PageReference cancel()  
     {
      PageReference pg1=new PageReference('/apex/adminPriorSale?retURL=/apexAdmin');
      pg1.setRedirect(true);
      return pg1;
     }  
   public void addrow() {
            
        Distributor_Prior_Sales__c proSale = new Distributor_Prior_Sales__c();
        proSale.SMS_sales_amount__c= (agnt.SMS_sales_amount__c);
        proSale.SMS_Year__c =(agnt.SMS_Year__c );
        proSale.Customer__c=(agnt.Customer__c);
        proSale.Calculation_Type__c=(agnt.Calculation_Type__c);
        
        accon.add(proSale );
       }  
     }


And it test class is 


@isTest(seeAllData=true)
private class test_adminPriorSale {
    static testMethod void test_adminPriorSale()
    { 
        Distributor_Prior_Sales__c   t1= new Distributor_Prior_Sales__c  ();
        t1.Name='test1';
        t1.SMS_sales_amount__c =123;
        t1.SMS_Year__c='2012';
        insert t1;
        
        String csvContent = 'test1',123,'2012','I Architects','Estimated Prior sales';
        
        PageReference pageRef = Page.adminPriorSale; // Adding VF page Name here
        pageRef.getParameters().put('id', String.valueOf(t1.id));//for page reference
        Test.setCurrentPage(pageRef);
        
        ApexPages.currentPage().getParameters().put('RecordType','adminPriorSale');
        ApexPages.StandardController sc = new ApexPages.standardController(t1);
        adminPriorSale controller = new adminPriorSale(sc);
        
        controller.save1();
        controller.saveRecord();
        controller.addrow();
        controller.DeleteSale();
        controller.editSection = true;
        controller.EdittheSection();
        //controller.LoadData();
        controller.cancel();
        controller.importCSVFile();
        
    }
    static testMethod void test_adminPriorSale2()
    { 
        Distributor_Prior_Sales__c   t1= new Distributor_Prior_Sales__c  ();
        t1.Name='test1';
        //t1.SMS_sales_amount__c =123;
        //t1.SMS_Year__c='2014';
        insert t1;

        Distributor_Prior_Sales__c   t2= new Distributor_Prior_Sales__c  ();
        t2.Name='test1';
        t2.SMS_sales_amount__c =123;
        t2.SMS_Year__c='2014';
        insert t2;
        
        PageReference pageRef = Page.adminPriorSale; // Adding VF page Name here
        pageRef.getParameters().put('id', String.valueOf(t1.id));//for page reference
        pageRef.getParameters().put('retURL', String.valueOf(t1.id));//for page reference
        Test.setCurrentPage(pageRef);
        
        ApexPages.currentPage().getParameters().put('RecordType','adminPriorSale');
        ApexPages.StandardController sc = new ApexPages.standardController(t1);
        adminPriorSale controller = new adminPriorSale(sc);
        controller.saveRecord();
        controller.cancel();
    }

    static testMethod void test_adminPriorSale3()
    { 
        Distributor_Prior_Sales__c   t1= new Distributor_Prior_Sales__c  ();
        t1.Name='test1';
        //t1.SMS_sales_amount__c =123;
        //t1.SMS_Year__c='2014';
        insert t1;
        
        PageReference pageRef = Page.adminPriorSale; // Adding VF page Name here
        pageRef.getParameters().put('id', String.valueOf(t1.id));//for page reference
        Test.setCurrentPage(pageRef);
        
        ApexPages.currentPage().getParameters().put('RecordType','adminPriorSale');
        ApexPages.StandardController sc = new ApexPages.standardController(t1);
        adminPriorSale controller = new adminPriorSale(sc);
        controller.cancel();
        controller.editSection = true;
        controller.EdittheSection();
    }
    
}

It is giving 64% code coverage.not covering the importing csv file part.someone please help me on this.
  • October 14, 2015
  • Like
  • 0
Hello,
Here i am tried to write a test class for importing csv file.THere is no code coverage.Plese help me on this.

Controller Class-
public class adminPriorSale {
    public list<Sales__c> accon{get;set;}
    public Sales__c agnt{get;set;}
    
    public Blob csvFileBody{get;set;}
    public string csvAsString{get;set;}
    public String[] csvFileLines{get;set;}
    
    public adminPriorSale(apexpages.standardcontroller controller )
   {
     agnt = new Distributor_Prior_Sales__c();
     accon = New List<Distributor_Prior_Sales__c>(); 
     accon=[selectid,Name,SMS_sales_amount__c,SMS_Year__c,Exhibit_A_Customer__c,Calculation_Type__c from Distributor_Prior_Sales__c]; 
     csvFileLines = new String[]{};
     
     }

public void importCSVFile(){
        
       try{
              csvAsString = csvFileBody.toString();
              csvFileLines = csvAsString.split('\n'); 
              for(Integer i=0;i<csvFileLines.size();i++){
               Sales__c prisale = new Sales__c () ;
               string[] csvRecordData = csvFileLines[i].split(',');
               prisale.Year__c= csvRecordData[0] ;             
               prisale.sales_amount__c= Decimal.valueof(csvRecordData[1]);
               prisale.Customer__c= csvRecordData[2];
               prisale.Calculation_Type__c = csvRecordData[3];   
               accon.add(prisale); 
             
           }
        upsert accon;
        
        }
        catch (Exception e)
        {
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,e.getMessage());
            ApexPages.addMessage(errorMessage);
        } 
        
  } 
}   



Testclass-
 @isTest
private class test_ExhibitAadminPriorSale {
    static testMethod void test_ExhibitAadminPriorSale4()
    { 
      //  Distributor_Prior_Sales__c   t1= new Distributor_Prior_Sales__c  ();
        //t1.Name='test1';
        //t1.SMS_sales_amount__c =123;
        //t1.SMS_Year__c='2014';
       // insert t1;
  
      
        Document lstDoc = [select id,name,Body from Document where name = 'accttest'];
 
        ExhibitAadminPriorSale file=new ExhibitAadminPriorSale ();
        file.fileAccess();
        Blob content= lstDoc.Body;
        file.csvFileBody = content; 
        file.importCSVFile(); 

file.csvAsString =content.toString();
String[] csvFileLines = new String[]{};
List accon;

accon = new List();
for (Integer i=1;i<csvFileLines.size();i++)
{
String[] csvRecordData = new String[]{};
csvRecordData = csvFileLines [i].split(',');
//Distributor_Prior_Sales__c a = new Distributor_Prior_Sales__c ();
Distributor_Prior_Sales__c   t1= new Distributor_Prior_Sales__c  ();
        t1.Name='test1';
        t1.SMS_sales_amount__c =123;
        t1.SMS_Year__c='2012';
        t1.Exhibit_A_Customer__c='I Architects';
        t1.Calculation_Type__c='Estimated Prior sales';
        t1.RecordTypeId = '0011900000AFc6c';

accon.add(t1); 
try{
      insert accon;
}
catch (Exception e)
{
      ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template');
      ApexPages.addMessage(errormsg);
}

}
}
 
  • October 12, 2015
  • Like
  • 0
I have 4 custom buttons with differentionality.i.e
1. Edit
2. Send to Customer
3.Create pdf
4.Rebate

The senario is if there is no pdf in the custom detail page the "Send to Customer" button is disables else if at least one pdf is there this button is enable.Please some one help me.

here i declare a boolean-

public class Controller
{
public List<Attachment> attachments{get;set;}
public Boolean sendbutton{get;set;}
public Controller(ApexPages.StandardController controller)
{
if (attachments.size()>0)
       {sendbutton=True;}
//other codes
}
}

it throws an error--Attempt to de-reference a null object 
An unexpected error has occurred. Your development organization has been notified.
  • September 29, 2015
  • Like
  • 0
Hello Everyone,

My query is how to differenciate two attachment i.e 2 list for two different attachments in two different page block section..
public List<Attachment> attachments{get;set;}
public List<Attachment> attachments1{get;set;}

Here i create Two different Pageblock Section for both of the attachments.but the problem is that
- i am unable to differenciate both the attachments i.e both page blocksections fetch same data from both attachments.

So give some idea how i differenciate this two different attachments?
  • September 28, 2015
  • Like
  • 0

my class-

public class ExhibitAadminTier {
   public list<Min_Tier_threshold__c> accon{get;set;}
    public Min_Tier_threshold__c agnt{get;set;}
    public Integer mintier{set;get;}
    public id tobeEdited{get; set;} 
    
    public boolean editSection {get;set;}
    public ApexPages.StandardController stand;
    Public String retURL{get;set;}
    
    
    public ExhibitAadminTier(apexpages.standardcontroller controller )
   {
     retURL = ApexPages.currentPage().getParameters().get('retURL');
     this.stand=controller;
     tobeEdited = controller.getId();
     agnt = new Min_Tier_threshold__c();
     accon= [select id,Name,SMS_Threshold__c,SMS_Tier__c,SMS_Tier_Description__c from Min_Tier_threshold__c]; 
      
     }


public PageReference EdittheSection()
     {
       PageReference ref=new PageReference('/apex/ExhibitAadminTier1?retURL=/apex/ExhibitAAdmin');
       ref.setRedirect(true);
       update accon;
       return ref;
       }
    
    private void LoadData()
        {
            accon= [select id,Name,SMS_Threshold__c,SMS_Tier__c,SMS_Tier_Description__c from Min_Tier_threshold__c WHERE (owner.id =: userinfo.getuserid())];
        }
    public void save1()
        {
         update accon;
        }
     public string deleteid{get;set;}
     public void DeleteTier()
       {
        Min_Tier_threshold__c del_task=new Min_Tier_threshold__c (id=deleteid);
        delete del_task;
        accon=[select id,Name,SMS_Threshold__c,SMS_Tier__c,SMS_Tier_Description__c from Min_Tier_threshold__c];
        }
        
        
     public pagereference saveRecord()
     {
        List<Min_Tier_threshold__c> discLocal=accon.clone() ;
        List<Min_Tier_threshold__c> discLocal2=new List<Min_Tier_threshold__c>(accon);
         integer i=0;
        for(Min_Tier_threshold__c Tier:accon){
        
               if(Tier.SMS_Threshold__c==null && Tier.SMS_Tier__c ==null && Tier.SMS_Tier_Description__c==null )
               { discLocal2.remove(i); }
               
               else if(Tier.SMS_Threshold__c==null || Tier.SMS_Tier__c ==null || Tier.SMS_Tier_Description__c==null )
               {
               ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR,'You must enter all required fields');
               ApexPages.addMessage(msg);
               return null;
              }
              i++;
           }
          upsert discLocal2; 
        PageReference pageRef = new PageReference('/apex/ExhibitAadminTier?retURL=/apex/ExhibitAAdmin');
        pageref.setRedirect(true);
        return pageref; 
      }
    
     public PageReference cancel()  
     {
      PageReference pg1=new PageReference('/apex/ExhibitAadminTier?retURL=/apex/ExhibitAAdmin');
      pg1.setRedirect(true);
      return pg1;
     }  
   public void addrow() {
            
        Min_Tier_threshold__c proTier = new Min_Tier_threshold__c();
        proTier .SMS_Threshold__c= (agnt.SMS_Threshold__c);
        proTier .SMS_Tier__c =(agnt.SMS_Tier__c );
        proTier .SMS_Tier_Description__c=(agnt.SMS_Tier_Description__c);
        
        accon.add(proTier );
       }  

     

}

test class--

@isTest//(SeeAllData=true)
private class test_ExhibitAadminTier {
    //boolean editSection = true;
    static testMethod void test_ExhibitAadminTier(){ 
        Min_Tier_threshold__c min1= new Min_Tier_threshold__c();
        min1.name='test1';
        min1.SMS_Threshold__c=100.00;
        min1.SMS_Tier__c='test2';
        min1.SMS_Tier_Description__c ='test3';
        insert min1;
        
        PageReference pageRef = Page.ExhibitAadminTier; // Adding VF page Name here
        pageRef.getParameters().put('id', String.valueOf(min1.id));//for page reference
        Test.setCurrentPage(pageRef);
        
        ApexPages.currentPage().getParameters().put('RecordType','ExhibitAadminTier');
        ApexPages.StandardController sc = new ApexPages.standardController(min1);
        ExhibitAadminTier controller = new ExhibitAadminTier(sc);
    
        controller.save1();
        controller.DeleteTier();
        controller.saveRecord();
        controller.addrow();
}
}

the bold/underlined line parts are not covered i.e THE PAGEREFERENCE part.it covers only 30% of the class. Please take a look on my test class and help me on this
  • September 27, 2015
  • Like
  • 0
How to write a test class for this page reference method.i am unable to cover this part on my controllerclass.

public pagereference saveRecord()
     {
        List<Min_Tier_threshold__c> discLocal=accon.clone() ;
        List<Min_Tier_threshold__c> discLocal2=new List<Min_Tier_threshold__c>(accon);
         integer i=0;
        for(Min_Tier_threshold__c Tier:accon){
        
               if(Tier.SMS_Threshold__c==null && Tier.SMS_Tier__c ==null && Tier.SMS_Tier_Description__c==null )
               { discLocal2.remove(i); }
               
               else if(Tier.SMS_Threshold__c==null || Tier.SMS_Tier__c ==null || Tier.SMS_Tier_Description__c==null )
               {
               ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR,'You must enter all required fields');
               ApexPages.addMessage(msg);
               return null;
              }
              i++;
           }
          upsert discLocal2; 
        PageReference pageRef = new PageReference('/apex/ExhibitAadminTier?retURL=/apex/ExhibitAAdmin');
        pageref.setRedirect(true);
        return pageref; 
      }
    
     public PageReference cancel()  
     {
      PageReference pg1=new PageReference('/apex/ExhibitAadminTier?retURL=/apex/ExhibitAAdmin');
      pg1.setRedirect(true);
      return pg1;
     }  
   public void addrow() {
            
        Min_Tier_threshold__c proTier = new Min_Tier_threshold__c();
        proTier .SMS_Threshold__c= (agnt.SMS_Threshold__c);
        proTier .SMS_Tier__c =(agnt.SMS_Tier__c );
        proTier .SMS_Tier_Description__c=(agnt.SMS_Tier_Description__c);
        
        accon.add(proTier );
       }  


this is my test class---
PageReference pageRef = Page.ExhibitAadminTier; // Adding VF page Name here
        pageRef.getParameters().put('id', String.valueOf(min1.id));//for page reference
        Test.setCurrentPage(pageRef);
        
        ApexPages.currentPage().getParameters().put('RecordType','ExhibitAadminTier');
        ApexPages.StandardController sc = new ApexPages.standardController(min1);
        ExhibitAadminTier controller = new ExhibitAadminTier(sc);
  
        controller.saveRecord();
        controller.addrow();
        controller.cancel();
  • September 27, 2015
  • Like
  • 0
public PageReference FetchExcelReport() {
        PageReference nextpage = new PageReference('/apex/KDashboardExportToExcel');
        return nextpage;
    }
  • September 22, 2015
  • Like
  • 0
My apex code is--

public with sharing class KHistoryController{  
    //Protected Members
    private static final DescribeSObjectResult oSomeObjectSchema = Schema.SObjectType.K_Document__c;
    private static final Map<string, Schema.SObjectField> mapFields = oSomeObjectSchema.fields.getMap();

    //Properties
    public Id SomeObjectId {get;set;}
    public integer PageSize {get;set;}
    public boolean AllowShowMore {get;set;}

    public List<SomeObjectHistory> SomeObjectHistories {
        get { return getSomeObjectHistory(SomeObjectId); }
    }

    //Constructors

    /**
     * Default Constructor
     */
    public KHistoryController() {
        PageSize = 5;   
        AllowShowMore = true;
    }

    //Public Methods
    public void showMore() {
        PageSize += 5;
    }

    //Private Methods

    /**
     * Returns SomeObject History records associated to the current SomeObject
     *
     * @param   SomeObjectId     the SomeObject__c record id to retrieve
     * @return  a list of SomeObjectHistory objects
     */
    private List<SomeObjectHistory> getSomeObjectHistory(Id SomeObjectId) {
        List<SomeObjectHistory> listSomeObjectHistory = new List<SomeObjectHistory>();

        if (SomeObjectId != null) {
            DateTime dLastCreatedDate = null;

            integer limitPlusOne = PageSize + 1;

            List<K_Document__History> listEntityHistory = [SELECT Id, Field, NewValue, OldValue, CreatedDate, CreatedById, CreatedBy.Name FROM K_Document__History WHERE ParentId = :SomeObjectId ORDER BY CreatedDate DESC, Id DESC LIMIT :limitPlusOne];
            AllowShowMore = (listEntityHistory.size() == limitPlusOne);

            for (K_Document__History oHistory : listEntityHistory) {
                SomeObjectHistory oSomeObjectHistory = new SomeObjectHistory(oHistory);

                if (mapFields.containsKey(oHistory.Field)) {
                    oSomeObjectHistory.FieldLabel = mapFields.get(oHistory.Field).getDescribe().Label;
                }

                if (dLastCreatedDate == oHistory.CreatedDate) {
                    oSomeObjectHistory.ShowDateAndUser = false;
                }
                else {
                    oSomeObjectHistory.ShowDateAndUser = true;
                }

                listSomeObjectHistory.add(oSomeObjectHistory);
                dLastCreatedDate = oHistory.CreatedDate;

                if (listSomeObjectHistory.size() == PageSize) break;
            }
        }

        return listSomeObjectHistory;
    }

    //Internal Classes

    /**
     * Data structure representing a SomeObject History record for display
     */
    public class SomeObjectHistory {
        //Properties
        public boolean ShowDateAndUser {get;set;}
        public string FieldLabel {get;set;}
        public K_Document__History History {get; private set;}

        public string ActionFormat {
            get { return getActionFormat(); }
        }

        public SomeObjectHistory(K_Document__History oHistory) {
            History = oHistory;
        }

        //Constructors
        public SomeObjectHistory() {
            showDateAndUser = true;
        }

        //Private Methods
        private string getActionFormat() {
            string sActionFormat = '';

            if (History != null) {
                sActionFormat = 'Record {0}.';

                if (History.newValue != null && History.oldValue == null) {
                    sActionFormat = 'Changed <strong>{1}</strong> to <strong>{3}</strong>.';    
                }
                else if (History.newValue != null && History.oldValue != null) {
                    sActionFormat = 'Changed <strong>{1}</strong> from {2} to <strong>{3}</strong>.';   
                }
                else if (History.Field != null && History.Field.equalsIgnoreCase('created')) {
                    sActionFormat = 'Created.';
                }
            }

            return sActionFormat;
        }
    }
}

and its test class is--

@isTest
private class test_KHistoryControllerTest 
{
    static testMethod void test_KHistoryController1()
    {
        K_Document__c k1 = new K_Document__c();
        k1.note__c = 'abcde';
        k1.Order_Number__c = '123';
        insert k1;
        
        k1.note__c = 'ABCD';
        update k1;
        
        //K_Document__History testHistroyrecord = new K_Document__History(field = 'Test History');//Please add any required field if it shows error
        //insert testHistroyrecord;

        Test.startTest();
        KHistoryController testController = new KHistoryController();
        testController.SomeObjectId = k1.id;
        testController.showMore(); 
        
        List<KHistoryController.SomeObjectHistory> testMethodCalling = testController.SomeObjectHistories;
        Test.stopTest();
    }
}

Here i got 42% of code coverage,please someone help me on this.


 
  • September 17, 2015
  • Like
  • 0
public with sharing class KHistoryController{  
    //Protected Members
    private static final DescribeSObjectResult oSomeObjectSchema = Schema.SObjectType.K_Document__c;
    private static final Map<string, Schema.SObjectField> mapFields = oSomeObjectSchema.fields.getMap();

    //Properties
    public Id SomeObjectId {get;set;}
    public integer PageSize {get;set;}
    public boolean AllowShowMore {get;set;}

    public List<SomeObjectHistory> SomeObjectHistories {
        get { return getSomeObjectHistory(SomeObjectId); }
    }

    //Constructors

    /**
     * Default Constructor
     */
    public KHistoryController() {
        PageSize = 5;   
        AllowShowMore = true;
    }

    //Public Methods
    public void showMore() {
        PageSize += 5;
    }

    //Private Methods

    /**
     * Returns SomeObject History records associated to the current SomeObject
     *
     * @param   SomeObjectId     the SomeObject__c record id to retrieve
     * @return  a list of SomeObjectHistory objects
     */
    private List<SomeObjectHistory> getSomeObjectHistory(Id SomeObjectId) {
        List<SomeObjectHistory> listSomeObjectHistory = new List<SomeObjectHistory>();

        if (SomeObjectId != null) {
            DateTime dLastCreatedDate = null;

            integer limitPlusOne = PageSize + 1;

            List<K_Document__History> listEntityHistory = [SELECT Id, Field, NewValue, OldValue, CreatedDate, CreatedById, CreatedBy.Name FROM K_Document__History WHERE ParentId = :SomeObjectId ORDER BY CreatedDate DESC, Id DESC LIMIT :limitPlusOne];
            AllowShowMore = (listEntityHistory.size() == limitPlusOne);

            for (K_Document__History oHistory : listEntityHistory) {
                SomeObjectHistory oSomeObjectHistory = new SomeObjectHistory(oHistory);

                if (mapFields.containsKey(oHistory.Field)) {
                    oSomeObjectHistory.FieldLabel = mapFields.get(oHistory.Field).getDescribe().Label;
                }

                if (dLastCreatedDate == oHistory.CreatedDate) {
                    oSomeObjectHistory.ShowDateAndUser = false;
                }
                else {
                    oSomeObjectHistory.ShowDateAndUser = true;
                }

                listSomeObjectHistory.add(oSomeObjectHistory);
                dLastCreatedDate = oHistory.CreatedDate;

                if (listSomeObjectHistory.size() == PageSize) break;
            }
        }

        return listSomeObjectHistory;
    }

    //Internal Classes

    /**
     * Data structure representing a SomeObject History record for display
     */
    public class SomeObjectHistory {
        //Properties
        public boolean ShowDateAndUser {get;set;}
        public string FieldLabel {get;set;}
        public K_Document__History History {get; private set;}

        public string ActionFormat {
            get { return getActionFormat(); }
        }

        public SomeObjectHistory(K_Document__History oHistory) {
            History = oHistory;
        }

        //Constructors
        public SomeObjectHistory() {
            showDateAndUser = true;
        }

        //Private Methods
        private string getActionFormat() {
            string sActionFormat = '';

            if (History != null) {
                sActionFormat = 'Record {0}.';

                if (History.newValue != null && History.oldValue == null) {
                    sActionFormat = 'Changed <strong>{1}</strong> to <strong>{3}</strong>.';    
                }
                else if (History.newValue != null && History.oldValue != null) {
                    sActionFormat = 'Changed <strong>{1}</strong> from {2} to <strong>{3}</strong>.';   
                }
                else if (History.Field != null && History.Field.equalsIgnoreCase('created')) {
                    sActionFormat = 'Created.';
                }
            }

            return sActionFormat;
        }
    }
}
  • September 17, 2015
  • Like
  • 0
public class KEmailBodyController{
    public K_Approval_Request_Body__c body{get;set;}
    String kId = '';
    public KEmailBodyController(){
        body = new K_Approval_Request_Body__c();
        kId = ApexPages.currentPage().getParameters().get('id');
        if(common.NVL(kId) != ''){
            List<K_Approval_Request_Body__c> lstBody = [Select Id, Body__c, Related_Document__c, Status__c
                From K_Approval_Request_Body__c Where Related_Document__c=:kId and Status__c = 'Pending' Limit 1];
            if(lstBody != null && lstBody.size()>0){
                body = lstBody[0];


            }
            else{
                body.Related_Document__c = kId;
                body.Status__c = 'Pending';
            }
        }
    }
    public void save(){
        if(body != null && common.NVL(body.Body__c) != ''){
            upsert body;
        }
    }
}

Plese help me,i have totally no idea about test classes.
  • September 17, 2015
  • Like
  • 0
public void save(){
    Datetime yourDate = Datetime.now();
    String dateOutput = yourDate.format('MM/dd/yyyy  h:mm a');
        K_Document__c doc = [Select Id, note__c from K_Document__c where id=:kId];
        if(objNote.note__c <> null){ //format('MM/dd/yyyy HH:mm:ss'
            String note = '<B>' + UserInfo.getName() + '</B>'+ '&nbsp&nbsp' + '<B>'+  yourDate.format('MM/dd/yyyy  h:mm a') + '</B>' ;
            note += '<BR/>' + objNote.note__c;
            doc.note__c = note + '<BR/><BR/>' + common.NVL(doc.note__c);
            
            update doc;
            
            
        }
  • September 16, 2015
  • Like
  • 0
Hello Everyone,

i am trying to make a validation rule for a text field with 2 decimal values just like 20/30,40/50,1/2,12/4 and single numbers.
It should give error message if it is like 122/22 or 299/349.

Here i wrote a validation rule :
NOT(REGEX(Edited_Discount__c,"[0-9]+[/]{1}[0-9]{2}"))

It will Validate 20/30,40/50 but when i give single it throws validation exception.
Please help me on this .

Thanks
Lisa
  • September 16, 2016
  • Like
  • 0
Hi,

I have a weird issue in my sand box.
I had wrote a javascript custom button to open a tab in primary tab.But the weird  thing is this code only works in my Login only,for others in the same sandbox it throws error

 "Unable to Access Page
You are missing information needed by the page you have attempted to access. If you believe this is an error, please refresh your screen. If the error persists, please report it to our Customer Support team and provide the URL of the page you were requesting as well as any other related information. "

Javascript code :

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!requireScript("/soap/ajax/29.0/apex.js")} 
{!REQUIRESCRIPT("/xdomain/xdomain.js")} 
{!REQUIRESCRIPT("/support/console/33.0/integration.js")} 

var url = "{!$Setup.Product_Complaints_ObjectId__c.ObjectID__c}"; 
if (typeof(srcSelf) == 'function') { 

sforce.console.openPrimaryTab(null, '/setup/ui/recordtypeselect.jsp?ent='+url+'&q_lkid={!Case.Id}&retURL=/a6z/o&save_new_url=/a6z/e?retURL=/a6z/o', true, 'New Product Complaint', openSuccess, 'salesforceTab');
var openSuccess = function openSuccess(result) {};  
}else{ 
window.open("/setup/ui/recordtypeselect.jsp?ent=01IM0000000A31h&q_lkid={!Case.Id}&retURL=/a6z/o&save_new_url=/a6z/e?retURL=/a6z/o","_blank"); 
}

In If part i fetch the id from a custom setting (didn't work for other user in sandbox except me),in else part id is hardcoded (Works for all the users in sandbox).
  • July 23, 2016
  • Like
  • 0
Hii Everyone,

Here i am tried to redirect the button to standard Task page after saving.
It displays an error that EmailAuthor page not found Plz help on this .

public PageReference attachPdfandEmail() 
   {
        PageReference pdf;
        pdf= Page.Quote_PDF;
        pdf.getParameters().put('id', selectedQuote);
        Blob pdfBlob = Test.isRunningTest() ? Blob.valueOf('UNIT.TEST') : pdf.getContent();
        Attachment myAttach = new Attachment();
        myAttach.Parentid = quotes.id;
        myAttach.name = 'Quote_v'+(attachments.size()+1)+'.pdf';
        myAttach.body = pdf.getContentAsPdf();
        insert myAttach;
        system.debug(myattach.id);
        PageReference ref=new PageReference('/apex/_ui/core/email/author/EmailAuthor?p2_lkid='+acc.id+'&rtype=003&p3_lkid='+quotes.id);
          ref.setRedirect(true);
          return ref;
        
        
    }
  • May 16, 2016
  • Like
  • 0
Here Freight is a field from Account object,i create a pdf for this along with other data objects.
The Requirement is like if  there is some value in the Freight field then only its row appear in the Pdf else the row is not at all present.
User-added image
here the Freight value field is Empty so the whole row Freight along with value must be hidden.

I wrote this code but it gives the Error --PDF generation failed. Check the page markup is valid.
Give me some idea about this.


<tr>
<apex:outputPanel rendered="{!if(Account.freight__c!=null,true,false)}">
      <td style="text-align: center; border-right:solid 1px; border-top: 1px solid #000000; width:80%" >
           Freight 
      </td>
     <td style="text-align: center; border-top: 1px solid #000000; width:20%">
          <apex:param value="{!Account.freight__c}" />
     </td>
</apex:outputPanel>
</tr>
  • November 11, 2015
  • Like
  • 0
Here i am trying to write a test class this class,which work is to upload large amount of records in a custom object.
Help me to write its test class please.

public class MassUpload{
    transient public Blob M_Body{get;set;}
    public String emailToalert{get;set;}
    public String retURL{get;set;}
    
    
    public MassUpload(){
    emailToalert='';
    retURL = ApexPages.currentPage().getParameters().get('retURL');
    }
    public void massUpload(){
        if(M_Body==null || M_Body.size()==0){
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select a file to attach.'));
        return;
        }
        try{
        List<String> csvFileLines=M_Body.toString().split('\n');
        csvFileLines.remove(0);
        if(csvFileLines!=null && csvFileLines.size()>0){
        MassUpload mass=new MassUpload(csvFileLines,emailToalert);
        Database.executeBatch(mass,26);
        }
        }catch(Exception e){
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importin data Please make sure input csv file is correct');
            ApexPages.addMessage(errorMessage);
        }
    }
}
  • November 09, 2015
  • Like
  • 0
Hello,

I an a new learner to Email Inbound class.So please Help me on this code.

global class RebateMailService implements Messaging.InboundEmailHandler{
public SMS_bit_A__c bitA; 
 public List<Attachment> attachments;

  global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
    Messaging.InboundEnvelope envelope) {
        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
        String bitAName,comments,status;
       
        
        String[] subjectSplit=email.Subject.split(' ');
            if(!subjectSplit.isEmpty()){
                bitAName=subjectSplit[subjectSplit.size()-2];
                status=subjectSplit[subjectSplit.size()-1];
            }
            
        String[] bodySplit= email.plainTextBody.split('\n');
            if(!bodySplit.isEmpty()){
                   comments=bodySplit[0];
            }    
        bitA=[select id,name,SMS_Contact_Email__c,SMS_Status__c,SMS_VP_sales_email__c,SMS_Legal_person_email__c,Owner.Name from SMS_bit_A__c where name=:bitAName Limit 1];
        attachments=[select id,name,Body,CreatedDate from Attachment where parentId=: bitA.Id Order By CreatedDate Desc LIMIT 1];
        
        if(bitA!=null){           
        if(bitA.SMS_Status__c.equalsIgnoreCase('Draft') || bitA.SMS_Status__c.equalsIgnoreCase('Customer Reject') 
            || bitA.SMS_Status__c.equalsIgnoreCase('In Process')){
            Customer_Email__c custEmail=new Customer_Email__c();
            custEmail.Name=email.Subject;
            custEmail.Email_Content__c=email.htmlBody;
            custEmail.From__c=email.fromAddress;
            custEmail.bit_A__c=bitA.Id;
            insert custEmail;
            if (email.binaryAttachments !=null && email.binaryAttachments.size() > 0)
            {
                for (integer i = 0 ; i < email.binaryAttachments.size() ; i++)
                {
                    Attachment a = new Attachment(ParentId = custEmail.Id,
                    Name = email.binaryAttachments[i].filename,
                    Body = email.binaryAttachments[i].body);
                    insert a;
                }
            }
            
            if(email.textAttachments!=null && email.textAttachments.size() > 0)
            {
                for (integer i = 0 ; i < email.textAttachments.size() ; i++)
                {
                    Attachment a = new Attachment(ParentId = custEmail.Id,
                    Name = email.textAttachments[i].filename,
                    Body = Blob.valueOf(email.textAttachments[i].body));
                    insert a;
                }
            }   
    }
    }
    return result;
 }   
    void sendEmailtoNextApproverfinal(String sendTo){
        List<String> sendToAdds=new List<String>();
        sendToAdds.add(sendTo);
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setToAddresses(sendToAdds);
        
        mail.setReplyTo('noreply@salesforce.com');
        mail.setSenderDisplayName(bitA.Owner.Name);
        //List<String> ccTo = new List<String>();
        //mail.setCcAddresses(ccTo);
        String subject = 'Final Rebate Program ' + bitA.name;
        mail.setSubject(subject);
        String body = getEmailrebateprogram(subject);
        mail.setHtmlBody(body);
         // Create the email attachment
        if(attachments.size()>0){
        Messaging.EmailFileAttachment efa1 = new Messaging.EmailFileAttachment();
        efa1.setFileName(attachments[0].name);
        efa1.setBody(attachments[0].Body);
        mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa1});
        }
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
    }
    
    String getEmailrebateprogram(String subject){
        String strBody = '';        
        strBody+='Dear Customer.';
        strBody+='<BR/>';
        strBody+='<BR/>';
        strBody+= 'This is our Rebate';
        strBody+='<BR/>';
        strBody+='<BR/>';
        strBody+= 'Find the attachment below ';
        strBody+='<BR/>';
        strBody+='<BR/>';
        strBody+='Regards,';
        strBody+='<BR/>';
        strBody+='<BR/>';
        strBody+='abc Solutions, Inc.';
        strBody+='<BR/>';
        strBody+=' Security Division';
        strBody+='<BR/>';
        strBody+='<BR/>';
        strBody+='<BR/>';
        strBody+='Thanks ';
return strBody;    
    } 
    
}
  • October 14, 2015
  • Like
  • 0
Hi,

I wanted to add some additional rows to my pageblock table.  For example, I'm doing a top 10 opportunities, and I wanted

total opportuntities
total goal 
variance from goal.

Is this possible?   I figure I could make a custom class and piece together all the different pieces but I'm hoping there's a better easier solution, kind of like how you might do it when piecing together a regular table with apex repeat.

Thanks,

my class-

public class ExhibitAadminTier {
   public list<Min_Tier_threshold__c> accon{get;set;}
    public Min_Tier_threshold__c agnt{get;set;}
    public Integer mintier{set;get;}
    public id tobeEdited{get; set;} 
    
    public boolean editSection {get;set;}
    public ApexPages.StandardController stand;
    Public String retURL{get;set;}
    
    
    public ExhibitAadminTier(apexpages.standardcontroller controller )
   {
     retURL = ApexPages.currentPage().getParameters().get('retURL');
     this.stand=controller;
     tobeEdited = controller.getId();
     agnt = new Min_Tier_threshold__c();
     accon= [select id,Name,SMS_Threshold__c,SMS_Tier__c,SMS_Tier_Description__c from Min_Tier_threshold__c]; 
      
     }


public PageReference EdittheSection()
     {
       PageReference ref=new PageReference('/apex/ExhibitAadminTier1?retURL=/apex/ExhibitAAdmin');
       ref.setRedirect(true);
       update accon;
       return ref;
       }
    
    private void LoadData()
        {
            accon= [select id,Name,SMS_Threshold__c,SMS_Tier__c,SMS_Tier_Description__c from Min_Tier_threshold__c WHERE (owner.id =: userinfo.getuserid())];
        }
    public void save1()
        {
         update accon;
        }
     public string deleteid{get;set;}
     public void DeleteTier()
       {
        Min_Tier_threshold__c del_task=new Min_Tier_threshold__c (id=deleteid);
        delete del_task;
        accon=[select id,Name,SMS_Threshold__c,SMS_Tier__c,SMS_Tier_Description__c from Min_Tier_threshold__c];
        }
        
        
     public pagereference saveRecord()
     {
        List<Min_Tier_threshold__c> discLocal=accon.clone() ;
        List<Min_Tier_threshold__c> discLocal2=new List<Min_Tier_threshold__c>(accon);
         integer i=0;
        for(Min_Tier_threshold__c Tier:accon){
        
               if(Tier.SMS_Threshold__c==null && Tier.SMS_Tier__c ==null && Tier.SMS_Tier_Description__c==null )
               { discLocal2.remove(i); }
               
               else if(Tier.SMS_Threshold__c==null || Tier.SMS_Tier__c ==null || Tier.SMS_Tier_Description__c==null )
               {
               ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR,'You must enter all required fields');
               ApexPages.addMessage(msg);
               return null;
              }
              i++;
           }
          upsert discLocal2; 
        PageReference pageRef = new PageReference('/apex/ExhibitAadminTier?retURL=/apex/ExhibitAAdmin');
        pageref.setRedirect(true);
        return pageref; 
      }
    
     public PageReference cancel()  
     {
      PageReference pg1=new PageReference('/apex/ExhibitAadminTier?retURL=/apex/ExhibitAAdmin');
      pg1.setRedirect(true);
      return pg1;
     }  
   public void addrow() {
            
        Min_Tier_threshold__c proTier = new Min_Tier_threshold__c();
        proTier .SMS_Threshold__c= (agnt.SMS_Threshold__c);
        proTier .SMS_Tier__c =(agnt.SMS_Tier__c );
        proTier .SMS_Tier_Description__c=(agnt.SMS_Tier_Description__c);
        
        accon.add(proTier );
       }  

     

}

test class--

@isTest//(SeeAllData=true)
private class test_ExhibitAadminTier {
    //boolean editSection = true;
    static testMethod void test_ExhibitAadminTier(){ 
        Min_Tier_threshold__c min1= new Min_Tier_threshold__c();
        min1.name='test1';
        min1.SMS_Threshold__c=100.00;
        min1.SMS_Tier__c='test2';
        min1.SMS_Tier_Description__c ='test3';
        insert min1;
        
        PageReference pageRef = Page.ExhibitAadminTier; // Adding VF page Name here
        pageRef.getParameters().put('id', String.valueOf(min1.id));//for page reference
        Test.setCurrentPage(pageRef);
        
        ApexPages.currentPage().getParameters().put('RecordType','ExhibitAadminTier');
        ApexPages.StandardController sc = new ApexPages.standardController(min1);
        ExhibitAadminTier controller = new ExhibitAadminTier(sc);
    
        controller.save1();
        controller.DeleteTier();
        controller.saveRecord();
        controller.addrow();
}
}

the bold/underlined line parts are not covered i.e THE PAGEREFERENCE part.it covers only 30% of the class. Please take a look on my test class and help me on this
  • September 27, 2015
  • Like
  • 0
hello

i am trying to make a validation rule for a currency field with 2 decimal values so that it only enables the user to put .00 .25 .50 and .75, with any other value in the decimals i need it to trigger the erro message.
this is what i've got so far:

NOT(REGEX(TEXT( Gross_Pay__c ), "[0-9]+[.]{1}[25,50]{2}")) it works for 25 and other values but not for 50 
We have created a custom sObject Address which is linked to Account in a Child-Parent way. So that one Account has multiple Addresses. We have added the Address sObject as a related list to our Account layout.
Does anybody know how can we configure the Address to open as a primary tab instead of a sub tab in the Salesforce.com Console when we open it from the Account related list?

Thank you!
Valid: 12.00, 12.10, 12.01, 12.56
Not Valid: 12, 12.1, 12.0

NOT(REGEX(TEXT(Price__c), "[0-9]+[.][0-9][0-9]?"))

I am writing an validation rule for currency field. Can anyone help me with this.
  • January 16, 2014
  • Like
  • 0

///////Visualforce////////

<apex:page standardController="Student__c" extensions="Student">
<apex:pageblock title="New Account">
<apex:pageBlockSection title="Register">
<apex:form >
<b>Username:</b> <br/>
<apex:inputText required="true" id="username" value="{!Student__c.Name}" /> <br/>
<b>Password:</b> <br/>
<apex:inputSecret required="true" id="password" value="{!Student__c.Mobile__c}"/> <br/>
<b>Email:</b> <br/>
<apex:inputText required="true" id="emailid" value="{!Student__c.Email__c}" /> <br/>
<b>Phone Number:</b> <br/>
<apex:inputText required="true" id="phno" value="{!Student__c.Height__c}" /> <br/> <br/>

<apex:commandButton value="Register" action="{!register}"/> <t/> <t/>
<apex:commandButton value="Existing User" action="{!pbck}"/> <br/> <br/>
</apex:form>
</apex:pageBlockSection>

</apex:pageblock>


</apex:page>

 

 

 

/////Controller////////

 

public with sharing class Student {
private final Student std;

public String Name{ get; set; }
public Double Height__c{ get; set; }
public String Email__c{ get; set; }
public String Mobile__c { get; set; }

list<student__c> stdlist=[select id, Name, Height__c, Email__c, Mobile__c from student__c where id=:ApexPages.currentPage().getParameters().get('id')];

public Student(ApexPages.StandardController controller) {
this.std= (Student)Controller.getRecord();
}

public PageReference pbck() {

return page.mylogin;
}


public PageReference register() {
insert stdlist;
return page.mylogin;
}

}

 

 

Im facing following errors:

1: Error: Student Compile Error: Invalid identifier: Height__c at line 5 column 13

2: Error: Student Compile Error: Incompatible types since an instance of SObject is never an instance of Student at line 12 column 19

 

 

for 1st error, i tried all the premitive data types, still that error is there.

I wanna call the standard 'EmailQuote()' method of quotes in my custom visualforce page. 

 

VF Page:

<apex:page standardController="quote" extensions="quoteSample">

<apex:form >
<apex:pageBlock >
    <apex:outputfield value="{!quote.Name}"/>
    <apex:commandButton action="{!EmailQuote}" value="Email"/>
    
    </apex:pageBlock>
</apex:form>

</apex:page>

 Class:

 

 

public with sharing class quoteSample {    
public quote q;        

public quoteSample(ApexPages.StandardController controller) {
    this.q = (quote)controller.getRecord();    }  

public pagereference EmailQuote(){
        EmailQuote();        
        PageReference newPage = New PageReference('get('id'));
newPage.setRedirect(true); return newPage; } }

 

Error:

 

Maximum stack depth reached: 1001

Error is in expression '{!EmailQuote}' in component <apex:page> in page quotesample

 

 

An unexpected error has occurred. Your development organization has been notified.