• sudha76
  • NEWBIE
  • 5 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 29
    Questions
  • 35
    Replies

Can I built a VF Email Template where the "To" field can populated or overwritten?

 

The Email will be sent out from the Lead level, and as you know be default the "To" field displays the Lead Name.

 

There is a lookup to Contact custom field in the LEAD, and when the VFTemplate is selected the "To" field should be overwritten to that Contact Name which is already selected on the LEAD.

 

Can this be done?

Here is my formula to extract first few lines from the TASK Description (Standard) Field.

 

TRIM(RIGHT( Description , 200))

 

The above works but not exactly.

 

I get the content which starts from the middle of the paragraph. How can I write this?

I am looking for an example to create a Trigger that will copy the first n character (255 characters) from the TASK standard field called - Description to the custom field under TASKS called - "Extract Task Heading".

 

Any examples on how to copy values within same object and different fields would also help?

 

thanks.

Based on the current limitation which is Task Description field of TASKS object, cannot be pulled into the related list properties due to the field type ie - Long Text Area, I need to come up with some kind of customized solution to display the first few lines of this field on the realted list view page.

 

The challenge is, I tried using the Formula field on the activity custom field, but "Description" standard field is unavailbel for any field updates.

 

So seems I cannot use Formulas to capture the lines from this field .

 

The Goal is to display a field on related list view which displays first few statements from the Description field, so that the Sales Team can glance the updates.

Hi there,

We have a lookup field on LEADS point to Accounts. The Web To Lead Form does not display the Lookup field called "Reseller", and I am not sure what HTML element should be used to grab the data from the Web Form and then populate into the look up field into LEADS object.

We have tried using something like this:-

Reseller: 

 

 

Reseller:<input  id="00N80000004nbGG" maxlength="100" name="00N80000004nbGG" size="20" type="text" /><br>



This is not working.

On the Web Form the field Reseller is a picklist while in SFDC we are trying to populate into lookup field.

How should this be resolve, what do we need to do on our web form to populate this value into SFDC under the lookup field.?

This Rule below, ensures that if the Account Source = Data.com , then the Account Name should have a "-" and end with the value from the "Site_City" field.

 

IF(ISPICKVAL(AccountSource, "Data.com"),FALSE,OR(FIND( " - ", Name ) = 0, FIND( Site_City__c , Name ) = 0))

 

This works fine.

 

I wanted to do a similiar thing in the custom picklist field called = Site_Country.

 

If the Account Source = Data.com, then the value from the BillingCountry should be copied over to the picklist field Site_Country field.

 

