• Ravi K 47
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 8
    Replies
Hello All,

I have a requirement to display for each Parent ,list of child records and their list of grand parent records in a visualforce page.
Parent and child have lookup relationship .
But Child to Grand Child are not having any relationship but in GrandChild Object i have one text field "Parent Id " in that filed The Child record id is storing.

User-added image

Apex Class :
 
public  without sharing class Parentchildgrandchild {
    
   
    public string str;
    public list<Contact> Pilist;
    public Map<Contact,list<Grandchild__c>> PIMcamap {get;set;}
    Map<Account,List<Contact>> IPPIMap {get;set;}
                   
    public Parentchildgrandchild(ApexPages.StandardController controller) {
        
        String pcId = ApexPages.currentPage().getParameters().get('id');
        PIMcamap= new Map<Contact,list<Grandchild__c>>();
        
         IPPIMap = new Map<Account,List<Contact>>();
        test__c pc= [select id from test__c where id =:pcId];
		
		for(Account Ip:[select id,name,from Account where test__c =:pcId])
            {   
				for(Contact pi :[SELECT id,name,parent from Contact where Account =:ip.id order by LastModifiedDate ])
                     
                {            
				
					PIList=new List<Contact>();
																					
					list<Grandchild__c> ca= new list<Grandchild__c>();
					str=(string)pi.id;
					ca=[select id, name, parentid from Grandchild__c where parentid=:str];
																					
					PIMcamap.put(pi,ca);
					PIList.add(pi);
                                                                                                
                 }
                                                                                                                
                IPPIMap.put(ip,PIList);   
                                                                                
                   
                
       
			}
    
    public class PIwrapper {
        
        public Account IP {get;set;}
        public Contact pi{get;set;}
        public Grandchild__c mca {get;set;}
       
        
        
    }
    
    
}

VisuaForce Page :
 
<apex:page renderAs="pdf" standardController="MedConnect__Product_Complaint__c" extensions="Parentchildgrandchild">
    
              
                  <apex:repeat value="{!IPPIMap}" var="ac">
                      <table width = "100%" row ="1" column="3" >
                        
					  <tr><th width = "500">Name #</th></tr>
					  <tr><td >{!ac.Name}</td></tr>
					  <tr><th>Child Name</th></tr>
					  
					   <apex:repeat value="{!IPPIMap[ac]}" var="child"> 
							<tr><td>{!child.name}</td></tr>   
							<tr><th>Grand Child Name</th></tr>
							
									<apex:repeat > 
									<tr><td>{!child.name.name}</td></tr>   
									
									</apex:repeat>
						  
						</apex:repeat>
                      
                  
                  </table>
                </apex:repeat>
                    
   
</apex:page>

Due to not having any relationship between Child and GrandChild ,i have created a Wrapper class for that and store thevalues.

From the Apex Class im able to store values of 
Parent and List of Child Records into the map ==> IPPIMap and 
Child record and list of  GrandChild Records ==>PIMcamap

But while referencing in the visualforce page im getting the  below error 

Unknown property 'ParentchildgrandchildStandardController.IPPIMap'

Could you please check and help me on this request .
Hello All,

I have a requirement to download only the selected child records (Not all child records )into an excel file in salesforce.

Lets assume,take Account and Contact
Account	Contacts
India	Delhi,
	    Karnataka
	    Chennai,
	    Andhra Pradesh
Now my requirement is to select few contacts only (lets assume only Delhi and Chennai )  for Account : India then only the selected records to be download into excel.

I can download all the contacts but not the selected records .Below is the code reference for all contacts
<apex:page standardController="Account" contentType="application/vnd.ms-excel#contacts.xls">
    <apex:pageBlock title="Contacts">
        <apex:pageBlockTable value="{!account.Contacts}" var="contact">
            <apex:column value="{!contact.Name}"/>
            <apex:column value="{!contact.MailingCity}"/>
            <apex:column value="{!contact.Phone}"/>
            <apex:selectOption itemLabel="C" itemValue="f"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>


Could you please check and let me know if you require any additional information.

Thanks,
Ravi.
 
Hello,

I have a custom medata data CMDCongi API name  "CMDCongi __mdt"  and under this i have created one custom filed i.ie value API :"Value__c" .

These metadat i have used in the Apex class.

So now my requirement is to cover the custom metadata in test class.

Could you please help on this req and let me know if you require any additonal information .


Thanks
 
Hello All,

I have a requirement to udpate Product2(IsActive) field.

The requirement is udpate IsActive=true for all newly updating records and remaing all old records(oldrecords- newly updating records) should update with IsActive=false value.

Below are the old records 
 
id name isactive
1   ravi     true
2    kumar true
3   kusuma true

Below are the newly updating records
id name isactive
1  ravi    true

and final output looks like 
id name isactive
1   ravi     true
2    kumar false
3   kusuma false

Could you please help me to provide the trigger for this requirement .

 
Hello All,

I have two objects Account and Price_info__c which is related to Account(Master-deatil relationship).

My requirement is :

Im getting data from external system as Csv file and need to  insert/upsert data into my salesforce org.

Below is the sample csv file 
 
CUST_CD      CUST_NM   PAy_CD 
12345        Test1      17890 
23456        Test2      234567


Here in my org i have created one External id field i.e., outlet_number__c  on price_info__c object . Below is the mapping file 
 
CUST_NM=Account_Id__c 
CUST_CD=Outlet_Number__c 
PAY_CD=Account_Number__c


Now my requriement is to update /insert price_info__c based on the outlet number.

Where in the csv file im getting CUST_NM(Account Name ) instead of Account Id .

So while saving the record (Account ID is required as it is a mandatory field) ,so i need to convert the name into respective account id . 


Could you  please help me how to resolve the issue ??
 
Im facing issues with Upsert operation from Command Line Data Loader.

Below is my requirement.

1) I have a custom object custom__c with Account has Master . Fields(Account_Name__c(Master),external__c(text field==>not unique/external))
2)Account has an external id (external__c==>Unique)

