• David Lee(China Developer)
  • NEWBIE
  • 55 Points
  • Member since 2013

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 8
    Replies

Can anyone help me to fix this trigger?  

 

What am I missing here?

 

 

Error: Compile Error: expecting a left angle bracket, found '>' at line 3 column 32

 

trigger ContractLine_ContractHeaderLookupUpdate on Contract_Line__c (before insert, before update){

Set <Id> headerIds = new Id<Set>():
List <Contract_Line__c> contractLines = new List <Contract_Line__c>();
List <Contract_Line__c> updateContractUpdate = new List <Contract_Line__c>();

//go through trigger items and add related headers to a set
for(Contract_Line__c c: Trigger.new){
headerIds.add(c.Contract_Header_LOOKUP__c)
}

//go through headers and get account Ids
    List <Contract_Header__c> headers = [Select Id, Account__c FROM Contract_Header__c WHERE Id IN: headerIds];

    //match header accounts to cl accounts
List <Contract_Line__c> contractLines = [Select Id, Contract_Header_LOOKUP__c
     FROM Contract_Line__c
     WHERE Id IN: Trigger.newMap.keySet()
     AND Account__c IN: contractHeaderAccts]);

//copy the record id to contract header lookup
if(contractLines.size()>0 && headers.size()>0){     
for(Contract_Line__c cl: contractLines){
for(Contract_Header__c ch: headers){
cl.Contract_Header_LOOKUP__c = ch.Id;
updateContractUpdate.add(cl);
}
}
}

    if(updateContractUpdate.size()>0){
     update updateContractUpdate;
    }
 }

 

 

This was my original code, but I was getting too many SOQL queries (not enough filters) when uploading data, so I changed it (with lots of help) to the above:

 

trigger ContractLine_ContractHeaderLookupUpdate on Contract_Line__c (before insert, before update)
{

    for (Contract_Line__c cl: Trigger.new)
    {
        
        if(cl.Contract_Header_LOOKUP__c == Null)
        {
            cl.Contract_Header_LOOKUP__c = [SELECT id FROM Contract_Header__c WHERE Name =: cl.Contract_Header__c].id ;
        }
        
    }
    
}

 

  • April 25, 2013
  • Like
  • 0

Hello Helpers

 

I would like to know  how  can I send email with attachment  from an apex class

 

I know  how  to send mails.

I sew articles about how  to attach a VFpage  rendered as pdf

 

but what I need is to attach a file  to my email

 

I am thinking to a static resource  

 

any suggestions?

 

regards

csbaa

 

  • April 21, 2013
  • Like
  • 0

Can anyone help me to fix this trigger?  

 

What am I missing here?

 

 

Error: Compile Error: expecting a left angle bracket, found '>' at line 3 column 32

 

trigger ContractLine_ContractHeaderLookupUpdate on Contract_Line__c (before insert, before update){

Set <Id> headerIds = new Id<Set>():
List <Contract_Line__c> contractLines = new List <Contract_Line__c>();
List <Contract_Line__c> updateContractUpdate = new List <Contract_Line__c>();

//go through trigger items and add related headers to a set
for(Contract_Line__c c: Trigger.new){
headerIds.add(c.Contract_Header_LOOKUP__c)
}

//go through headers and get account Ids
    List <Contract_Header__c> headers = [Select Id, Account__c FROM Contract_Header__c WHERE Id IN: headerIds];

    //match header accounts to cl accounts
List <Contract_Line__c> contractLines = [Select Id, Contract_Header_LOOKUP__c
     FROM Contract_Line__c
     WHERE Id IN: Trigger.newMap.keySet()
     AND Account__c IN: contractHeaderAccts]);

//copy the record id to contract header lookup
if(contractLines.size()>0 && headers.size()>0){     
for(Contract_Line__c cl: contractLines){
for(Contract_Header__c ch: headers){
cl.Contract_Header_LOOKUP__c = ch.Id;
updateContractUpdate.add(cl);
}
}
}

    if(updateContractUpdate.size()>0){
     update updateContractUpdate;
    }
 }

 

 

This was my original code, but I was getting too many SOQL queries (not enough filters) when uploading data, so I changed it (with lots of help) to the above:

 

trigger ContractLine_ContractHeaderLookupUpdate on Contract_Line__c (before insert, before update)
{

    for (Contract_Line__c cl: Trigger.new)
    {
        
        if(cl.Contract_Header_LOOKUP__c == Null)
        {
            cl.Contract_Header_LOOKUP__c = [SELECT id FROM Contract_Header__c WHERE Name =: cl.Contract_Header__c].id ;
        }
        
    }
    
}

 

  • April 25, 2013
  • Like
  • 0

