• Amarjeet
  • NEWBIE
  • 50 Points
  • Member since 2016
  • Developer
  • Freelance

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 9
    Replies
Unable to cover highlighted part of the code in the test class.

List<Messaging.SendEmailResult> results =  Messaging.sendEmail(
                                                       new List<Messaging.SingleEmailMessage> {singleEmailMsg});

              if (results[0].success) {
           
                Date d = System.today();
                .....................
                 
                String myDate = myDT.format('yyyy-MM-dd');
                Attachment a = new Attachment(parentId = Order.id, name=myDate+'|'+dTime+' '+Order.Name +' '+ 'Body Email', body = Blob.valueof(emailBody));
                insert a;
                PageReference pgRef = new PageReference('/' + Order.Id);
                pgRef.setRedirect(true);
                return pgRef;
           
            } else {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Error sending Email Message. Details = ' + results.get(0).getErrors()[0].getMessage()));
                return null;
            }
I need to convert hyperlink formula field to text field?
Changed datatype from text to textarea of a field, migration to PROD-failed due to existing data? How to mitigate this without doing that manually?
Hello all,

how to migrate sharing setting , object level setting and field level setting from one org to another or we need to set that all manually after deployment? Please give some suggestion .

Thanks all in advance.
How to make one checkbox field to false on the result of another checkbox field to true and vice versa. Either of two will remain checked.

How to do that with out code?
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, OrderTrigger: execution of AfterUpdate

caused by: System.NullPointerException: Attempt to de-reference a null object

Class.StatusUpdate.Progress: line 25, column 1
Class.OrderTriggerHandler.afterUpdate: line 57, column 1
Class.TriggerHandler.run: line 47, column 1
Trigger.OrderTrigger: line 91, column 1: []


I am getting this error for my test class fail.
Hey ,I am using future method in one apex class which is used to calaculate and update some field value. But, I am getting the value updated after few secand/ few refresh. What can be the solution for this to update the field in the excat time without removing the future method?

Thanks in advance
User-added image

I am getting the above error. My requirement is to change the currency field data, if opportunity already having child quote records. So its not possible through standard . Thus I am working out for custom solution. Earlier its was working on clicking cancel it use to create clonned opportunity but now its not working now on create and on cancel both.

Apex:-


public with sharing class CloneOpportunityExtension {
    //to get opp id from url
    public String recId {get;set;}
    // for new currency and name
    public Opportunity cloneOpp {get;set;}
    
    public CloneOpportunityExtension(ApexPages.StandardController stdCon) {
        cloneOpp = new Opportunity();
        recId = null;
        recId = ApexPages.currentPage().getParameters().get('id'); 
        System.debug('recId'+recId);
        if(recId!=null) {
            // setting the currency on page load
            cloneOpp.CurrencyIsoCode = ((opportunity)stdCon.getRecord()).CurrencyIsoCode;
            // setting Name
            cloneOpp.Name = ((opportunity)stdCon.getRecord()).Name;
            

//setting Account Name
// cloneOpp.Account= ((opportunity)stdCon.getRecord()).Account;
        } else {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, ' '+Label.select_a_vaild_Opportunity));
        }
    }
   
    /**
    * to save the Clone Opportunity with New Currency
    * 
    */
    public PageReference saveNewOpp(){   
        PageReference pRef = null;
        if(recId!=null) {
            if(cloneOpp!=null) {
                try{
                    // calling clone class
                    String returnId = null;
                    returnId = Cls_CloneOptyRelated.CloneOpportunity(recId, cloneOpp.CurrencyIsoCode, cloneOpp.Name);
                    if(returnId!=null) {
                        pRef = new PageReference('/'+returnId);
                        pRef.setRedirect(true);
                    }
                    else {
                       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, ' '+Label.Issue_in_Cloning));
                    }
                }
                catch(Exception e) {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, ' ' + Label.Issue_in_Cloning + ' ' + e.getMessage()));
                }
            }
        }
        return pRef;
    }
}


Visualforce Page:-

