• Tushar Tyagi 4
  • NEWBIE
  • 85 Points
  • Member since 2017

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies
Hi team,
I want to create a Vf page for below requirment
I am crating a button on Account Object When Click on the button then open the Vf page of the Related contact with Account.
I am Facing problem In pagination ,sorting Name column and open each contact.
Reguirment:-
ABC Firm wants to view all the contacts against an account in a custom UI where
10 records are displayed at a time and user has ability to paginate over all
records. User should have ability to sort records in asc/desc order on Name as
needed.
Requirement Details
 Create a custom button on Account andu.
 Connect developed VF Page with the Account custom button
 VF Page should have capability of pagination
 VF Page should have ability of sorting Name column
 While sorting a loading image should be displayed for user to wait till
operation completes.
 VF Page should display – Name, Birthdate, Lead Source, Email, Phone
 You are free to decide on Pages Look and Feel
 Adhere to salesforce best practices.
 Create test class to ensure developed code can be deployed; adhere to
best practices of testing framework.
<apex:page standardController="Account" sidebar="false" >
    <apex:form >

        <apex:pageBlock title="Contacts List" id="contacts_list">
    
            
            <apex:pageBlockTable value="{! Account.contacts }" var="ct">
                
            
                
            <apex:column value="{!ct.Name}"/>
                <apex:column value="{!ct.Birthdate}"/>
                <apex:column value="{!ct.Phone}"/>
                <apex:column value="{!ct.Email}"/>
                 <apex:column value="{!ct.LeadSource}"/>
            </apex:pageBlockTable>
          

            
           
        </apex:pageBlock>

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

 
  • August 23, 2017
  • Like
  • 0
Hi all,

I'm a newbie in Apex and I have a doubt which is bugging me.
 
