• Santosh Sriram 2310
  • NEWBIE
  • 95 Points
  • Member since 2016
  • ProQuest Consulting


  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 14
    Replies
Hello Developers!
I need some help on this..
Two Objects with Master-Detail: 1) Volunteer_Project__c (Master) , 2) Participation__c (Detail)
Task: Need to count identical email address on parent for child.
Trigger:
Trigger UniqueEmailCount On Volunteer_Project__c(before insert, before update)
{
    List<Participation__c> ParticipationList = new List<Participation__c>();
    Set<String> uniqueEmails = new Set<String>();
    
    
    ParticipationList = [SELECT Volunteer_Email__c FROM Participation__c where Volunteer_Project_Name__c IN :Trigger.New];

        for (Integer i = 0; i< ParticipationList.size(); i++)
        {uniqueEmails.add(ParticipationList[i].Volunteer_Email__c);
        }
        
        for(Volunteer_Project__c proj: Trigger.new)
        { 
        proj.Total_Associated_Volunteers__c = uniqueEmails.size();
        }
}
Problem:
When I individually add parent and then child for them it counts unique emails. All good as of now!
But when I Mass update all parent then they all gets updated with same value.
(e.g., Let's say 3 projects A, B, C and each has Total_Associated_Volunteers__c as 5, 10, 15.
But When I update all 3 project as Mass Update then all Projects has Total_Associated_Volunteers__c = 15)
Thank you for the support!
 
Hi,

I am new to apex and an trying to write a trigger that will update a contact field after an opportunity is closed won.  These contacts are those contact roles attached to the opportunity.

I have a custom field on the contact and also the account object called Lifecycle Status and would like these to update to 'Customer' upon the opportunity becoming closed won.

First here is my bad code for trying to update the contact role on the opportunity to 'customer': 

trigger UpdateContact on Opportunity (after insert, after update) {

        OpportunityContactRole ocr;
        Contact contact;
        
        Opportunity opp = Trigger.new[0];
            if(opp.StageName == 'Won' && opp.Number_Of_Contact_Roles__c > 0)
            
          ocr = [Select o.Role, o.OpportunityId, o.IsPrimary, o.Id, o.ContactId 
         From OpportunityContactRole o where o.OpportunityId =: opp.id];

          contact = [Select c.OwnerId, c.Id, c.AccountId,c.name,c.Lead_Lifecycle_Stage__c 
          From Contact c where c.id =: ocr.ContactId ];
         
                {
                    contact.Lead_Lifecycle_Stage__c = 'Customer';
                    update contact;      
                }
}


I am getting a null error and asuming because its looking for the contact role upon saving the opportunity when its not there.  How do I list or map the associated contact roles to the opportunity and then upon one fire the update of the contact field and account field (although the account field maybe a separate trigger

Thanks for any help
  • November 08, 2016
  • Like
  • 0
Hi all,
I want to download the PDF in the new tab when a button in custom vfpage is clicked. Can anyone help me over here.
Hi,

Could you please let me know how can I count the leads records of an user and insert that value on the user profile?

Thank you a lot !!!
what is trigger and how to start develop any appas and what is importent for learning language basic?i m extrememly new to coding and am attempt to a simple coding that how to increase my coding life i very interest in for develo? 
Hello Developers!
I need some help on this..
Two Objects with Master-Detail: 1) Volunteer_Project__c (Master) , 2) Participation__c (Detail)
Task: Need to count identical email address on parent for child.
Trigger:
Trigger UniqueEmailCount On Volunteer_Project__c(before insert, before update)
{
    List<Participation__c> ParticipationList = new List<Participation__c>();
    Set<String> uniqueEmails = new Set<String>();
    
    
    ParticipationList = [SELECT Volunteer_Email__c FROM Participation__c where Volunteer_Project_Name__c IN :Trigger.New];

        for (Integer i = 0; i< ParticipationList.size(); i++)
        {uniqueEmails.add(ParticipationList[i].Volunteer_Email__c);
        }
        
        for(Volunteer_Project__c proj: Trigger.new)
        { 
        proj.Total_Associated_Volunteers__c = uniqueEmails.size();
        }
}
Problem:
When I individually add parent and then child for them it counts unique emails. All good as of now!
But when I Mass update all parent then they all gets updated with same value.
(e.g., Let's say 3 projects A, B, C and each has Total_Associated_Volunteers__c as 5, 10, 15.
But When I update all 3 project as Mass Update then all Projects has Total_Associated_Volunteers__c = 15)
Thank you for the support!
 

