• ashishkr
  • NEWBIE
  • 170 Points
  • Member since 2012

  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 37
    Replies

When I attempt to pull in the Name of an Account that is related to an Opportunity:  

 

string s = trigger.newMap.get(oppty.AccountId).name;

 

I get the following error:

 

 

Error:Apex trigger updateOpptyCustomerWons caused an unexpected exception, contact your administrator: updateOpptyCustomerWons: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.updateOpptyCustomerWons: line 31, column 1

 

Any ideas what I might be doing wrong?  

 

trigger updateOpptyCustomerWons on Opportunity (after update) { 

    //make a set to hold opportunity ids that we need
    Set<Id> opptyIds = new Set<Id>();
    
    for(Opportunity o : trigger.new)
        {
        //check to see if our field has been changed
        if(o.StageName != trigger.oldMap.get(o.Id).StageName){
            
            opptyIds.add(o.Id);
            
        }

       }
    
    if(!opptyIds.isEmpty()){
    
        //get any opptys associated with the accounts that have been edited
        
        //Opportunity opp
        
        
        //Opportunity oppty = [SELECT Id,Name, StageName FROM Opportunity WHERE StageName = 'Closed Won' AND Id IN :opptyIds limit 1];
        List<Opportunity> opptyList = [SELECT Id,StageName,Name, AccountId FROM Opportunity WHERE StageName = 'Closed Won' AND Id IN :opptyIds ]; //include Name
        for(Opportunity oppty: opptyList){
        Opportunity opp = new Opportunity();
        
        
        //string s = oppty.name;
        string s = trigger.newMap.get(oppty.AccountId).name;
        
        OpportunityUpdateURL.hitTheServer(s);
        
        
        
     } 
       
    }


}

 

 

 

We run advertising campagins and sometimes they get paused.  I am trying create a field that tells me how many days a campagin has been Paused

So I created 2 fields

"Pause Date" and "Un-Pause Date"

I created Workflows that when the Stage changes to Paused it puts todays date in the "Paused" Field and when its Unpaused it puts today's Date in the "Unpaused" Field.  

I then Created a Formula Field "Days Paused" which subtracts the Unpaused Date from the Paused Date.  This all works perfectly.

 

My Problem is what happens if it gets paused more then once.  How do I keep adding to the "Days Paused" field because the pause date and unpause date fields will be changeing as things get paused and unpaused

  • March 22, 2013
  • Like
  • 0

Hi there, when I test my trigger by updating an opportunity to be 'closed won', I am getting an error back specifying that my trigger isn't returning any rows.  I'm hoping there is something quick that I missed:

 

Error:

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger updateOpptyCustomerWons caused an unexpected exception, contact your administrator: updateOpptyCustomerWons: execution of AfterUpdate caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.updateOpptyCustomerWons: line 24, column 1

 

Trigger:

 

trigger updateOpptyCustomerWons on Opportunity (after update) { 

    //make a set to hold opportunity ids that we need
    Set<Id> opptyIds = new Set<Id>();
    
    for(Opportunity o : trigger.new)
        {
        //check to see if our field has been changed
        if(o.StageName != trigger.oldMap.get(o.Id).StageName){
            
            opptyIds.add(o.Id);
            
        }

       }
    
    if(!opptyIds.isEmpty()){
    
        
        //Opportunity opp
        
        
        Opportunity oppty = [SELECT Id,StageName FROM Opportunity WHERE StageName = 'Closed Won' AND Id IN :opptyIds limit 1];
        
        Opportunity opp = new Opportunity();
        
        if (oppty != null) {
        string s = oppty.name;
        OpportunityUpdateURL.hitTheServer(s);
        }    
        
      
       
    }


}

 

I am trying a bunch of things with this trigger code and was wondering if anybody could give some input on this :

The main elements :

Parent Object : Contract_Overview__c

Field : Subsidiaries_On_Contract__c (multi-value text)

 

