• Abc234
  • NEWBIE
  • 0 Points
  • Member since 2012

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

Apex Controller:
=====================

public with sharing class ApexButtonGetDist{
    public static Opportunity theOpportunity = new Opportunity();
    public static Opportunity theOpportunity2 = new Opportunity();
    public static Account getDistributor = new Account();
    
    public ApexButtonGetDist(ApexPages.StandardController stdController){
       theOpportunity = (Opportunity)stdController.getRecord();  
    }
    
    public PageReference doMyApexLogic() {
        theOpportunity2 = [SELECT ID, Name, Distributor_Name__c,Dist_street__c,Dist_City__c,Dist_State__c,Dist_PostalCode__c from Opportunity where Id = :theOpportunity.Id];
        getDistributor = [SELECT ID, Name, BillingStreet,BillingState,BillingCity,BillingPostalCode,SourceCode__c from Account where Id = :theOpportunity2.Distributor_Name__c];
        theOpportunity.Dist_street__c = getDistributor.BillingStreet;
      theOpportunity.Dist_City__c = getDistributor.BillingCity;
      theOpportunity.Dist_State__c = getDistributor.BillingState;
      theOpportunity.Dist_PostalCode__c = getDistributor.BillingPostalCode;        
      theOpportunity.Distr_SourceCode__c = getDistributor.SourceCode__c;        
        update theOpportunity;
        return new PageReference('/' + theOpportunity.ID);
    }
}

Test Class
@isTest
private class ApexButtonGetDistTest {
      
        static testmethod void testApexButtonGetDist(){
        
           Account acc = new Account (Name = 'test');
           
           insert acc;
            
           Opportunity opp = new Opportunity(Name = 'Test opp',
           StageName = 'Test Stage',
           CloseDate = date.today());
           insert opp;
           
        ApexPages.StandardController controller = new ApexPages.StandardController(opp);
        ApexButtonGetDist ABGD = new ApexButtonGetDist(controller);
        ABGD.doMyApexLogic();
       
       }           
}

The code Coverage is 53% So How do I increase the code coverage. The code below was not covered.

 theOpportunity.Dist_street__c = getDistributor.BillingStreet;
      theOpportunity.Dist_City__c = getDistributor.BillingCity;
      theOpportunity.Dist_State__c = getDistributor.BillingState;
      theOpportunity.Dist_PostalCode__c = getDistributor.BillingPostalCode;        
      theOpportunity.Distr_SourceCode__c = getDistributor.SourceCode__c;        
        update theOpportunity;
        return new PageReference('/' + theOpportunity.ID);
        
       

public class sendEmail{
    public Account account = new Account();
    public Account acct = new Account();
    public sendEmail(ApexPages.StandardController stdController) {
        account = (Account)stdController.getRecord();
        acct = [select id,name,billingstreet,billingcity,billingstate,billingpostalcode,phone, (select Contact.Name, Contact.Email FROM Account.Contacts) from Account where id = :account.id];
    }
    public String subject { get; set; }
    public String body { get; set; }
   public Account getAccount() {
        return account;
    }

    public PageReference send() {
        // Define the email
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

        String addresses = 'bharathvsfdc@gmail.com';
        String body2;
        String[] toAddresses = addresses.split(':', 0);
        body2 = 'Name: ' + acct.Name + '<br />';
        body2 += 'Address:<br />';
        body2 += '  Street    :  ' + acct.BillingStreet + 'br />';
        body2 += '  City      :  ' + acct.BillingCity + '<br />';
        body2 += '  State     :  ' + acct.BillingState + '<br />';
        body2 += '  PostalCode:  ' + acct.BillingPostalCode + '<br />';
        body2 += 'Telphone Number:  ' + acct.Phone + '<br /><br />';
        body2 += 'Contact Name:<br />  ';
        for (Integer i = 1; i < acct.Contacts.size(); i++)
        {
            body2 += '  ' + acct.Contacts[i].Name + '<br />';
        }

        // Sets the paramaters of the email
        email.setSubject( subject );
        email.setToAddresses( toAddresses );
        email.setPlainTextBody( body2 );
        email.setHtmlBody(body2);
       
        // Sends the email
        Messaging.SendEmailResult [] r =
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});  
       
        return new PageReference('/' + account.ID);
    }
}

 

How to write test class for this

Class :