I'd like to create code that would be a before insert I believe.

I have a Custom Object titled, "Speciality Objects". This object has a record type titled "HERO Stories". There is a lookup to Contacts on this object (not a Master Detail).

The code needs to lookup to the Contact and pull the Contact's "First Name" (from Contact) + "Last Name" (from Contact) + HERO Story (plain text) into a field.

How is this possible?

Hi,

I am new to apex and an trying to write a trigger that will update a contact field after an opportunity is closed won.  These contacts are those contact roles attached to the opportunity.

I have a custom field on the contact and also the account object called Lifecycle Status and would like these to update to 'Customer' upon the opportunity becoming closed won.

First here is my bad code for trying to update the contact role on the opportunity to 'customer': 

trigger UpdateContact on Opportunity (after insert, after update) {

        OpportunityContactRole ocr;
        Contact contact;
        
        Opportunity opp = Trigger.new[0];
            if(opp.StageName == 'Won' && opp.Number_Of_Contact_Roles__c > 0)
            
          ocr = [Select o.Role, o.OpportunityId, o.IsPrimary, o.Id, o.ContactId 
         From OpportunityContactRole o where o.OpportunityId =: opp.id];

          contact = [Select c.OwnerId, c.Id, c.AccountId,c.name,c.Lead_Lifecycle_Stage__c 
          From Contact c where c.id =: ocr.ContactId ];
         
                {
                    contact.Lead_Lifecycle_Stage__c = 'Customer';
                    update contact;      
                }
}