Child Object : Subs_Serviced_On_Contract__c

Fields : Contract_Over Subsidiary_Name__c : one of the values stripped from Subsidiaries_On_Contract__c in parent Contract_and_Sub : field used as External ID (Contract + Sub name)

 

I am attempting to upsert a new child record for each value in the Subsidiaries_On_Contract__c field on the Contract_Overview__c object every time a Contract_Overview__c is created or updated using this code :

trigger AutoCreateSubs on Contract_Overview__c (after insert, after update) {
 List<Subs_Serviced_On_Contract__c> subs = new List<Subs_Serviced_On_Contract__c>();

    //For each position processed by the trigger, add a new  

    //Subs_Serviced_On_Contract record for the specified Subsidiaries_On_Contract__c.  

    //Note that Trigger.New is a list of all the new positions  

    //that are being created.  

    for (Contract_Overview__c newContract : Trigger.New) {
        if (newContract.Subsidiaries_On_Contract__c != null) {
            // split out the multi-select picklist using the comma delimiter
            System.debug('Subsidiaries_On_Contract__c ' + newContract.Subsidiaries_On_Contract__c);
            for(String subsoncontract: newContract.Subsidiaries_On_Contract__c.split(',')){
                subs.add(new Subs_Serviced_On_Contract__c(
                        Name = newContract.Name,
                        Contract_Overview__c = newContract.Id,
                        Subsidiary_Name__c = subsoncontract,
                        Contract_and_Sub__c = newContract.Name + '~' + subsoncontract,
                        Logo_Usage_Allowed__c = 'Yes'));
            }
        } 
    }
    upsert subs;

}

 

Right now, it will properly create a new child record for each value which it gets from the Subsidiaries_On_Contract__c upon create or update of a parent (Contract Overview). It then puts that value into the Subsidiary_Name__c field in the child.

However, it will give me this error whenever I attempt to create or update a new Contract Overview which contains a value in its Subsidiaries_On_Contract__c which has already had a child record created :


Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AutoCreateSubs: execution of AfterInsert caused by: System.DmlException: Upsert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: Subsidiary_Name__c duplicates value on record with id: a11W0000000kG4W: [] Trigger.AutoCreateSubs: line 26, column 1: []
Error is in expression '{!Save}' in component <apex:page> in page contractoverviewsfdc

 

I don't understand why I am getting this error. Also, I want to use the Contract Name+Subsidiary Name as the key for the upsert to identify if a child record for a Sub already exists for that particular Contract - and to update an existing one instead of creating a new one.

 

Can anybody give me some input  on this ?

Thank you very much for your time.

  • March 22, 2013
  • Like
  • 0

Hello,

I'm brand new to development and triggers and I'm seeking some help in modifying the below simple trigger.

This is a trigger on the Attachemnt object that checks to count the number of attachments. If more than one then it flags a checkbox Attachment_Added__c on a custom object - Proposal. It works fine, but i would like to change it so that when the attachment is deleted and there are no attachments under the Proposal object then the checkbox on the proposal get cleared. Can someone please help?

Thank you in advance!

 

My current trigger:

// Trigger to update the Attachment__c custom checkbox field in Custom Object(Custom_Obj__c) if it has any attachment.
trigger CountAttachments on Attachment (after insert) 
{          
List<Proposal__c> co = [select id, Attachment_Added__c from Proposal__c where id =: Trigger.New[0].ParentId];          
If(co.size()>0)          
{              
co[0].Attachment_Added__c = True;              
update co;          
} 
}

 

  • March 22, 2013
  • Like
  • 0

There is an excel sheet having data  in different tabs(each tab has data related to various SFDC objects).

Need to pull the required data from each tab & keep it in one final tab. In a single click, entire data from final tab need to get imported to respective SFDC objects.

 

Will there be any possible solution for this scenario?

When I attempt to pull in the Name of an Account that is related to an Opportunity:  

 

string s = trigger.newMap.get(oppty.AccountId).name;

 