public with sharing class ApexButtonGetDist{
    public static Opportunity theOpportunity = new Opportunity();
    public static Opportunity theOpportunity2 = new Opportunity();
    public static Account getDistributor = new Account();
   
    public ApexButtonGetDist(ApexPages.StandardController stdController){
        theOpportunity = (Opportunity)stdController.getRecord();  
    }
   
    public PageReference dologic() {
        theOpportunity2 = [SELECT ID, Name, customfiled__c from Opportunity where Id = :theOpportunity.Id];

        getDistributor = [SELECT ID, Name, BillingStreet,BillingState,BillingCity,BillingPostalCode from Account where Id = :theOpportunity2.customfiled__c];
        theOpportunity.customfiled1__c = getDistributor.BillingStreet;
        theOpportunity.customfiled2__c = getDistributor.BillingCity;
        theOpportunity.customfiled3__c= getDistributor.BillingState;
        theOpportunity.customfiled4__c = getDistributor.BillingPostalCode;       
        update theOpportunity;
        return new PageReference('/' + theOpportunity.ID);
    }
}

Test Class:

@isTest

private class ApexButtonGetDistTest {
      
        static testmethod void testApexButtonGetDist(){
        
        opportunity opps = new opportunity();
            
            Opportunity opp = new Opportunity();
            opp.Name = 'Test opp';
            opp.StageName = 'Test Stage';
            opp.CloseDate = date.today();
            insert opp;
            
            PageReference pr = new PageReference(opp.ID);
            Test.setCurrentPage(pr);
            
            ApexPages.StandardController controller = new ApexPages.StandardController(opps); 
            
            Test.startTest();
            
            ApexButtonGetDist ABG = new ApexButtonGetDist(controller);
            
            Test.stopTest();
 
           
            
 
 
        
        }           
}

Hi All,

 

I am getting Attempt to de-reference a null object while opening visual force template.

 

Here is the code:

 


Template Code :
======================

<messaging:emailTemplate subject="New Template" recipientType="User" relatedToType="Custom__object__c">
    <messaging:plainTextEmailBody >
      <c:Test_EmailTemplatecomponent AccId="{!relatedTo.ID}"/>   
    </messaging:plainTextEmailBody>
</messaging:emailTemplate>


Component :
===============

<apex:component controller="Test_EmailTemplatecontroller" access="global">
     <apex:attribute name="AccId" description="My Account ID." type="String" required="required" assignTo="{!accountId}"/>
     <h1>Congratulations</h1>
     <p>{!accountName}</p>
</apex:component>

Controller:
=============

public without sharing class Test_EmailTemplatecontroller
{
     private String cAccountId;
     private Custom__object__c cAccount;

     public String getAccountId()
     {
System.debug('####################Account ID : ' + cAccountId);
          return cAccountId;
     }

     public void setAccountId(String id)
     {
System.debug('###################################### id: ' + id);
          cAccountId = id;
          initializeAccount();
     }

     public String getAccountName()
     {
System.debug('#####################################name: ' + cAccount.Name);
          return cAccount.Name;
     }

     private void initializeAccount()
     {
System.debug('################################initializeAccount');
          if(cAccountId != null) {
               Custom__object__c cAccount = [SELECT Name, Id FROM Custom__object__c WHERE ID = :cAccountId];
          }
     }
}

                 
>> I am not getting any error When I comment out getAccountName method but I want to dispay the account name here

 

 Can any one help me to how to resolve this?

 

Thanks,
                

 

  • April 13, 2013
  • Like
  • 0

We are trying to find ways to track adoption/usage of our application on force.com. Is there anyway to access frequency of access of custom objects by user?

 

Thanks in advance

  • March 15, 2013
  • Like
  • 0

I pass Opportunity object and opportunity field set. 

public static List<Schema.FieldSetMember> readFieldSet(String fieldSetName, String ObjectName) 
{ 

Map<String, Schema.SObjectType> GlobalDescribeMap = Schema.getGlobalDescribe(); 
Schema.SObjectType SObjectTypeObj = GlobalDescribeMap.get(ObjectName); 
Schema.DescribeSObjectResult DescribeSObjectResultObj = SObjectTypeObj.getDescribe(); 

//system.debug('====>' + DescribeSObjectResultObj.FieldSets.getMap().get(fieldSetName)); 

Schema.FieldSet fieldSetObj = DescribeSObjectResultObj.FieldSets.getMap().get(fieldSetName); 

//List<Schema.FieldSetMember> fieldSetMemberList = fieldSetObj.getFields(); 
//system.debug('fieldSetMemberList ====>' + fieldSetMemberList); 
return fieldSetObj.getFields(); 
}

  • January 30, 2013
  • Like
  • 0

