• Vivek Deepak11
  • NEWBIE
  • -1 Points
  • Member since 2014
  • Senior Developer


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 5
    Replies
Hi,

I have an apex trigger that updates the event custom field with opportunity Stage Value.The trigger is working fine.Now i want to move it to production.But having issues with the test class.

When i run the test class i get the error First Exception on row 0 insufficient access to cross reference entity Id.
Please help! Iam very bad at test classes.


The trigger:
trigger trigeventOpp on Event (before insert, before update) {

   
    Set<Id> opIds = new Set<Id>();
    for(Event t : trigger.new){
        String wId = t.WhatId;
                if(wId!=null && wId.startsWith('006') && !opIds.contains(t.WhatId))
                { opIds.add(t.WhatId);
                } }
    // Pull in opp ids and related field to populate Event record
    List<Opportunity> taskOps = [Select Id, StageName from Opportunity where Id in :opIds];
    Map<Id, Opportunity> opMap = new Map<Id, Opportunity>();
    for(Opportunity o : taskOps)
    { opMap.put(o.Id,o);  } // Update custom task field with  opp field
    for(Event t : trigger.new)
    { String wId = t.WhatId;
     if(wId!=null && wId.startswith('006'))
     { Opportunity thisOp = opMap.get(t.WhatId);
      if(thisOp!=null){t.Opportunity_stage__c = thisOp.StageName;}
                                                 } }
}

The test class

@isTest
private class TheTestClassEvent {
  
public static testMethod void testocc(){
   
     // GET USER FROM USER TABLE...
     User u = [select name, Id  FROM user LIMIT 1];
      Account acc = new Account(
       name = 'temp validation account',
       Type = 'Prospect',
             Sub_Type__c='Merchant - Body',
             BillingCity='Dubai',
             BillingCountry='United Arab Emirates'
            
       );
         insert acc;
       
        Account accCreated = [Select Name From Account Where Id =: acc.Id LIMIT 1];
     // RUN AS USER...
     system.runAs(u)
     {
            Opportunity od = new Opportunity(
       Name = 'Distributor',
                AccountId=accCreated.id,
       Type='New Business',
                StageName='Pending',
                Stage_Notes__c='test opp',
                Edition__c='2014',
                LeadSource='Distributor',
                CloseDate=System.Today()
       );
         insert od;
           
           
           
            // TEST ADDING A NEW Event...                       
      Event eve = new Event(
       subject = 'Meeting test',
                whatId=od.Id
      
       );
         insert eve;
        

        
     }
     system.debug('----->>> RUNNING AS USER: ' + u.name);

   }       
}
Hi,

I have a visualforce page embeded in my Contact and why is it showing the editor instead of the page? Please refer screen shot below:

User-added image
I am having trouble with apex:outputField and a long textarea field.  Salesforce appears to be inserting extra spaces on lines after BR tags.

Here is the text exactly as it appears within the long textarea field:

The following questions and requirements are needed to continue your on-boarding. Once you have finished, you will have access to our system for client and resource management.

1. Fill in some demographic information
2. Sign the advocate handbook

If you have any questions, please contact your Program Manager.

Welcome to the team!

Note all lines are flush against the left margin.


Here is resulting HTML after apex:outputField:

<span>
The following questions and requirements are needed to continue your on-boarding. Once you have finished, you will have access to our system for client and resource management.
<br>
<br>
 1. Fill in some demographic information
<br>
 2. Sign the advocate handbook
<br>
<br>
 If you have any questions, please contact your Program Manager.
<br>
<br>
 Welcome to the team!
</span>


Note that all the text lines after BR tags are indented by a space.  This causes problems because we are also using Markdown to do some extra formatting.

Anyone know how I can eliminate those extra spaces?  I've already tried outputText but that does not suit our needs.

Thanks
David
When I insert a lead, I want to assign a campaign to the lead. However, after I do it, the SF will convert the lead to a contact automatically. How could I solve this using Apex code or Visualforce?

The code I use is as following:

Map<String,Id> recordtypeMap  = new Map<String,Id>();
for(RecordType leadRT :  [select id, Name from RecordType where SObjectType = 'Lead' ]){
recordtypeMap.put(leadRT.Name,leadRT.Id);
}
Lead l = new Lead(firstname='testInsertLead-1-0326', lastname='test-1-0326',company='Temp Company',
                  RecordTypeId = recordtypeMap.get('Temp Lead Type'));
insert l;
Campaign c = [Select id from Campaign limit 1];
CampaignMember mem = new CampaignMember (campaignid=c.id, leadid=l.id);
insert mem;

Thanks.
I have a flow embed in VF page and triyng to render it based on record type selction.

--> rendered="{!Product__c.RecordType.Name=='RecordTypeName'}"'

Don't know if i am missing anything?