While acquiring Id of a particular record of an object, why do I have to create sObject (if I'm not wrong) and not create a variable of type ID?
 
Further details:

The following works correctly and gives me the Account Id.
Account acct = [Select Id from Account where Name='Test'];
System.debug('ID: '+acct.Id);
 
But the following throws an error.
ID id = [Select Id from Account where Name='Test'];
System.debug('ID: '+id);

Why so??

Please help and any additional information will be greatly appreciated.

Thanks guys!
Hey, team, 
I m Facing issue with the below mentioned Bold point.
Please help.


• Create a custom checkbox field on Account and name it ‘Create Contact?’
• Create a number field on Account and name it as ‘No. Of Contacts to create’.
• Create an autonumber field on Account name it as “Account Number”.
• Create a custom number field on Contact and name it as “Contact Count”.
• Each time an account record is saved with checkbox marked as true; with a given number value, that many contact records should be created with following actions
o LastName = Account Number - Contact Count
o FirstName = Account Name
o Phone = Phone
o Billing Address = Billing Address
o Shipping Address = Shipping Address
o Contact Count = which number of contact this is with respect to Account. So for example Account ‘Acme’ already had 5 Contacts and you are creating 6th Contact it should say Contact Count as 6th, 7th etc.
public class AccountAutomation 
{

    public void contactHandler(List<Account> AccList)
    {
    try{
    List<Contact> ConList = new List<Contact>();
    map<id,decimal> AccMap=new map<id,decimal>(); 
       
        for(Account Acc : AccList)
        {
            if(Acc.Create_Contact__c == true)
            {
                
            	AccMAp.put(Acc.id, Acc.No_Of_Contacts_to_create__c);
             	if(Accmap.size()>0 && Accmap!=Null)
                {
                    for(ID AccID : AccMap.keySet())
                    {
                       for(integer i = 0;i<AccMap.get(Accid);i++) 
                       {
                           Contact Con = new Contact();
                           Con.accountId         = Accid;
                           Con.LastName          = Acc.Account_Number__c + '-' + con.Contact_Count__c;
                           Con.FirstName                     = Acc.Name;
                           Con.Phone	                        = Acc.Phone;
                           con.MailingStreet                 =acc.BillingStreet;
               			   con.MailingCity             =acc.BillingCity;
                		   con.MailingState           =acc.BillingState;
                		   con.MailingPostalCode =acc.BillingPostalCode;
                		   con.MailingCountry       =acc.BillingCountry;
                          
                           ConList.add(Con);
                       }
              
                    }
                }
                if(ConList.Size()>0 && ConList!=Null)
                insert ConList;
                
                
            }
        }
        
    }
         catch (Exception e)
        {
            system.debug('An Exception has occured = '+e);
        }

}
}

 

An internal server error has occurred
An error has occurred while processing your request. The salesforce.com support team has been notified of the problem. If you believe you have additional information that may be of help in reproducing or correcting the error, please contact Salesforce Support. Please indicate the URL of the page you were requesting, any error id shown on this page as well as any other related information. We apologize for the inconvenience. 

Thank you again for your patience and assistance. And thanks for using salesforce.com! 

Error ID: 640199601-8566 (-1664635790)



 
trigger TriggerUpdateSalesRep on Account (before insert, Before Update)
{
	Set<ID> SetAccOwner = new Set<ID>();
    for(Account Acc : Trigger.new)
    {
        setAccOwner.add(Acc.OwnerID);
    }
    map<Id,User>User_Map = New Map<Id,User>('select Name from User where id in:setAccOwner');
	for(Account acc:Trigger.new)
         {
          User usr = User_Map.get(Acc.OwnerId);
             Acc.Sales_Rep__c=usr.name;
         }
    
    
}

 
Hi team,
I want to create a Vf page for below requirment
I am crating a button on Account Object When Click on the button then open the Vf page of the Related contact with Account.
I am Facing problem In pagination ,sorting Name column and open each contact.
Reguirment:-
ABC Firm wants to view all the contacts against an account in a custom UI where
10 records are displayed at a time and user has ability to paginate over all
records. User should have ability to sort records in asc/desc order on Name as
needed.
Requirement Details
 Create a custom button on Account andu.
 Connect developed VF Page with the Account custom button
 VF Page should have capability of pagination
 VF Page should have ability of sorting Name column
 While sorting a loading image should be displayed for user to wait till
operation completes.
 VF Page should display – Name, Birthdate, Lead Source, Email, Phone
 You are free to decide on Pages Look and Feel
 Adhere to salesforce best practices.
 Create test class to ensure developed code can be deployed; adhere to
best practices of testing framework.
<apex:page standardController="Account" sidebar="false" >
    <apex:form >

        <apex:pageBlock title="Contacts List" id="contacts_list">
    
            
            <apex:pageBlockTable value="{! Account.contacts }" var="ct">
                
            
                
            <apex:column value="{!ct.Name}"/>
                <apex:column value="{!ct.Birthdate}"/>
                <apex:column value="{!ct.Phone}"/>
                <apex:column value="{!ct.Email}"/>
                 <apex:column value="{!ct.LeadSource}"/>
            </apex:pageBlockTable>
          

            
           
        </apex:pageBlock>

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

 
  • August 23, 2017
  • Like
  • 0
Hi all,

I'm a newbie in Apex and I have a doubt which is bugging me.
 
While acquiring Id of a particular record of an object, why do I have to create sObject (if I'm not wrong) and not create a variable of type ID?
 
Further details:

The following works correctly and gives me the Account Id.
Account acct = [Select Id from Account where Name='Test'];
System.debug('ID: '+acct.Id);
 
But the following throws an error.
ID id = [Select Id from Account where Name='Test'];
System.debug('ID: '+id);

Why so??

Please help and any additional information will be greatly appreciated.

Thanks guys!
Hey, team, 
I m Facing issue with the below mentioned Bold point.
Please help.


• Create a custom checkbox field on Account and name it ‘Create Contact?’
• Create a number field on Account and name it as ‘No. Of Contacts to create’.
• Create an autonumber field on Account name it as “Account Number”.
• Create a custom number field on Contact and name it as “Contact Count”.
• Each time an account record is saved with checkbox marked as true; with a given number value, that many contact records should be created with following actions
o LastName = Account Number - Contact Count
o FirstName = Account Name
o Phone = Phone
o Billing Address = Billing Address
o Shipping Address = Shipping Address
o Contact Count = which number of contact this is with respect to Account. So for example Account ‘Acme’ already had 5 Contacts and you are creating 6th Contact it should say Contact Count as 6th, 7th etc.
public class AccountAutomation 
{

    public void contactHandler(List<Account> AccList)
    {
    try{
    List<Contact> ConList = new List<Contact>();
    map<id,decimal> AccMap=new map<id,decimal>(); 
       
        for(Account Acc : AccList)
        {
            if(Acc.Create_Contact__c == true)
            {
                
            	AccMAp.put(Acc.id, Acc.No_Of_Contacts_to_create__c);
             	if(Accmap.size()>0 && Accmap!=Null)
                {
                    for(ID AccID : AccMap.keySet())
                    {
                       for(integer i = 0;i<AccMap.get(Accid);i++) 
                       {
                           Contact Con = new Contact();
                           Con.accountId         = Accid;
                           Con.LastName          = Acc.Account_Number__c + '-' + con.Contact_Count__c;
                           Con.FirstName                     = Acc.Name;
                           Con.Phone	                        = Acc.Phone;
                           con.MailingStreet                 =acc.BillingStreet;
               			   con.MailingCity             =acc.BillingCity;
                		   con.MailingState           =acc.BillingState;
                		   con.MailingPostalCode =acc.BillingPostalCode;
                		   con.MailingCountry       =acc.BillingCountry;
                          
                           ConList.add(Con);
                       }
              
                    }
                }
                if(ConList.Size()>0 && ConList!=Null)
                insert ConList;
                
                
            }
        }
        
    }
         catch (Exception e)
        {
            system.debug('An Exception has occured = '+e);
        }

}
}

 

An internal server error has occurred
An error has occurred while processing your request. The salesforce.com support team has been notified of the problem. If you believe you have additional information that may be of help in reproducing or correcting the error, please contact Salesforce Support. Please indicate the URL of the page you were requesting, any error id shown on this page as well as any other related information. We apologize for the inconvenience. 

Thank you again for your patience and assistance. And thanks for using salesforce.com! 

Error ID: 640199601-8566 (-1664635790)



 
trigger TriggerUpdateSalesRep on Account (before insert, Before Update)
{
	Set<ID> SetAccOwner = new Set<ID>();
    for(Account Acc : Trigger.new)
    {
        setAccOwner.add(Acc.OwnerID);
    }
    map<Id,User>User_Map = New Map<Id,User>('select Name from User where id in:setAccOwner');
	for(Account acc:Trigger.new)
         {
          User usr = User_Map.get(Acc.OwnerId);
             Acc.Sales_Rep__c=usr.name;
         }
    
    
}