The data is coming from an external system and i need to insert/update into custom__c using Command Line Data Loader.
 
Process-config:

<entry key="sfdc.externalIdField" value="id"/>
                <entry key="sfdc.entity" value="custom__c"/>
                <entry key="process.operation" value="upsert"/>


 
Mapping File:

Id=Id
Account_Name__r.external__c=Account_Name__r\:external__c



Here ,im facing issues when keeping externalIdField value as "Id" ==>Its updating the existing records but not inserting and throwing me an error."Record Id is missing"

Even i tried with below ==> Still no luck
<entry key="sfdc.externalIdField" value="Account_Name__r.external__c"/>


Could you please help me on this issue.

 
Hello ,

I have an urgent requirement to extract the data from external application and upsert the data in Sobject (custom object )in salesforce.

Could you please help me to provide relative example for extract and upsert data using Batch Apex in salesforce.

Thanks,
Ravi Kumar K.
Hello All,

In my org there are around 150+ profiles and now my requirement is to disable "Mass Email Functionality " for an entire org.

Im checking the below two options 

1) Disable "Mass Email" checkbox from General User Permissions Settting from Profile Level .Can you pls let me know is there any workaround instead of going to each profile and edit the settting .Can this be acheived for all profiles at a time??

2) From Set Up-->Email Adminstration-->Deliverabilty-> System Email Only .But this option seems to invalid .

Could you please check and provide any workaround for this ??
 
Salesforce is planning to upate the Approval process and below the breif description
Update: Make Sure Records that are Submitted Behind the Scenes are Routed to the Right Approval Process
When records are submitted for approval, Salesforce automatically makes sure that the record meets the entry criteria for the approval process. This critical update does the same for the submitting user when records are submitted behind the scenes by making sure that user is an allowed submitter.

Could you please explain in detail whats the difference between the existing approval process and the latest update.
I have created custom link type "test" for object "Account"  which contains an url "www.google.com" .

Now my requirement only system administrator can see the custom link on account detail page.

Please help on this
Below is the trigger 
 
trigger TaskBeforeDelete on Task (before delete) {

      Map<Id,Profile> profileMap=new Map<Id,Profile>([SELECT Id,Name FROM Profile WHERE Name  IN ('Standard User')]);
       
    System.debug('profileMap==>'+profileMap);
    
    profile p=profileMap.get(UserInfo.getprofileID());
     try {
        
        for (Task task : Trigger.old)  {    
        
        	  if(task.Activity_LFD_Type__c.equalsIgnoreCase('Test') && task.WhatId.getSObjectType() == account.sObjectType && task.WhatId != null && (p==null) )           
            
            {    
                if(!Test.isRunningTest()){
                
                task.addError('You are not permitted to delete this task');
                
                }
     
            }
        
        }
        
    } Catch(Exception e){
        
            
       throw new RuntimeException('****TaskBeforeDelete:'+':' +e.getMessage());
    }
        
     }

Below is the test class 
 
@istest

    public class TaskBeforeDelete_Test{
    
    public static testMethod void BeforeDelete(){ 
    
           Profile pId = [SELECT Id FROM Profile WHERE Name = 'Test Profile'];
        
         User testUser = new User(Email='test@email.com',Phone='555-555-5555',
                                 FirstName='Test',LastName='User', ProfileId=pId.Id,UserName=uniqueName + '@test' + orgId + '.com',
                                 Alias='tesUse',TimeZoneSidKey='America/New_York',
                                 LocaleSIdKey='en_US',EmailEncodingKey='UTF-8',
                                 LanguageLocaleKey='en_US'); 
                                 
        
        system.runAs(testUser){
        
        account acc= new account();
        acc.name='test';
        acc.Site='testsite';
        insert acc;
        
        
       task task=new task();
       task.Activity_LFD_Type__c='Test';
       task.whatid=acc.id;
       
       insert task;
       
       delete task;
       
       }
        
    
    }


}