<apex:page standardController="Opportunity" extensions="CloneOpportunityExtension" tabStyle="Opportunity" title="{!$ObjectType.Opportunity.Label} {!$Label.Clone}">
<apex:sectionHeader subtitle="{!Opportunity.Name}" title="{!Opportunity.Name} {!$Label.Clone}" rendered="{!recId != null}"/>
<apex:form >
<apex:pageMessages >
</apex:pageMessages>
<apex:pageBlock title="{!$ObjectType.Opportunity.Label} {!$Label.Clone}">
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!saveNewOpp}" value="{!$Label.Clone}" rendered="{!recId != null}"/>
<apex:commandButton action="{!cancel}" value="{!$Label.Cancel}" rendered="{!recId != null}"/>
<apex:outputPanel rendered="{!recId == null}"> <input type="button" name="{!$Label.Back}" value="{!$Label.Back}" class="btn" onclick="window.top.location='/006/o';"/>
</apex:outputPanel>
</apex:pageBlockButtons>
<apex:pageBlockSection columns="1">
<apex:inputField value="{!cloneOpp.Name}" label="{!$ObjectType.Opportunity.fields.Name.Label}"/>
<apex:inputField value="{!cloneOpp.CurrencyIsoCode}" label="{!$ObjectType.Opportunity.fields.CurrencyIsoCode.Label}"/>
<!--- <apex:inputField value="{!cloneOpp.Account.Name}" label="{!$ObjectType.Opportunity.fields.Account.Name.Label}"/> ----> </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Test Result Detail 
Time Started1/2/2018 12:15 AM
Classaccsearchcontrollertest
Method NameTestclear
Pass/FailFail
Error MessageSystem.NullPointerException: Attempt to de-reference a null object
Stack TraceClass.accsearchController.clear: line 25, column 1
Class.accsearchcontrollertest.Testclear: line 49, column 1


Apex Test Class:-

@isTest 
public class accsearchcontrollertest
{
    @testSetup static void createTestData()
      {

        Account acc= new Account();
        acc.Name='TestAccount';
        acc.Is_Acct_IP_or_RP__c='IP';
        acc.Buying_Groups__c='N/A (none)';
        insert acc;

        Opportunity op = new Opportunity ();
        op.Name = 'Test' ;
        op.Accountid= acc.Id;
        op.StageName='A = Market Participant';
        op.CloseDate= System.today() + 5;
        insert op;

        Quote qt = new Quote();
        qt.Name = 'Test123';
        qt.CBG_Employee_Responsible__c = UserInfo.getUserId();
        qt.CBG_Incoterms__c = 'CFR';
        qt.CBG_PaymentTerms__c = 'CO04 payable immediatly';
        qt.Format__c = 'List';
        qt.CBG_SAPQuoteNumber__c = '30010012';
        qt.OpportunityId=op.id; 
        insert qt;

      }
      
    static TestMethod void TestprocessLinkClick()
      {
      
        PageReference pref1 = Page.CBG_SearchQuote ;   
        Test.setCurrentPage(pref1);   
        accsearchcontroller Obj = new accsearchcontroller();
        Obj.searchstring = '30010012';  
        //Obj.clear();
        Obj.processLinkClick();
        
      }   
    static TestMethod void Testclear()//////////////////////////////////This one failing---->How to pass value to search string
      {
      
        
        accsearchcontroller Obj = new accsearchcontroller();
        Obj.searchstring = '30010012';  
        Obj.clear();  
             
     }  

   static TestMethod void Testsearch()
      {
      
        accsearchcontroller Obj = new accsearchcontroller();
        Obj.search();
        
      }  
    
}


Apex Class:-

public with sharing class accsearchController 
{

    public accsearchcontroller(ApexPages.StandardController controller) {

    }


public String l { get; set; }
public list <quote> acc {get;set;}
public string searchstring {get;set;}
public String quoteid{get; set;}
public Boolean search{get; set;}
public Boolean result{get; set;}
public accsearchcontroller( ) 
{
}
public void search(){
string searchquery='select QuoteNumber,Name,Email,Opportunity.Name,CBG_SAPQuoteNumber__c ,CBG_Phoenix_Offer_Number__c from quote where CBG_SAPQuoteNumber__c like \'%'+searchstring+'%\' OR CBG_SAPQuoteNumber__c like \'*'+searchstring+'*\' OR  CBG_Phoenix_Offer_Number__c like \'%'+searchstring+'%\' OR  CBG_Phoenix_Offer_Number__c  like \'*'+searchstring+'*\' Limit 20';
acc= Database.query(searchquery);
}
public void clear(){
acc.clear();

}
public PageReference processLinkClick() {
         
        search = false;
        result = false;
        
        Pagereference p1 = new PageReference('https://cs84.salesforce.com/'+quoteid);
        p1.setRedirect(true);
        return p1;
    }
}
I  want to make the column of pageblocktable dragable to adjust the size of column. Code below is working:--