Hi All,

 

 

whether or not emails sent from an Apex class are routed according to our email relay settings or do they bypass the relay settings and go to the recipient directly from Salesforce?

 

Any help is appriciated..

 

Thanks & Regards,

Bharath

 

 

  • November 19, 2012
  • Like
  • 0

Hi,

 

I need to display selected picklist values that are selected in record type in visualforce, Can anyone help me how to achieve this,

 

For example,

 

I have to record types RT1(Indian citizen),RT2(US citizen) and one picklist filed in my custom object named State__c

 

so I have selected states AP,UP,DELHI like for RT1 record type and new york,new jersey,etc for RT2 record type

 

So my requirement is,

 

if I select RT1 record type in VF Page, state__c picklist should show only related states in india that I already selected for that record type(RT1)

 

If I select RT2 record type in Vf page, state__c picklist should show only related states in US that I already selected for that record type(RT2)

 

(OR) Is there any other way like directly redirecting to pagelayouts in VF page

 

Any helpappericiated 

Thanks & Regards,

Bharath

 

  • October 15, 2012
  • Like
  • 0

pageReference pr = new pageReference('/apex/Homepage?uid ='+ listusers[0].id);

pr.setredirect(true);

return pr;

when i use above code am getting error

 

LoginController Compile Error: line 37:81 no viable alternative at character '' at line 37 column 81

 

 So i tried with getparameters still am getting run time error

 

PageReference pr= page.Homepage;
pr.getParameters().put('id',listusers[0].id);

pr.setredirect(true);

return pr;

 

Visualforce Error

Id value a099000000AWn0l is not valid for the Movie__c standard controller

 

How to use ID that i passed through getparameters, in Movie page

 

I just need to display like hello Name

 

Can anyone help me in this

  • September 28, 2012
  • Like
  • 0

pageReference pr = new pageReference('/apex/Homepage?uid ='+ listusers[0].id);

pr.setredirect(true);

return pr;

when i use above code am getting error

 

LoginController Compile Error: line 37:81 no viable alternative at character '' at line 37 column 81

 

 So i tried with getparameters still am getting run time error

 

PageReference pr= page.Homepage;
pr.getParameters().put('id',listusers[0].id);

pr.setredirect(true);

return pr;

 

Visualforce Error

Id value a099000000AWn0l is not valid for the Movie__c standard controller

 

How to use ID that i passed through getparameters, in Movie page

 

I just need to display like hello Name

 

Can anyone help me in this

  • September 28, 2012
  • Like
  • 0

Hi,

 

i have created one login page,So i used below code to redirect my homepage once user credentials match

 

PageReference pr= page.Homepage;
              pr.getParameters().put('id',listusers[0].id);
              pr.setRedirect(true);
              return pr;

 

But my question is,how to use the id that i pass in this page in home page

 

So in my home page i need to display like Hi rahul

 

Can anyone help me how to do this

  • September 27, 2012
  • Like
  • 0

Hi All,

 

I have 2 custom objects called Login_page__c and Candidate__c

 

when I click  on Newuser button in Login_page__c that is created in if page, then it should redirected to Candidate edit page for creating new candidate 

 

Thanks & Regards,

Bharath

Hi,

 

i am new to salesforce.

 

i have an doubt how to add values to the nested list

 i have declared a nested list(as below) then i need to add values to that nested

List<List<Integer>> my_list_2 = new List<List<Integer>>();

Regards,

Bharath

i have filed named PAN CARD with length 10, so i need to validate that filed with below requirment

 

1st 5 characters should be alphabets, next 4 characters are numbes and 10 place should be alphabet

 

for  example :

 

AIEPV4202F

 


public class sendEmail{
    public Account account = new Account();
    public Account acct = new Account();
    public sendEmail(ApexPages.StandardController stdController) {
        account = (Account)stdController.getRecord();
        acct = [select id,name,billingstreet,billingcity,billingstate,billingpostalcode,phone, (select Contact.Name, Contact.Email FROM Account.Contacts) from Account where id = :account.id];
    }
    public String subject { get; set; }
    public String body { get; set; }
   public Account getAccount() {
        return account;
    }