I am getting a null error and asuming because its looking for the contact role upon saving the opportunity when its not there.  How do I list or map the associated contact roles to the opportunity and then upon one fire the update of the contact field and account field (although the account field maybe a separate trigger

Thanks for any help
  • November 08, 2016
  • Like
  • 0
Im pretty sure you can do this and I think Ive done before but I can t exactly remember how.
I want to link Account and Contact together but I dont know the Id of the Account. Similarly to how Workbench uses Smart Lookup I want to eneter the Name of the Account and the DML does the rest to link the 2 objects

So it would be something like 

Contact c = new Contact (Firstname='Steve', Lastname='Hendry', AccountId='36 Robinsmith Rd');
insert c  ;

As you see Ive not provided the Id for the AccountId but so long as the Account '36 Robinsmith Rd' exists I want them to link
public class ldController {
    public Lead leadRecord{get;set;}
   
    public ldController(ApexPages.StandardController sc){
     this.leadRecord = (Lead) sc.getRecord();        
    }
     
	Double leadLatitude = leadRecord.Latitude;
    Double leadLongitude = leadRecord.Longitude;
    
    List<Account> acc = new List<Account>();


    public List<Account> getAccounts(){
        Acc = Database.query('SELECT Id, Name, ShippingLatitude, ShippingLongitude, Phone FROM Account WHERE RecordTypeId=:\'01258000000ATCX\' AND DISTANCE(LOCATION(' + leadLatitude + ', ' + leadLongitude + ' ), LOCATION(ShippingLatitude, ShippingLongitude),\'km\') limit 20');    
        return Acc;
    }
}
 
<apex:page standardController="Lead" extensions="ldController">
    <apex:form >
        <apex:pageBlock title="Lead Information">
            <apex:pageBlockSection title="Details" columns="1">
               
                 Name: {! leadRecord .name} <br />
                Phone: {! leadRecord .Phone} <br />
                
            <apex:commandButton action="{! save}" value="Save"/>    
            </apex:pageBlockSection>
             <apex:pageBlockSection title="Accounts" id="results" >       
            <apex:pageBlockTable value="{!accounts}" var="a" >
            <apex:column value="{!a.id}"/>
            <apex:column value="{!a.name}"/>    
            <apex:column value="{!a.phone}"/>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
</apex:page>
</apex:page>


I would like display a list which shows the nearst customers. I add a Button to the lead - pagelayout. but when i click on it, it thorws an exception :

 

Visualforce Page: /apex/ShowNearLeads



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

Class.ldController.<init>: line 8, column 1

Debug Log:
38.0 APEX_CODE,FINE;APEX_PROFILING,FINE;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,FINE;WORKFLOW,INFO
12:54:50.0 (324935)|USER_INFO|[EXTERNAL]|005580000010hIq|osrc@viessmann.com.dev1|Mitteleuropäische Normalzeit|GMT+01:00
12:54:50.0 (369104)|EXECUTION_STARTED
12:54:50.0 (374755)|CODE_UNIT_STARTED|[EXTERNAL]|0666E0000004CoG|VF: /apex/ShowNearLeads
12:54:50.0 (5930161)|VF_APEX_CALL_START|[EXTERNAL]|01p6E000000Ce2l|ldController <init>
12:54:50.0 (5944369)|SYSTEM_MODE_ENTER|true
12:54:50.0 (6376576)|METHOD_ENTRY|[1]|01p6E000000Ce2l|ldController.ldController()
12:54:50.0 (6389953)|METHOD_EXIT|[1]|ldController
12:54:50.0 (6677559)|EXCEPTION_THROWN|[8]|System.NullPointerException: Attempt to de-reference a null object
12:54:50.0 (7009926)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object

Class.ldController.<init>: line 8, column 1
12:54:50.0 (7108339)|VF_APEX_CALL_END|ldController <init>
12:54:50.19 (19837942)|CUMULATIVE_PROFILING_BEGIN
12:54:50.19 (19837942)|CUMULATIVE_PROFILING|No profiling information for SOQL operations
12:54:50.19 (19837942)|CUMULATIVE_PROFILING|No profiling information for SOSL operations
12:54:50.19 (19837942)|CUMULATIVE_PROFILING|No profiling information for DML operations
12:54:50.19 (19837942)|CUMULATIVE_PROFILING|method invocations|
External entry point: public void <init>(ApexPages.StandardController): executed 1 time in 1 ms
Class.ldController.<init>: line 8, column 1: public Lead __sfdc_leadRecord(): executed 1 time in 0 ms

12:54:50.19 (19837942)|CUMULATIVE_PROFILING_END

 

Can someone help me ?

Is there any possibility to change or set domain for cookies in browsers ?

User-added image

Help me out

Thanks !
Hi all,
I want to download the PDF in the new tab when a button in custom vfpage is clicked. Can anyone help me over here.
Hi All,  I used batch Apex normally but using dynamic apex i am new.Can anyone please guide me for the Following Scenario using Batch Apex(Dynamic)
 In Batch Class constructor: global Account batch(String ObjectName)  
My scenario i passed this ObjectName as parameter and
if (ObjectName==Account)
{ need to query account  records
}
else if (ObjectName =Contact )
{ Query Contact records)
}
So i will get either account or contact records in scope and in execute method i will create records for other custom object based on this scope And in scheduler class how i will pass for account and contact  
Please anyone guide me to do this  
Thanks in advance

I'm working with a standard object that's used by a managed package. The managed package includes some software that runs on the package author's own server and that calls into Salesforce using the web services API, to create records for that standard object. Other Salesforce apps also create records for that standard object. I need to write a trigger that can detect if a record is being added by the managed package's code (i.e., as a result of an API call) or by some other means.

 

I have no control over the way the external server calls into Salesforce to create records for this object. I can't modify that software.

 

I have no control over the UI. Because it's a standard object, many apps can create records for it. I can't change all of those apps to make them set some kind of flag that says "I'm not creating this record through the API."

 

Given those limitations, is there any way a trigger can determine whether it's being called as a result of an API call?

 

I've tried various UserInfo methods, without much luck. I thought if I called UserInfo.getUiThemeDisplayed() from a trigger invoked as a result of an API call, it might tell me that there's no UI Theme being displayed, but it doesn't.  

UserInfo.getUserId() doesn't help me because the external server logs into Salesforce using the same login credentials that a browser user would.

  

Is there anything in UserInfo.getSessionId() that might be useful? 

 

Thanks for your help!

  • June 10, 2010
  • Like
  • 1