<apex:page standardController="Account" tabStyle="Account" recordSetVar="accounts">
<apex:includeScript value="//cdn.jsdelivr.net/jquery/1.7/jquery.min.js"/>
<apex:includeScript value="//cdn.jsdelivr.net/jquery.colresizable/1.3/colResizable.min.js"/>
<apex:sectionHeader title="colResizable" subtitle="Resize columns"/>
<apex:form >
<apex:pageBlock title="Accounts" mode="edit">
<apex:pageBlockTable id="tbl" value="{!accounts}" var="Con"> <apex:column value="{!Con.Name}" >
<apex:facet name="header">Name</apex:facet>
</apex:column>
<apex:column value="{!Con.Industry}"/>
<apex:column value="{!Con.Type}"/>
<apex:column value="{!Con.Phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
<script type="text/javascript">
var j= $("[id$=tbl]").colResizable({ liveDrag: true, draggingClass: "dragging" });
</script>
</apex:page>


But how to apply same logic here . You can see the below code is different and complex unlike the above one . Please help:--

<apex:pageBlock id="PLPageBlock" title="{!$Label.Main_Title}">
<apex:pageMessages id="errorMessages"></apex:pageMessages>
<div id="plitablediv" style="flex-direction: column; overflow-x:scroll; max-height: 300px;">
<apex:pageBlockTable id="p" value="{!productLines}" var="pl" onRowClick="fixInlineEditBug(); productLineSelected(this);">
<apex:column style="width:1%;" >
<apex:facet name="header">
</apex:facet>
<span style="display:none;" id="plid">{!pl.ident}</span> </apex:column> <apex:column styleClass="{!IF((LEN(pl.ident) < 10), 'highlightedRow', '')}">
<apex:commandLink rendered="{!pl.item.Id != null}" value="Detail" onclick="window.open('/{!pl.item.Id}'); return false;" /> <br /> <apex:commandLink value="{!$Label.Delete_Item}" onclick="if(confirm('{!$Label.Delete_Confirmation}')){delProductLine('{!pl.ident}');} return false;" />
<apex:facet name="header">{!$Label.Action}</apex:facet>
</apex:column>
<apex:column id="d" styleClass="{!IF((LEN(pl.ident) < 10), 'highlightedRow', '')}"> <div id="draggable1" class="ui-widget-content"> <p>Drag me around 1</p> </div>
<apex:facet name="header">Satya </apex:facet> <span style="display:none;" id="plid">{!pl.ident}</span>
</apex:column>
<apex:column styleClass="{!IF((LEN(pl.ident) < 10), 'highlightedRow', '')}">
<apex:outputField value="{!pl.item.CBG_ItemLine__c}" rendered="{!!massEdit}"/>
<apex:inputField value="{!pl.item.CBG_ItemLine__c}" rendered="{!massEdit}" onkeypress="return fireSave(event);"/>
<apex:facet name="header">{!$ObjectType.ProductLineItem__c.fields.CBG_ItemLine__c.Label}</apex:facet>
</apex:column>
<apex:column styleClass="{!IF((LEN(pl.ident) < 10), 'highlightedRow', '')}">
<apex:outputField value="{!pl.item.RecordTypeId}" >
<apex:inlineEditSupport disabled="true"/>
</apex:outputField> <apex:facet name="header">{!$Label.Record_Type}</apex:facet>
</apex:column>
public with sharing class accsearchcontroller
  {
    public accsearchcontroller(ApexPages.StandardController controller) {     }   
  public String l { get; set; }
public list <quote> acc {get;set;}
public string searchstring {get;set;}
public String quoteid{get; set;}
public Boolean search{get; set;}
public Boolean result{get; set;}
public accsearchcontroller( )
  { }
public void search()
{ string searchquery='select QuoteNumber,Name,Email,Opportunity.Name,SAP_Reference_Number__c  from quote where SAP_Reference_Number__c like \'%'+searchstring+'%\' OR SAP_Reference_Number__c like \'*'+searchstring+'*\'  Limit 20'; acc= Database.query(searchquery);
}
public void clear()
{
acc.clear();
}
public PageReference processLinkClick()
 {                 
  search = false;    
    result = false;     
    //Pagereference p1 = new PageReference('https://ap7.salesforce.com/'+quoteid);     
  Pagereference p1 = new PageReference('https://swainswain-dev-ed.my.salesforce.com/'+quoteid);     
    p1.setRedirect(true);    
     return p1;    
 }
}
Integrating Google Adwords with salesforce for lead generation additionally to capture impresion and click per keywords by visitors.
Please help me out ,I will be helpfull.
We can implement web to lead code to capture lead from salesforce but additionally I need to fetch impression and click made by visitors using keywords.
I had created a web tab to redirect it to gmail page by giving the url but it is showing a blank page. plz help me 
how to implement functionality like gmail in a salesforce page ,where we will be able to see all incoming mails in a list and also be able to compose new mail to send from salesforce as a personal mail.
I want to see my contacts in linkdin within salesforce.....so how to integrate linkdn with salesforce 
I had created a web tab to redirect it to gmail page by giving the url but it is showing a blank page. plz help me 
How to make one checkbox field to false on the result of another checkbox field to true and vice versa. Either of two will remain checked.