    public PageReference send() {
        // Define the email
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

        String addresses = 'bharathvsfdc@gmail.com';
        String body2;
        String[] toAddresses = addresses.split(':', 0);
        body2 = 'Name: ' + acct.Name + '<br />';
        body2 += 'Address:<br />';
        body2 += '  Street    :  ' + acct.BillingStreet + 'br />';
        body2 += '  City      :  ' + acct.BillingCity + '<br />';
        body2 += '  State     :  ' + acct.BillingState + '<br />';
        body2 += '  PostalCode:  ' + acct.BillingPostalCode + '<br />';
        body2 += 'Telphone Number:  ' + acct.Phone + '<br /><br />';
        body2 += 'Contact Name:<br />  ';
        for (Integer i = 1; i < acct.Contacts.size(); i++)
        {
            body2 += '  ' + acct.Contacts[i].Name + '<br />';
        }

        // Sets the paramaters of the email
        email.setSubject( subject );
        email.setToAddresses( toAddresses );
        email.setPlainTextBody( body2 );
        email.setHtmlBody(body2);
       
        // Sends the email
        Messaging.SendEmailResult [] r =
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});  
       
        return new PageReference('/' + account.ID);
    }
}

 

How to write test class for this

Class :

public with sharing class ApexButtonGetDist{
    public static Opportunity theOpportunity = new Opportunity();
    public static Opportunity theOpportunity2 = new Opportunity();
    public static Account getDistributor = new Account();
   
    public ApexButtonGetDist(ApexPages.StandardController stdController){
        theOpportunity = (Opportunity)stdController.getRecord();  
    }
   
    public PageReference dologic() {
        theOpportunity2 = [SELECT ID, Name, customfiled__c from Opportunity where Id = :theOpportunity.Id];

        getDistributor = [SELECT ID, Name, BillingStreet,BillingState,BillingCity,BillingPostalCode from Account where Id = :theOpportunity2.customfiled__c];
        theOpportunity.customfiled1__c = getDistributor.BillingStreet;
        theOpportunity.customfiled2__c = getDistributor.BillingCity;
        theOpportunity.customfiled3__c= getDistributor.BillingState;
        theOpportunity.customfiled4__c = getDistributor.BillingPostalCode;       
        update theOpportunity;
        return new PageReference('/' + theOpportunity.ID);
    }
}

Test Class:

@isTest

private class ApexButtonGetDistTest {
      
        static testmethod void testApexButtonGetDist(){
        
        opportunity opps = new opportunity();
            
            Opportunity opp = new Opportunity();
            opp.Name = 'Test opp';
            opp.StageName = 'Test Stage';
            opp.CloseDate = date.today();
            insert opp;
            
            PageReference pr = new PageReference(opp.ID);
            Test.setCurrentPage(pr);
            
            ApexPages.StandardController controller = new ApexPages.StandardController(opps); 
            
            Test.startTest();
            
            ApexButtonGetDist ABG = new ApexButtonGetDist(controller);
            
            Test.stopTest();
 
           
            
 
 
        
        }           
}

Hi All,

 

I am getting Attempt to de-reference a null object while opening visual force template.

 

Here is the code:

 


Template Code :
======================

<messaging:emailTemplate subject="New Template" recipientType="User" relatedToType="Custom__object__c">
    <messaging:plainTextEmailBody >
      <c:Test_EmailTemplatecomponent AccId="{!relatedTo.ID}"/>   
    </messaging:plainTextEmailBody>
</messaging:emailTemplate>


Component :
===============

<apex:component controller="Test_EmailTemplatecontroller" access="global">
     <apex:attribute name="AccId" description="My Account ID." type="String" required="required" assignTo="{!accountId}"/>
     <h1>Congratulations</h1>
     <p>{!accountName}</p>
</apex:component>

Controller:
=============