I am getting the following error with this code : 

 

System.DmlException: Update failed. First exception on row 0 with id a1I20000000VfoZEAS; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, This person’s information is private because they’re not a member of the community.: []: []

 

That's all the code says. It doesn't give any further description.

 

The stack trace is this : 

Class.Milestone1_Task_Chatter_Tst.testChatterTaskReassignment: line 95, column 1

 

lines 94 & 95 are this : 


  testTask.Assigned_To__c = otherUser.Id;
  update testTask;

 

So I'm guessing that the problem lies in Assigning the task to otherUser.id  because of sharing rules ? I've already de-activated all of the Validation Rules, so it can't be that. 

 

This whole code is already in production. Apparently somebody made changes to it a while ago and now I can't deploy anything new into production. So, if I could just get the test to run successfully I would be happy, even if that means changing the Assigned_To__c to a setting which would work in the test.

 

Here is the entire class :

 

 

@isTest
private class Milestone1_Task_Chatter_Tst 
{
    static testMethod void testChatterTaskFollows()
    {
        
        Milestone1_Settings__c settings = Milestone1_Test_Utility.createDefaultCustomChatterSettings(true);
        System.assert(settings.Auto_Follow_Task__c, 'Auto Follow Task must be true for this test to work.');
        
        Milestone1_Project__c testProject = Milestone1_Test_Utility.sampleProject('UNIT TEST PROJECT NAME ABC123XYZ UNIQUE' + System.now());
        insert testProject;
        
        Milestone1_Milestone__c testMilestone = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now());
        insert testMilestone;

        Milestone1_Task__c testTask = Milestone1_Test_Utility.sampleTask(testMilestone.Id);
        testTask.Assigned_To__c = UserInfo.getUserId();
        testTask.Complete__c = false;
        insert testTask;
        
        EntitySubscription subscription = [Select Id, ParentId, SubscriberId from EntitySubscription where ParentId =: testTask.Id];
        //assert that the user is following this object
        system.assertEquals(UserInfo.getUserId(),subscription.SubscriberId);
        
        testTask.Complete__c = true;
        update testTask;
        
        List<EntitySubscription> subscriptionList = [Select Id, ParentId, SubscriberId from EntitySubscription where ParentId =: testTask.Id];
        //assert that no one is following this object after its marked as complete
        system.assertEquals(0,subscriptionList.size());
        
    }
    
    static testMethod void testChatterTaskReassignment()
    {
       // List<User> otherUserList = [Select Id from User where Id <> :UserInfo.getUserId() limit 1];
        List<User> otherUserList = [Select Id from User where Id <> :UserInfo.getUserId() and IsActive = true and Profile.UserLicense.Name <> 'Chatter Only' limit 1];
        User otherUser = null;
        //if(otherUserList.size() == 0)
        if(otherUserList.size() == 0)
        {
            List<Profile> prof = [Select Id from Profile limit 1]; 
            otherUser = new User(Alias='testxyz1',emailencodingkey='UTF-8', languagelocalekey='en_US',timezonesidkey='America/Los_Angeles',  CommunityNickname='XYZTEST12301', FirstName='Test Account', LastName='LastName', Email='testaccountxzy@testfacke123.com', username='UnitTest123fake@testfake.com',localesidkey='en_US', ProfileId=prof.get(0).Id);
            insert otherUser;
        }else
        {
            otherUser = otherUserList.get(0);
        }
        Milestone1_Test_Utility.createDefaultCustomChatterSettings(true);
        
        Milestone1_Project__c testProject = Milestone1_Test_Utility.sampleProject('UNIT TEST PROJECT NAME ABC123XYZ UNIQUE' + System.now());
        insert testProject;
        
        Milestone1_Milestone__c testMilestone = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now());
        insert testMilestone;

        Milestone1_Task__c testTask = Milestone1_Test_Utility.sampleTask(testMilestone.Id);
        testTask.Assigned_To__c = UserInfo.getUserId();
        testTask.Complete__c = false;
        insert testTask;
        
        EntitySubscription subscription = [Select Id, ParentId, SubscriberId from EntitySubscription where ParentId =: testTask.Id];
        //assert that the user is following this object
        system.assertEquals(UserInfo.getUserId(),subscription.SubscriberId);
        system.debug('Other User Id == ' + otherUser.Id + 'Task Assigned Id ==' + testTask.Assigned_To__c);
        testTask.Assigned_To__c = otherUser.Id;
        update testTask;
        
        List<EntitySubscription> subscriptionList = [Select Id, ParentId, SubscriberId from EntitySubscription where ParentId =: testTask.Id and SubscriberId =: UserInfo.getUserId()];
        //assert that no one is following this object after its marked as complete
        system.assertEquals(0,subscriptionList.size());
        
    }
    

}

 Any help you could give me would be very appreciated. 

 