How to do that with out code?
Hey ,I am using future method in one apex class which is used to calaculate and update some field value. But, I am getting the value updated after few secand/ few refresh. What can be the solution for this to update the field in the excat time without removing the future method?

Thanks in advance
User-added image

I am getting the above error. My requirement is to change the currency field data, if opportunity already having child quote records. So its not possible through standard . Thus I am working out for custom solution. Earlier its was working on clicking cancel it use to create clonned opportunity but now its not working now on create and on cancel both.

Apex:-


public with sharing class CloneOpportunityExtension {
    //to get opp id from url
    public String recId {get;set;}
    // for new currency and name
    public Opportunity cloneOpp {get;set;}
    
    public CloneOpportunityExtension(ApexPages.StandardController stdCon) {
        cloneOpp = new Opportunity();
        recId = null;
        recId = ApexPages.currentPage().getParameters().get('id'); 
        System.debug('recId'+recId);
        if(recId!=null) {
            // setting the currency on page load
            cloneOpp.CurrencyIsoCode = ((opportunity)stdCon.getRecord()).CurrencyIsoCode;
            // setting Name
            cloneOpp.Name = ((opportunity)stdCon.getRecord()).Name;
            

//setting Account Name
// cloneOpp.Account= ((opportunity)stdCon.getRecord()).Account;
        } else {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, ' '+Label.select_a_vaild_Opportunity));
        }
    }
   
    /**
    * to save the Clone Opportunity with New Currency
    * 
    */
    public PageReference saveNewOpp(){   
        PageReference pRef = null;
        if(recId!=null) {
            if(cloneOpp!=null) {
                try{
                    // calling clone class
                    String returnId = null;
                    returnId = Cls_CloneOptyRelated.CloneOpportunity(recId, cloneOpp.CurrencyIsoCode, cloneOpp.Name);
                    if(returnId!=null) {
                        pRef = new PageReference('/'+returnId);
                        pRef.setRedirect(true);
                    }
                    else {
                       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, ' '+Label.Issue_in_Cloning));
                    }
                }
                catch(Exception e) {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, ' ' + Label.Issue_in_Cloning + ' ' + e.getMessage()));
                }
            }
        }
        return pRef;
    }
}


Visualforce Page:-

<apex:page standardController="Opportunity" extensions="CloneOpportunityExtension" tabStyle="Opportunity" title="{!$ObjectType.Opportunity.Label} {!$Label.Clone}">
<apex:sectionHeader subtitle="{!Opportunity.Name}" title="{!Opportunity.Name} {!$Label.Clone}" rendered="{!recId != null}"/>
<apex:form >
<apex:pageMessages >
</apex:pageMessages>
<apex:pageBlock title="{!$ObjectType.Opportunity.Label} {!$Label.Clone}">
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!saveNewOpp}" value="{!$Label.Clone}" rendered="{!recId != null}"/>
<apex:commandButton action="{!cancel}" value="{!$Label.Cancel}" rendered="{!recId != null}"/>
<apex:outputPanel rendered="{!recId == null}"> <input type="button" name="{!$Label.Back}" value="{!$Label.Back}" class="btn" onclick="window.top.location='/006/o';"/>
</apex:outputPanel>
</apex:pageBlockButtons>
<apex:pageBlockSection columns="1">
<apex:inputField value="{!cloneOpp.Name}" label="{!$ObjectType.Opportunity.fields.Name.Label}"/>
<apex:inputField value="{!cloneOpp.CurrencyIsoCode}" label="{!$ObjectType.Opportunity.fields.CurrencyIsoCode.Label}"/>
<!--- <apex:inputField value="{!cloneOpp.Account.Name}" label="{!$ObjectType.Opportunity.fields.Account.Name.Label}"/> ----> </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Test Result Detail 
Time Started1/2/2018 12:15 AM
Classaccsearchcontrollertest
Method NameTestclear
Pass/FailFail
Error MessageSystem.NullPointerException: Attempt to de-reference a null object
Stack TraceClass.accsearchController.clear: line 25, column 1
Class.accsearchcontrollertest.Testclear: line 49, column 1