public without sharing class Test_EmailTemplatecontroller
{
     private String cAccountId;
     private Custom__object__c cAccount;

     public String getAccountId()
     {
System.debug('####################Account ID : ' + cAccountId);
          return cAccountId;
     }

     public void setAccountId(String id)
     {
System.debug('###################################### id: ' + id);
          cAccountId = id;
          initializeAccount();
     }

     public String getAccountName()
     {
System.debug('#####################################name: ' + cAccount.Name);
          return cAccount.Name;
     }

     private void initializeAccount()
     {
System.debug('################################initializeAccount');
          if(cAccountId != null) {
               Custom__object__c cAccount = [SELECT Name, Id FROM Custom__object__c WHERE ID = :cAccountId];
          }
     }
}

                 
>> I am not getting any error When I comment out getAccountName method but I want to dispay the account name here

 

 Can any one help me to how to resolve this?

 

Thanks,
                

 

  • April 13, 2013
  • Like
  • 0

I pass Opportunity object and opportunity field set. 

public static List<Schema.FieldSetMember> readFieldSet(String fieldSetName, String ObjectName) 
{ 

Map<String, Schema.SObjectType> GlobalDescribeMap = Schema.getGlobalDescribe(); 
Schema.SObjectType SObjectTypeObj = GlobalDescribeMap.get(ObjectName); 
Schema.DescribeSObjectResult DescribeSObjectResultObj = SObjectTypeObj.getDescribe(); 

//system.debug('====>' + DescribeSObjectResultObj.FieldSets.getMap().get(fieldSetName)); 

Schema.FieldSet fieldSetObj = DescribeSObjectResultObj.FieldSets.getMap().get(fieldSetName); 

//List<Schema.FieldSetMember> fieldSetMemberList = fieldSetObj.getFields(); 
//system.debug('fieldSetMemberList ====>' + fieldSetMemberList); 
return fieldSetObj.getFields(); 
}

  • January 30, 2013
  • Like
  • 0

pageReference pr = new pageReference('/apex/Homepage?uid ='+ listusers[0].id);

pr.setredirect(true);

return pr;

when i use above code am getting error

 

LoginController Compile Error: line 37:81 no viable alternative at character '' at line 37 column 81

 

 So i tried with getparameters still am getting run time error

 

PageReference pr= page.Homepage;
pr.getParameters().put('id',listusers[0].id);

pr.setredirect(true);

return pr;

 

Visualforce Error

Id value a099000000AWn0l is not valid for the Movie__c standard controller

 

How to use ID that i passed through getparameters, in Movie page

 

I just need to display like hello Name

 

Can anyone help me in this

  • September 28, 2012
  • Like
  • 0

Hi,

Can any one help me how to validate password should contain atleast one numeric, 1 alpha numeric and 1 special charaters

 

Thanks & Regards,

Bharath

Hi,

 

i am trying to validate the credintials but its giving error

Below is the my login controller let me know where i am wrong

 

 


public class LoginController {

public list<Candidate__c> listCandidates{get;set;}
    public string searchString {get;set;}
    public boolean showmsg{get;set;}
    public LoginController(ApexPages.StandardController controller)
    {
        listCandidates=new list<Candidate__c>();
        showmsg=false;
    }
    public pagereference ValidateUserName()
    {
        String AccountQuery = 'select UserName__c, PassWord__c from Candidate__c';
        
        if(searchString != '' && searchString != null)
            AccountQuery = AccountQuery +
            ' where name  =: ' + 'searchString' ;

 

so when i tried to login,i am getting below error i have entered user name as 'jakson'

 

System.QueryException: Variable does not exist: jakson

 

Error is in expression '{!ValidateUserName}' in component <apex:page> in page candidate_login_page

 

 

Class.LoginController.ValidateUserName: line 18, column 1          

 

 

Can anyone help me in this issue,

Thanks & Regards,

Bharath

please tell me about Encrypted Fields in brief? thanks in advanced.?

Hi,

 

i am new to salesforce.

 

i have an doubt how to add values to the nested list

 i have declared a nested list(as below) then i need to add values to that nested

List<List<Integer>> my_list_2 = new List<List<Integer>>();

Regards,

Bharath

i have filed named PAN CARD with length 10, so i need to validate that filed with below requirment

 

1st 5 characters should be alphabets, next 4 characters are numbes and 10 place should be alphabet

 

for  example :

 

AIEPV4202F

 


Hi,I

 

am getting the below error when trying to extract data through Command line.

 

There are only 3800 records.

 

The export is succesful when i extract using Dataloader tool.

 

Giving me the below error when trying to do it from Command line.


"java.lang.OutOfMemoryError: Java heap space"


Any help is much appriciated.

 

Thankyou,

Anna.