I get the following error:

 

 

Error:Apex trigger updateOpptyCustomerWons caused an unexpected exception, contact your administrator: updateOpptyCustomerWons: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.updateOpptyCustomerWons: line 31, column 1

 

Any ideas what I might be doing wrong?  

 

trigger updateOpptyCustomerWons on Opportunity (after update) { 

    //make a set to hold opportunity ids that we need
    Set<Id> opptyIds = new Set<Id>();
    
    for(Opportunity o : trigger.new)
        {
        //check to see if our field has been changed
        if(o.StageName != trigger.oldMap.get(o.Id).StageName){
            
            opptyIds.add(o.Id);
            
        }

       }
    
    if(!opptyIds.isEmpty()){
    
        //get any opptys associated with the accounts that have been edited
        
        //Opportunity opp
        
        
        //Opportunity oppty = [SELECT Id,Name, StageName FROM Opportunity WHERE StageName = 'Closed Won' AND Id IN :opptyIds limit 1];
        List<Opportunity> opptyList = [SELECT Id,StageName,Name, AccountId FROM Opportunity WHERE StageName = 'Closed Won' AND Id IN :opptyIds ]; //include Name
        for(Opportunity oppty: opptyList){
        Opportunity opp = new Opportunity();
        
        
        //string s = oppty.name;
        string s = trigger.newMap.get(oppty.AccountId).name;
        
        OpportunityUpdateURL.hitTheServer(s);
        
        
        
     } 
       
    }


}

 

 

 

We run advertising campagins and sometimes they get paused.  I am trying create a field that tells me how many days a campagin has been Paused

So I created 2 fields

"Pause Date" and "Un-Pause Date"

I created Workflows that when the Stage changes to Paused it puts todays date in the "Paused" Field and when its Unpaused it puts today's Date in the "Unpaused" Field.  

I then Created a Formula Field "Days Paused" which subtracts the Unpaused Date from the Paused Date.  This all works perfectly.

 

My Problem is what happens if it gets paused more then once.  How do I keep adding to the "Days Paused" field because the pause date and unpause date fields will be changeing as things get paused and unpaused

  • March 22, 2013
  • Like
  • 0

I am trying to figure out, what page or trigger this custom button is calling from this code.

 

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}

//GET OPPORTUNITY ID AND PARSE CORRECTLY
var urlstr=(document.URL);
var str=(urlstr);
var n=urlstr.split("/");
var w=n[2];
var x=n[3];
var z=x;
var QuoteHeaderID = x;
//alert(x);

var goNow = sforce.apex.execute("AddProductLines","donothing",{QuoteHeaderID:x});

window.location.href=(goNow);

 

/////////////////////////////////////////////////////////////////////

 

The *AddProductLines" is not under Pages. I am unable to understand exactly what is this and where should I get this info?

 

The Developer who built this form has left, so trying to understand. Please help.

I am trying a bunch of things with this trigger code and was wondering if anybody could give some input on this :

The main elements :

Parent Object : Contract_Overview__c

Field : Subsidiaries_On_Contract__c (multi-value text)

 

Child Object : Subs_Serviced_On_Contract__c

Fields : Contract_Over Subsidiary_Name__c : one of the values stripped from Subsidiaries_On_Contract__c in parent Contract_and_Sub : field used as External ID (Contract + Sub name)

 

I am attempting to upsert a new child record for each value in the Subsidiaries_On_Contract__c field on the Contract_Overview__c object every time a Contract_Overview__c is created or updated using this code :