Thank you very much.

  • April 25, 2013
  • Like
  • 0

Hello All,

 

I am trying to create a batch job (that I have scheduled to run daily) that copies the value of one fied to another field.

 

I thought I had it up and running, but when I ran a report this morning, it only updated the field for a small handful of opportunities and it should be running on all of them.This is my first batch job, and I have been trying to discern how to write it correctly based on other posted examples in different places. I was wondering if anyone would be able to help?

 

Here's what needs to happen:

  • Essentially, on a daily basis, I want the batch job to run a trigger on all Opportunities to take the value of the "Stage" field and copy the text into a custom field called "Start of Day Stage" (which sounds simple enough...)


Here's my trigger apex code for the update:

 

global class DailyStageUpdateBatch implements Database.batchable<sObject>, Database.Stateful{

global Database.QueryLocator start(Database.BatchableContext bc){

    return database.getQuerylocator('select id,name,stagename from opportunity');
}
    
   global void execute(Database.batchableContext info, List<Opportunity> scope){ 
       List<Opportunity> oppsToUpdate = new List<Opportunity>(); 
       for(Opportunity o : scope){ 
           o.start_of_day_stage__c = o.stagename;
           oppsToUpdate.add(o);
       }
       update oppsToUpdate; 
   }     
   global void finish(Database.batchableContext info){     
   } 
}

 

And here's the code that implements it (that I then have scheduled to run every morning):

 

// APEX to schedule the batch run to update Opportunities to capture the stage at the start of the day.  
//
global class DailyStageCaptureSchedule implements Schedulable{
   global void execute(SchedulableContext sc) {
        DailyStageUpdatebatch batch = new DailyStageUpdatebatch();
      ID batchprocessid = Database.executeBatch(batch); 
   }
}

 

Any thoughts/ideas please and thank you!!

HI , 

 

I have the below code , which is a part of the code that i am working on. I am able to retrieve the user  record , user Id and also contact Id . When I try to use the system.resetpassword(), it gives me an unknown exception with error Id, it is wierd  as it seems , since the system.resetpassword() tends to work correctly when i test this method in developer console , it does reset the password. Any help would be greatly appreciated.

 

Map<Id,User> usermap= new Map<Id,User>([Select Id,ContactId from User where ContactId IN: contactIdset]);

system.debug('reset password entered');
if(usermap.size()>0){

for(User user1:usermap.Values()){
system.debug('user id'+user1.Id);
system.debug('contact Id '+user1.ContactId);
system.resetPassword(user1.Id,true);

}
}

 

Thanks

I am trying to update the account phone based on the contact phone. See tigger below.

 

trigger UpdatePhone on Contact (after insert, after update) {
List<id> Accountids = new List<id>
list<Account> Accounts = new List<Account>
List <Contact> Contacts = new List <contact>
for(contact c:Trigger.new){
if(c.accountid!=Null){
Accountids.add(c.accountid);
}
}
Accounts=[select Id,Phone from Account where Id in:accountids]
for (contact c:Trigger.new) {
for (Account Acc in:Accounts){
if(c.accountid==acc.id){
acc.phone=c.phone;
}
}
update(acc);
}

 

I am getting the following eror

Error: Compile Error: unexpected token: 'list' at line 3 column 4

 

 

Can anyone help ?

Hi,

 

I am displaying a percent field in a vf page.

By default the field is getting populated with value 0.

But i need the field to be blank by default.

pls help me out.

Hi I am using Dynamic query in Apex and I am facing this issue I have my debug logs:

What am I doing wrong?? This is my query string  --

 

10:17:09.075 (75325000)|USER_DEBUG|[86]|DEBUG|******Select Id,Name,Lookup__c from Record__c where Lookup__c IN  '[a02i00000012UOvAAM, a02i00000012UOfAAM]'

 

  • April 22, 2013
  • Like
  • 0

Hello Helpers

 

I would like to know  how  can I send email with attachment  from an apex class

 

I know  how  to send mails.

I sew articles about how  to attach a VFpage  rendered as pdf

 

but what I need is to attach a file  to my email

 

I am thinking to a static resource  

 

any suggestions?

 

regards

csbaa

 

  • April 21, 2013
  • Like
  • 0