Apex Test Class:-

@isTest 
public class accsearchcontrollertest
{
    @testSetup static void createTestData()
      {

        Account acc= new Account();
        acc.Name='TestAccount';
        acc.Is_Acct_IP_or_RP__c='IP';
        acc.Buying_Groups__c='N/A (none)';
        insert acc;

        Opportunity op = new Opportunity ();
        op.Name = 'Test' ;
        op.Accountid= acc.Id;
        op.StageName='A = Market Participant';
        op.CloseDate= System.today() + 5;
        insert op;

        Quote qt = new Quote();
        qt.Name = 'Test123';
        qt.CBG_Employee_Responsible__c = UserInfo.getUserId();
        qt.CBG_Incoterms__c = 'CFR';
        qt.CBG_PaymentTerms__c = 'CO04 payable immediatly';
        qt.Format__c = 'List';
        qt.CBG_SAPQuoteNumber__c = '30010012';
        qt.OpportunityId=op.id; 
        insert qt;

      }
      
    static TestMethod void TestprocessLinkClick()
      {
      
        PageReference pref1 = Page.CBG_SearchQuote ;   
        Test.setCurrentPage(pref1);   
        accsearchcontroller Obj = new accsearchcontroller();
        Obj.searchstring = '30010012';  
        //Obj.clear();
        Obj.processLinkClick();
        
      }   
    static TestMethod void Testclear()//////////////////////////////////This one failing---->How to pass value to search string
      {
      
        
        accsearchcontroller Obj = new accsearchcontroller();
        Obj.searchstring = '30010012';  
        Obj.clear();  
             
     }  

   static TestMethod void Testsearch()
      {
      
        accsearchcontroller Obj = new accsearchcontroller();
        Obj.search();
        
      }  
    
}


Apex Class:-

public with sharing class accsearchController 
{

    public accsearchcontroller(ApexPages.StandardController controller) {

    }


public String l { get; set; }
public list <quote> acc {get;set;}
public string searchstring {get;set;}
public String quoteid{get; set;}
public Boolean search{get; set;}
public Boolean result{get; set;}
public accsearchcontroller( ) 
{
}
public void search(){
string searchquery='select QuoteNumber,Name,Email,Opportunity.Name,CBG_SAPQuoteNumber__c ,CBG_Phoenix_Offer_Number__c from quote where CBG_SAPQuoteNumber__c like \'%'+searchstring+'%\' OR CBG_SAPQuoteNumber__c like \'*'+searchstring+'*\' OR  CBG_Phoenix_Offer_Number__c like \'%'+searchstring+'%\' OR  CBG_Phoenix_Offer_Number__c  like \'*'+searchstring+'*\' Limit 20';
acc= Database.query(searchquery);
}
public void clear(){
acc.clear();

}
public PageReference processLinkClick() {
         
        search = false;
        result = false;
        
        Pagereference p1 = new PageReference('https://cs84.salesforce.com/'+quoteid);
        p1.setRedirect(true);
        return p1;
    }
}
public with sharing class accsearchcontroller
  {
    public accsearchcontroller(ApexPages.StandardController controller) {     }   
  public String l { get; set; }
public list <quote> acc {get;set;}
public string searchstring {get;set;}
public String quoteid{get; set;}
public Boolean search{get; set;}
public Boolean result{get; set;}
public accsearchcontroller( )
  { }
public void search()
{ string searchquery='select QuoteNumber,Name,Email,Opportunity.Name,SAP_Reference_Number__c  from quote where SAP_Reference_Number__c like \'%'+searchstring+'%\' OR SAP_Reference_Number__c like \'*'+searchstring+'*\'  Limit 20'; acc= Database.query(searchquery);
}
public void clear()
{
acc.clear();
}
public PageReference processLinkClick()
 {                 
  search = false;    
    result = false;     
    //Pagereference p1 = new PageReference('https://ap7.salesforce.com/'+quoteid);     
  Pagereference p1 = new PageReference('https://swainswain-dev-ed.my.salesforce.com/'+quoteid);     
    p1.setRedirect(true);    
     return p1;    
 }
}
I had created a web tab to redirect it to gmail page by giving the url but it is showing a blank page. plz help me 
Hello,

I want the Opportunity stage to update to the "Proposal/Price Quote Sent" picklist value when a quote is emailed. I was not successful at creating a workflow rule and field update and the user forum indicated this is only possible through an apex trigger. If this is correct, can someone provide me the code or other suggestions?

Thanks

Steve