trigger AutoCreateSubs on Contract_Overview__c (after insert, after update) {
 List<Subs_Serviced_On_Contract__c> subs = new List<Subs_Serviced_On_Contract__c>();

    //For each position processed by the trigger, add a new  

    //Subs_Serviced_On_Contract record for the specified Subsidiaries_On_Contract__c.  

    //Note that Trigger.New is a list of all the new positions  

    //that are being created.  

    for (Contract_Overview__c newContract : Trigger.New) {
        if (newContract.Subsidiaries_On_Contract__c != null) {
            // split out the multi-select picklist using the comma delimiter
            System.debug('Subsidiaries_On_Contract__c ' + newContract.Subsidiaries_On_Contract__c);
            for(String subsoncontract: newContract.Subsidiaries_On_Contract__c.split(',')){
                subs.add(new Subs_Serviced_On_Contract__c(
                        Name = newContract.Name,
                        Contract_Overview__c = newContract.Id,
                        Subsidiary_Name__c = subsoncontract,
                        Contract_and_Sub__c = newContract.Name + '~' + subsoncontract,
                        Logo_Usage_Allowed__c = 'Yes'));
            }
        } 
    }
    upsert subs;

}

 

Right now, it will properly create a new child record for each value which it gets from the Subsidiaries_On_Contract__c upon create or update of a parent (Contract Overview). It then puts that value into the Subsidiary_Name__c field in the child.

However, it will give me this error whenever I attempt to create or update a new Contract Overview which contains a value in its Subsidiaries_On_Contract__c which has already had a child record created :


Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AutoCreateSubs: execution of AfterInsert caused by: System.DmlException: Upsert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: Subsidiary_Name__c duplicates value on record with id: a11W0000000kG4W: [] Trigger.AutoCreateSubs: line 26, column 1: []
Error is in expression '{!Save}' in component <apex:page> in page contractoverviewsfdc

 

I don't understand why I am getting this error. Also, I want to use the Contract Name+Subsidiary Name as the key for the upsert to identify if a child record for a Sub already exists for that particular Contract - and to update an existing one instead of creating a new one.

 

Can anybody give me some input  on this ?

Thank you very much for your time.

  • March 22, 2013
  • Like
  • 0

Hello,

I'm brand new to development and triggers and I'm seeking some help in modifying the below simple trigger.

This is a trigger on the Attachemnt object that checks to count the number of attachments. If more than one then it flags a checkbox Attachment_Added__c on a custom object - Proposal. It works fine, but i would like to change it so that when the attachment is deleted and there are no attachments under the Proposal object then the checkbox on the proposal get cleared. Can someone please help?

Thank you in advance!

 

My current trigger:

// Trigger to update the Attachment__c custom checkbox field in Custom Object(Custom_Obj__c) if it has any attachment.
trigger CountAttachments on Attachment (after insert) 
{          
List<Proposal__c> co = [select id, Attachment_Added__c from Proposal__c where id =: Trigger.New[0].ParentId];          
If(co.size()>0)          
{              
co[0].Attachment_Added__c = True;              
update co;          
} 
}

 

  • March 22, 2013
  • Like
  • 0

Hi,

     I am sunil i need from account object there are 10 records to display  on visualforce page the fieds are Name,phone,Email.when i enter into name fied any character it should display that charater records first in the vf page bottom.can anybody please help me

 

 

thanks&Regards,

Sunil

Hi Folks,

 

I have a custom field (Score) on both my contact and lead objects that I want to includein campaign member reports. Since the report interface does not allow me include custom fields, I need to create a custom formula field (let's call it CMScore) on the Camapign Member object that pulls this data from the lead/ contact field. Can someone explain to me what syntax to use for the formula- i'm a newbee and nto familiar with using formulae.

 

This is essentially what it needs to do:

 

CMScore=

Lead.Score if CampaignMember is a Lead

Contact.Score if CamapignMember is a Contact

 

Any help is greatly appreciated!

 

Thanks!

 

  • March 21, 2013
  • Like
  • 0

Trying to lock editing on Opptys if they have one of two picklist values selected. Also need to except Admins from the rule.

 

My current attempt:

 

AND( 
ISPICKVAL(Status__c,"Active"), 
ISPICKVAL(Status__c,"Expired"), 
NOT($Profile.Id = "00e80000000zMnI") 
)

 

Thanks in advance!

Brian