How can I do this.

 

 IF(ISPICKVAL( AccountSource , "Data.com"),FALSE,
OR( ISPICKVAL( Site_Country__c , " "),
 FIND(search_text, text [, start_num])

 

I am stuck here and unable to understand how can I update this picklist field using FIND function, like it is done above in the first rule.

 

please help.

I have this rule on Accounts

 

OR(
ISBLANK( Site_Street__c ),
ISBLANK( Site_City__c ),
ISBLANK( TEXT(Site_Country__c ))
)

 

It works fine on Accounts.

 

If a lead is converted the error comes in when the user selects create a new Account. The LEAD already has all the values that I need on Acocunts, and the fields are also mapped correctly, then I do not understand why is this error coming on lead conversion.

 

Please can you help me. The error should come on lead conversion if the City is missing or street, but it still gives error even if all the data is present.

 

How weird is that?

On Accounts, there is a related list called - Account Technical Profile . One Account can only have one ATP record. It will never have more than one ATP record.

There is a master details relationship between Account and ATP custom object.

 

I have another lookup field on Account - Copy_TechnicalProfile. I would like this field to be populated when the Account has an ATP record created.  Here is my trigger.

 

trigger Capture_AccountTechnicalProfile on Account (before update) {

Set<Id> accIds = new Set<Id>();
Map(Id, Account> accmap;

for(Account acct: trigger.new)
{
    if(acct.Account_Technical_Profile__Id != null)
    {
        accIds.add(acct.Account_Technical_Profile__Id);
    }

accmap = [select Id, Copy_Account_Technical_Profile__c FROM Account where Account_Technical_Profile__Id IN : accIds];

    for(Account acct : trigger.new)
    {
        if(acct.AccountId !=null && accmap.containsKey(acct.Account_Technical_Profile__Id)
        {
            
            Copy_Account_Technical_Profile__c = accMap.get(acct.Account_Technical_Profile__Id).Copy_Account_Technical_Profile__c;
        }
}

 

 

I am getting this error message:-

 

Error

Error: Compile Error: unexpected token: 'Map' at line 5 column 0

 

 

 

 

 

I am trying to create a OnClick JS Code, where if an Account displays the Profile records, in the related list called - Account_Technical_Profile__c, then the user should not be allowed to create another record. Only one Technical Profile per Account is allowed. They can edit the existing Technical Profile, but they cannot add one more , if it already exists.

 

Here is my code:-

 

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

var Account = new sforce.SObject("Account");
var Account_Technical_Profile__c = new sforce.SObject("Account_Technical_Profile__c");
Account.id = "{!Account.Id}";

var qr = sforce.connection.query("Select Account__c From Account_Technical_Profile__c where Account_Technical_Profile__c='{!Account.Id}'");

var records = qr.getArray('records');
var alreadyadded = false;

if (records.length> 0)
{
for (var i=0;i<records.length;i++) {
alert ("The Account Profile for this Account already exists. Please update the existing Account Technical Profile");
alreadyadded = true;
}
else {
window.location = 'https://cs3.salesforce.com/a0f/e?CF00NQ0000000xdOp={!Account.Name}&&retURL={!Account.Id}'';
}
}

 

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

 

I am getting the "Syntax Error". What am I missing here? The logic seems to be correct, right?

 

 

 

I have this existing Trigger which checks for Account Duplicates, based on the Account Name - City Name. This is so generic that if the user enters the Account Name slightly differently but the street address is also the same, this Trigger does not warn users and lets them create the Account.

trigger AccountCreateTrigger on Account (before insert) {
for (Account acc: Trigger.new)
     {Account [] accs = [SELECT Name FROM Account WHERE Name = :acc.Name LIMIT 1];
      if (accs.size() > 0 ) //if account already exists, block and show the information on the page
         {acc.addError('Account  \'' + accs[0].Name +  '\' already exists. Please use existing account or contact your Salesforce Administrator for assistance.'); }
     }
}

 

 

 

 

How do you restrict users from entering the duplicate Accounts?

What criterias or fields do you use to make sure that duplicate accounts are not entered?

 

Please advice.

trigger AccountCreateTrigger on Account (before insert) {
for (Account acc: Trigger.new)
     {Account [] accs = [SELECT Name FROM Account WHERE Name = :acc.Name LIMIT 1];
      if (accs.size() > 0 ) //if account already exists, block and show the information on the page
         {acc.addError('Account  \'' + accs[0].Name +  '\' already exists. Please use existing account or contact your Salesforce Administrator for assistance.'); }
     }
}

Hi there,

 

I have a very unique sitatuon and possible a hard one to solve. I have this Validation Rule on the Contacts

 

 

AND(

OR(ISBLANK( LeadConverted2_ctc__c ),

AND(NOT(ISNEW()),

LeadConverted2_ctc__c =1

)

),

OR(

ISBLANK( Title ),

ISBLANK( Phone ),

ISBLANK( Email )

),

NOT(ISPICKVAL( LeadSource , "XYZ")))

 

 

We have data coming from the outside source which comes as a LEAD and in that external app we do not capture Title of the Lead. So this RULE should not kick in when the data is being fed from the external app as a LEAD.

I tried to solve the above by capturing the Lead Source. But here is another challenge that I am facing:-

 

If the LEAD that is being converted has a LEAD Source = XYZ and the Contact that is being attached to also has the same LEAD Source, then the Val Rule does not get ignored and gives the error message that Title, Phone and Email is required.

 

If the Contact's LEAD Source = SFDC then the Validation Rule is easily by passed.  I want this to happen at all lead conversion.

 

I want the Validation Rule not to kick in on the Lead Conversion.

 

Can I do this with Val Rule or is APEX the answer?

 

please help

 

 

 

 

 

hi there,

 

Today, I managed to write yet another trigger and like always I think I have some errors. Please help:-

 

Trigger ChangeLeadOwner on Lead (after Insert)
{

    //First I will get list of LEAD Records where Pardot Score is less than 50 using a Query
    
    
    List<Lead> ParLead = [SELECT Id, Name FROM LEAD WHERE pi__score__c < 50];

    set<Id> LeadIds = new set<Id>();

    
    // Also get the list of Queues related to LEAD object and the specific queue where these leads should be assigned to.
    
    List<QueueSobject) PardotQueue = [SELECT Id, SobjectType, QueueId, Queue.Name, Queue.Email FROM QueueSobject WHERE Queue.Id=: 00GS00000016UFx AND SObjectType='Lead'];

    
    // Now, I should define a FOR loop which will search through the LEAD Records and look for the Pardot_Score field to be 50 or more than 50 then
    // reassign the LEAD to the Pardot Queue.

    for(Lead Leady1: Trigger.new)
    {
        if(pi__score__c >= '50')
        {
            newLead[0].Ownerid = PardotQueue[0].id;
        }
    }
}

 

My Goal is :-

 

On a LEAD when the field pi__score__c reached 50 or greater than 50 then it should be reassigned to a a specfic queue called - Pardot_Queue where the ID is = 00GS00000016UFx

 

 

Please help.

The Trigger checks the Contacts and if it has Opportunity it makes the field HasOpportunity = true. Here is the trigger which works fine:-

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

trigger CheckContacts on Contact (before update)
{

// Map is intialized here to ContactID or Contact + all OCRs

Map<Id,Contact> cIdToContactWRelRecsMap  = new Map <Id,Contact>

([select id, (select id from OpportunityContactRoles) from Contact where id IN :trigger.new]);

// In the Trigger.new list, check the map to see if the size of the OCR related list is > 0.

for (Contact c: Trigger.new) {

    if (cIdToContactWRelRecsMap.get(c.id).opportunityContactRoles.size() > 0) c.HasOpportunity__c = true;
    
     }
     
     }

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

 

I need help in building the test class. How will I write the QUERY in this test class, here it is:-

 

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

@isTest
public class CheckContactsOppty{
    static testMethod void testContactoppty()
    {
        // First, prepare 200 contacts for the test data for which first we will create some Accounts data.
        Account acct = new Account(name='TestingReal account');
        insert acct;

        Contact[] contactsToCreate = new Contact[]{};
        for(Integer x=0; x<200; x++)
        {
            Contact ctc = new Contact(Account Id= acct.Id, lastname='Rao', firstname='Sierra');
            contactsToCreate.add(ctc);
        }

        // Now I will create the Opportunity for these contacts.

        Opportunity opptytoCreate = new Opportunity[]{};
        for (Integer x=0; x<200; x++)
        {
            Opportunity oppty = new Opportunity(Contact Id= contactsToCreate.Id, Name='BestDeal');
            opptytoCreate.add(oppty);
        }
            
        // Now query the test data if it has opportunity or not.

        Test.startTest();
        ([select contactsToCreate.id, (select id from OpportunityContactRoles) from Contact where id IN :trigger.new]);  

 


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

 

 

Please help

 

Trying to create a TRIGGER on CONTACT to set the checkbox called "Has_Opportunity__c" to TRUE if that Contact has any Opportunity.

 

or if that Contact is a part of the OpportunityContactRole table?

 

How can I query it? I am trying to use workbench, first to build such a query? any ideas?

Can I create a SOQL query saying - show me all those Contacts which have the opportunity. ?

 

I think i will have to use the OpportunityContactRole table.

 

Basically I am trying to search for those contacts which do no thave any email, phone but they have opportunity. How can I build such a query. ?

Hi there,

 

This is the piece of code:-

 

<td width="35%" align="left">
                <u><apex:outputText value="Account Manager Info" style="font-weight:bold; font-size:14px" /></u><br></br>
                     <b> Requestor Name: </b> <span> <span><apex:outputText value="{!relatedTo.Owner.Name}" /> </span></span>
                </td>

 

The output of this code is working great.

 

I used the same code here and just changed the labels:-

 

<td width="35%" align="left">
                <u><apex:outputText value="Partner Info for Reimbursement" style="font-weight:bold; font-size:14px" /></u><br> </br>
                     <b> Partner Name: </b> <span><span> <apex:outputText value="{!relatedTo.Owner.Name}" /> </span></span>
                </td>

 

 

The problem is:-

 

Partner Name is displayed very big font size. It does not look the same as the Requestor Name. I am simply using <b> tags and nothing else, then why is it showing so huge in the second cell and the first one works fine.

 

What am I missing?

 

 

 

 

Hi there,

 

Here is the APEX Class and the Trigger on the parent object - MDF_Funding.

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

/* This class will return the number of attachments in the Notes and Attachment section for the parent object Partner Funded Activity. */

public class checkAttachments
{
    public static boolean isInsert = false;
    public static integer numberOf(MDF_Funding__c[] funds)
    {
        Attachment [] att = [SELECT ID from Attachment Where ParentID IN: funds];
        return att.size();
    }
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


trigger QuoteAttached on MDF_Funding__c (before insert)
{

checkAttachments.numberOf(Trigger.new);

for(MDF_Funding__c funds : Trigger.new)
{
    if (checkAttachments.isInsert == false)
        {
        funds.addError('Please provide the Quote as an Attachment before saving this record');
        }
}
   

       

}

 

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

 

I want to add one more logic here, which says that when the attachment is provided the field called "Quote_Attached" should be set to TRUE. It should be checked.

 

How can I do this? Please help?

 

Hi there,

 

Using a standard Web to Lead form, we are unable to capture the First Name into the SFDC. When the user enters the Name, he first enter First Name and then Last Name. The Last Name comes into the SFDC but the First Name does not come.

 

Not sure, why is this happening and what we need to change in the code below to get the First Name. This has never happened before. Please help.:-

 

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

 

                post.Url = "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8";

 

                 post.PostItems.Add("first_name", query.ElementAt(i).FirstName);

                 post.PostItems.Add("last_name",query.ElementAt(i).LastName);

                 post.PostItems.Add("phone", query.ElementAt(i).Phone);

                 post.PostItems.Add("email", query.ElementAt(i).EmailID);

                 post.PostItems.Add("Lead_Type__c", usertype);

                 post.PostItems.Add("company",  query.ElementAt(i).Company);

                 post.PostItems.Add("title", query.ElementAt(i).JobTitle); // Added

                 post.PostItems.Add("Address", query.ElementAt(i).Address); // Added

        

 

                 post.PostItems.Add("oid", "00D00000000hbaA");

    

               

                //Lead source

                 post.PostItems.Add("lead_source", "Sunshine Web Site");

 

 

                // Lead Recoard Type

                // "012000000008Qyk"= New Sales Lead Record Type

                 post.PostItems.Add("recordType", "012000000008Qyk");

 

                // Web to Lead Form

                 post.PostItems.Add("00N00000008aJxp", "Mt. Sunshine Interest Form");

                 string result = post.Post();

 

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

 

 

Thanks for you help.

  • September 19, 2012
  • Like
  • 0

Hi there,

 

Can we create a TRIGGER on a custom object , that will make sure an attachment is provided under the notes and attachment section, before the record is saved.?

 

Is this possible?

 

thanks

 

  • September 07, 2012
  • Like
  • 0

Hi there,

 

I have installed SForce_Office_Toolkit from - http://code.google.com/p/excel-connector/downloads/detail?name=SForce_Office_Toolkit_MSI.zip&can=2&q=

 

Now,I try to follow these steps -

 

  1. Launch Excel 2007
  2. Click on Add-ins
  3. And now, I am unable to locate this file or Add in for Toolkit - I cannot see this file - sforce_connect.xla

I have tried several times and cannot locate this file anywhere, even though I have installed it. What am I missing.?

 

I have also installed this ZIP file - sforce_connect_ee_1602.zip and I see it under C:\sforce_connect_ee_1602.zip 

 

 

the installation is quite complex?

 

 

please help

Can I built a VF Email Template where the "To" field can populated or overwritten?

 

The Email will be sent out from the Lead level, and as you know be default the "To" field displays the Lead Name.

 

There is a lookup to Contact custom field in the LEAD, and when the VFTemplate is selected the "To" field should be overwritten to that Contact Name which is already selected on the LEAD.

 

Can this be done?

I am looking for an example to create a Trigger that will copy the first n character (255 characters) from the TASK standard field called - Description to the custom field under TASKS called - "Extract Task Heading".

 

Any examples on how to copy values within same object and different fields would also help?

 

thanks.

Based on the current limitation which is Task Description field of TASKS object, cannot be pulled into the related list properties due to the field type ie - Long Text Area, I need to come up with some kind of customized solution to display the first few lines of this field on the realted list view page.

 

The challenge is, I tried using the Formula field on the activity custom field, but "Description" standard field is unavailbel for any field updates.

 

So seems I cannot use Formulas to capture the lines from this field .

 

The Goal is to display a field on related list view which displays first few statements from the Description field, so that the Sales Team can glance the updates.

I have this rule on Accounts

 

OR(
ISBLANK( Site_Street__c ),
ISBLANK( Site_City__c ),
ISBLANK( TEXT(Site_Country__c ))
)

 

It works fine on Accounts.

 

If a lead is converted the error comes in when the user selects create a new Account. The LEAD already has all the values that I need on Acocunts, and the fields are also mapped correctly, then I do not understand why is this error coming on lead conversion.

 

Please can you help me. The error should come on lead conversion if the City is missing or street, but it still gives error even if all the data is present.

 

How weird is that?

On Accounts, there is a related list called - Account Technical Profile . One Account can only have one ATP record. It will never have more than one ATP record.

There is a master details relationship between Account and ATP custom object.

 

I have another lookup field on Account - Copy_TechnicalProfile. I would like this field to be populated when the Account has an ATP record created.  Here is my trigger.

 

trigger Capture_AccountTechnicalProfile on Account (before update) {

Set<Id> accIds = new Set<Id>();
Map(Id, Account> accmap;

for(Account acct: trigger.new)
{
    if(acct.Account_Technical_Profile__Id != null)
    {
        accIds.add(acct.Account_Technical_Profile__Id);
    }

accmap = [select Id, Copy_Account_Technical_Profile__c FROM Account where Account_Technical_Profile__Id IN : accIds];

    for(Account acct : trigger.new)
    {
        if(acct.AccountId !=null && accmap.containsKey(acct.Account_Technical_Profile__Id)
        {
            
            Copy_Account_Technical_Profile__c = accMap.get(acct.Account_Technical_Profile__Id).Copy_Account_Technical_Profile__c;
        }
}

 

 

I am getting this error message:-

 

Error

Error: Compile Error: unexpected token: 'Map' at line 5 column 0

 

 

 

 

 

I am trying to create a OnClick JS Code, where if an Account displays the Profile records, in the related list called - Account_Technical_Profile__c, then the user should not be allowed to create another record. Only one Technical Profile per Account is allowed. They can edit the existing Technical Profile, but they cannot add one more , if it already exists.

 

Here is my code:-

 

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

var Account = new sforce.SObject("Account");
var Account_Technical_Profile__c = new sforce.SObject("Account_Technical_Profile__c");
Account.id = "{!Account.Id}";

var qr = sforce.connection.query("Select Account__c From Account_Technical_Profile__c where Account_Technical_Profile__c='{!Account.Id}'");

var records = qr.getArray('records');
var alreadyadded = false;

if (records.length> 0)
{
for (var i=0;i<records.length;i++) {
alert ("The Account Profile for this Account already exists. Please update the existing Account Technical Profile");
alreadyadded = true;
}
else {
window.location = 'https://cs3.salesforce.com/a0f/e?CF00NQ0000000xdOp={!Account.Name}&&retURL={!Account.Id}'';
}
}

 

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

 

I am getting the "Syntax Error". What am I missing here? The logic seems to be correct, right?

 

 

 

Hi Team,

 

I Have a field called price in three objects A,B and C.

 

Now i want to get the price values of object A and B into C.

 

Could you please tell me how to create a trigger for it.

 

  • November 27, 2012
  • Like
  • 0

Hi there,

 

I have a very unique sitatuon and possible a hard one to solve. I have this Validation Rule on the Contacts

 

 

AND(

OR(ISBLANK( LeadConverted2_ctc__c ),

AND(NOT(ISNEW()),

LeadConverted2_ctc__c =1

)

),

OR(

ISBLANK( Title ),

ISBLANK( Phone ),

ISBLANK( Email )

),

NOT(ISPICKVAL( LeadSource , "XYZ")))

 

 

We have data coming from the outside source which comes as a LEAD and in that external app we do not capture Title of the Lead. So this RULE should not kick in when the data is being fed from the external app as a LEAD.

I tried to solve the above by capturing the Lead Source. But here is another challenge that I am facing:-

 

If the LEAD that is being converted has a LEAD Source = XYZ and the Contact that is being attached to also has the same LEAD Source, then the Val Rule does not get ignored and gives the error message that Title, Phone and Email is required.

 

If the Contact's LEAD Source = SFDC then the Validation Rule is easily by passed.  I want this to happen at all lead conversion.

 

I want the Validation Rule not to kick in on the Lead Conversion.

 

Can I do this with Val Rule or is APEX the answer?

 

please help

 

 

 

 

 

hi there,

 

Today, I managed to write yet another trigger and like always I think I have some errors. Please help:-

 

Trigger ChangeLeadOwner on Lead (after Insert)
{

    //First I will get list of LEAD Records where Pardot Score is less than 50 using a Query
    
    
    List<Lead> ParLead = [SELECT Id, Name FROM LEAD WHERE pi__score__c < 50];

    set<Id> LeadIds = new set<Id>();

    
    // Also get the list of Queues related to LEAD object and the specific queue where these leads should be assigned to.
    
    List<QueueSobject) PardotQueue = [SELECT Id, SobjectType, QueueId, Queue.Name, Queue.Email FROM QueueSobject WHERE Queue.Id=: 00GS00000016UFx AND SObjectType='Lead'];

    
    // Now, I should define a FOR loop which will search through the LEAD Records and look for the Pardot_Score field to be 50 or more than 50 then
    // reassign the LEAD to the Pardot Queue.

    for(Lead Leady1: Trigger.new)
    {
        if(pi__score__c >= '50')
        {
            newLead[0].Ownerid = PardotQueue[0].id;
        }
    }
}

 

My Goal is :-

 

On a LEAD when the field pi__score__c reached 50 or greater than 50 then it should be reassigned to a a specfic queue called - Pardot_Queue where the ID is = 00GS00000016UFx

 

 

Please help.

The Trigger checks the Contacts and if it has Opportunity it makes the field HasOpportunity = true. Here is the trigger which works fine:-

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

trigger CheckContacts on Contact (before update)
{

// Map is intialized here to ContactID or Contact + all OCRs

Map<Id,Contact> cIdToContactWRelRecsMap  = new Map <Id,Contact>

([select id, (select id from OpportunityContactRoles) from Contact where id IN :trigger.new]);

// In the Trigger.new list, check the map to see if the size of the OCR related list is > 0.

for (Contact c: Trigger.new) {

    if (cIdToContactWRelRecsMap.get(c.id).opportunityContactRoles.size() > 0) c.HasOpportunity__c = true;
    
     }
     
     }

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

 

I need help in building the test class. How will I write the QUERY in this test class, here it is:-

 

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

@isTest
public class CheckContactsOppty{
    static testMethod void testContactoppty()
    {
        // First, prepare 200 contacts for the test data for which first we will create some Accounts data.
        Account acct = new Account(name='TestingReal account');
        insert acct;

        Contact[] contactsToCreate = new Contact[]{};
        for(Integer x=0; x<200; x++)
        {
            Contact ctc = new Contact(Account Id= acct.Id, lastname='Rao', firstname='Sierra');
            contactsToCreate.add(ctc);
        }

        // Now I will create the Opportunity for these contacts.

        Opportunity opptytoCreate = new Opportunity[]{};
        for (Integer x=0; x<200; x++)
        {
            Opportunity oppty = new Opportunity(Contact Id= contactsToCreate.Id, Name='BestDeal');
            opptytoCreate.add(oppty);
        }
            
        // Now query the test data if it has opportunity or not.

        Test.startTest();
        ([select contactsToCreate.id, (select id from OpportunityContactRoles) from Contact where id IN :trigger.new]);  

 


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

 

 

Please help

 

I need some help wrapping my head around testing this trigger - I seem to have prepared and inserted my dataset correct, but I'm not sure why it's giving me an error of "Expected:Null".

 

My Trigger (working in sandbox, manually inserting records)

 

trigger AddCountyId on Contact (before insert, before update) {
	
    Set<String> CountyIds = new Set<String>();
    
    for(Contact c : Trigger.new) {       
       CountyIds.add(c.fdicCountyID__c);       
    }       
    
    Map<String, Id> countyMap = new Map<String,Id>();

	//Add both sets of IDS to above Map
	for(County__c cty : [SELECT cty.Id, cty.fdicCountyID__c
		FROM County__c cty
		WHERE cty.fdicCountyID__c != null AND cty.fdicCountyID__c IN :CountyIds]) {
    		countyMap.put(cty.fdicCountyID__c, cty.Id);
		}    
  
  	//Update Primary County on the Contact with County ID
    for(Contact updateC : Trigger.new) {
	    try {    
	          if(updateC.fdicCountyID__c != null) {
	  			  //Update Primary County with County Id from Map
	              updateC.Primary_County__c = countyMap.get(updateC.fdicCountyID__c);
	          }
	    }  
	    catch (Exception e) {
	   	}
	}

}

 

Stripped down test method in my test class

 

	static testMethod void verifyCountyId() {
		
		//Create Test County
  		County__c cty = new County__c(Name='Test County', Latitude__c = 1, Longitude__c = 1, fdicCountyId__c ='abcd1234');
  		insert cty;
		
		//Create Test Vendor
		Account vAcct = new Account(Name = 'Test Vendor Account');
		insert vAcct;
		Contact v = new Contact(LastName = 'Vendor Demo', last_engaged_date__c = Date.today(), AccountId = vAcct.Id, fdicCountyId__c = 'abcd1234');
		insert v;
		
		System.assertEquals (v.Primary_County_ID__c, cty.Id);
	}

 I get a System.AssertException: Assertion Failed: Expected:null Actual: a0hJ000000FymvMac 

 

Does anyone have any insight as to what i'm doing wrong?

  • February 27, 2012
  • Like
  • 0