For the above trigger the code coverage is below 75 % and i'm not able to cover the catch block.

Can any one suggest on this please.
My requirement is Do not permit any users in any profile except 'System Administrator','Standard User' to delete tasks where Left 3 characters of the WhatId = ‘a0P’(DeleteTask__c) and Type(type__c) = ‘Test’
 
trigger TaskBeforeDelete on Task (before delete) {

  Map<Id,Profile> profileMap=new Map<Id,Profile>([SELECT Id,Name FROM Profile WHERE Name Not IN ('System Administrator','Standard User')]);
    profile p=profileMap.get(UserInfo.getprofileID());


    system.debug('Profile ==>'+p);

    for (Task task : Trigger.old)  {    

    if(task.type__c.equalsIgnoreCase('Test') && (p==null)&& task.WhatId != null && task.WhatId.getSObjectType() == == Deletetask__c.sObjectType)           

        {
            task.addError('You are not permitted to delete this task');

        }

    }

 }

Issue is While deleting Task from other objects(like account,contact) throwing NullPointerException: Attempt to de-reference a null object error
Below is the complete Error message
 
Validation Errors While Saving Record(s)There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger TaskBeforeDelete1 caused an unexpected exception, contact your administrator: TaskBeforeDelete1: execution of BeforeDelete caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.TaskBeforeDelete1: line 11, column 1".
Can any one please help to resolve the issue

 
Below is the trigger 
 
trigger TaskBeforeDelete on Task (before delete) {

      Map<Id,Profile> profileMap=new Map<Id,Profile>([SELECT Id,Name FROM Profile WHERE Name  IN ('Standard User')]);
       
    System.debug('profileMap==>'+profileMap);
    
    profile p=profileMap.get(UserInfo.getprofileID());
     try {
        
        for (Task task : Trigger.old)  {    
        
        	  if(task.Activity_LFD_Type__c.equalsIgnoreCase('Test') && task.WhatId.getSObjectType() == account.sObjectType && task.WhatId != null && (p==null) )           
            
            {    
                if(!Test.isRunningTest()){
                
                task.addError('You are not permitted to delete this task');
                
                }
     
            }
        
        }
        
    } Catch(Exception e){
        
            
       throw new RuntimeException('****TaskBeforeDelete:'+':' +e.getMessage());
    }
        
     }

Below is the test class 
 
@istest

    public class TaskBeforeDelete_Test{
    
    public static testMethod void BeforeDelete(){ 
    
           Profile pId = [SELECT Id FROM Profile WHERE Name = 'Test Profile'];
        
         User testUser = new User(Email='test@email.com',Phone='555-555-5555',
                                 FirstName='Test',LastName='User', ProfileId=pId.Id,UserName=uniqueName + '@test' + orgId + '.com',
                                 Alias='tesUse',TimeZoneSidKey='America/New_York',
                                 LocaleSIdKey='en_US',EmailEncodingKey='UTF-8',
                                 LanguageLocaleKey='en_US'); 
                                 
        
        system.runAs(testUser){
        
        account acc= new account();
        acc.name='test';
        acc.Site='testsite';
        insert acc;
        
        
       task task=new task();
       task.Activity_LFD_Type__c='Test';
       task.whatid=acc.id;
       
       insert task;
       
       delete task;
       
       }
        
    
    }


}

For the above trigger the code coverage is below 75 % and i'm not able to cover the catch block.

Can any one suggest on this please.
Hello All,

I have a requirement to display for each Parent ,list of child records and their list of grand parent records in a visualforce page.
Parent and child have lookup relationship .
But Child to Grand Child are not having any relationship but in GrandChild Object i have one text field "Parent Id " in that filed The Child record id is storing.

User-added image

Apex Class :
 
public  without sharing class Parentchildgrandchild {
    
   
    public string str;
    public list<Contact> Pilist;
    public Map<Contact,list<Grandchild__c>> PIMcamap {get;set;}
    Map<Account,List<Contact>> IPPIMap {get;set;}
                   
    public Parentchildgrandchild(ApexPages.StandardController controller) {
        
        String pcId = ApexPages.currentPage().getParameters().get('id');
        PIMcamap= new Map<Contact,list<Grandchild__c>>();
        
         IPPIMap = new Map<Account,List<Contact>>();
        test__c pc= [select id from test__c where id =:pcId];
		
		for(Account Ip:[select id,name,from Account where test__c =:pcId])
            {   
				for(Contact pi :[SELECT id,name,parent from Contact where Account =:ip.id order by LastModifiedDate ])
                     
                {            
				
					PIList=new List<Contact>();
																					
					list<Grandchild__c> ca= new list<Grandchild__c>();
					str=(string)pi.id;
					ca=[select id, name, parentid from Grandchild__c where parentid=:str];
																					
					PIMcamap.put(pi,ca);
					PIList.add(pi);
                                                                                                
                 }
                                                                                                                
                IPPIMap.put(ip,PIList);   
                                                                                
                   
                
       
			}
    
    public class PIwrapper {
        
        public Account IP {get;set;}
        public Contact pi{get;set;}
        public Grandchild__c mca {get;set;}
       
        
        
    }
    
    
}

VisuaForce Page :
 
<apex:page renderAs="pdf" standardController="MedConnect__Product_Complaint__c" extensions="Parentchildgrandchild">
    
              
                  <apex:repeat value="{!IPPIMap}" var="ac">
                      <table width = "100%" row ="1" column="3" >
                        
					  <tr><th width = "500">Name #</th></tr>
					  <tr><td >{!ac.Name}</td></tr>
					  <tr><th>Child Name</th></tr>
					  
					   <apex:repeat value="{!IPPIMap[ac]}" var="child"> 
							<tr><td>{!child.name}</td></tr>   
							<tr><th>Grand Child Name</th></tr>
							
									<apex:repeat > 
									<tr><td>{!child.name.name}</td></tr>   
									
									</apex:repeat>
						  
						</apex:repeat>
                      
                  
                  </table>
                </apex:repeat>
                    
   
</apex:page>

Due to not having any relationship between Child and GrandChild ,i have created a Wrapper class for that and store thevalues.

From the Apex Class im able to store values of 
Parent and List of Child Records into the map ==> IPPIMap and 
Child record and list of  GrandChild Records ==>PIMcamap

But while referencing in the visualforce page im getting the  below error 

Unknown property 'ParentchildgrandchildStandardController.IPPIMap'

Could you please check and help me on this request .
Hello All,

I have a requirement to download only the selected child records (Not all child records )into an excel file in salesforce.

Lets assume,take Account and Contact
Account	Contacts
India	Delhi,
	    Karnataka
	    Chennai,
	    Andhra Pradesh
Now my requirement is to select few contacts only (lets assume only Delhi and Chennai )  for Account : India then only the selected records to be download into excel.

I can download all the contacts but not the selected records .Below is the code reference for all contacts
<apex:page standardController="Account" contentType="application/vnd.ms-excel#contacts.xls">
    <apex:pageBlock title="Contacts">
        <apex:pageBlockTable value="{!account.Contacts}" var="contact">
            <apex:column value="{!contact.Name}"/>
            <apex:column value="{!contact.MailingCity}"/>
            <apex:column value="{!contact.Phone}"/>
            <apex:selectOption itemLabel="C" itemValue="f"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>


Could you please check and let me know if you require any additional information.

Thanks,
Ravi.
 
Hello All,

I have a requirement to udpate Product2(IsActive) field.

The requirement is udpate IsActive=true for all newly updating records and remaing all old records(oldrecords- newly updating records) should update with IsActive=false value.

Below are the old records 
 
id name isactive
1   ravi     true
2    kumar true
3   kusuma true

Below are the newly updating records
id name isactive
1  ravi    true

and final output looks like 
id name isactive
1   ravi     true
2    kumar false
3   kusuma false

Could you please help me to provide the trigger for this requirement .

 
My requirement is Do not permit any users in any profile except 'System Administrator','Standard User' to delete tasks where Left 3 characters of the WhatId = ‘a0P’(DeleteTask__c) and Type(type__c) = ‘Test’
 
trigger TaskBeforeDelete on Task (before delete) {

  Map<Id,Profile> profileMap=new Map<Id,Profile>([SELECT Id,Name FROM Profile WHERE Name Not IN ('System Administrator','Standard User')]);
    profile p=profileMap.get(UserInfo.getprofileID());


    system.debug('Profile ==>'+p);

    for (Task task : Trigger.old)  {    

    if(task.type__c.equalsIgnoreCase('Test') && (p==null)&& task.WhatId != null && task.WhatId.getSObjectType() == == Deletetask__c.sObjectType)           

        {
            task.addError('You are not permitted to delete this task');

        }

    }

 }

Issue is While deleting Task from other objects(like account,contact) throwing NullPointerException: Attempt to de-reference a null object error
Below is the complete Error message
 
Validation Errors While Saving Record(s)There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger TaskBeforeDelete1 caused an unexpected exception, contact your administrator: TaskBeforeDelete1: execution of BeforeDelete caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.TaskBeforeDelete1: line 11, column 1".
Can any one please help to resolve the issue