• grandmaster
  • NEWBIE
  • 35 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 17
    Replies

Hi All

 

I am held up with this and would really appreciate any suggestions, inputs , help.

 

I have a trigger on the Account object. The trigger pulls a user ID from a custom sObject. The User Id is successfully fetched. It also appears in the debug log that the fetched user Id is assigned correctly to the Account's OwnerID. However, when I go back and check the account record, it still shows the previous User Id and not the ID that is fetched from the custom object. 

 

I have pasted the trigger and debug log excerpt below. Any thoughts?

 

TRIGGER

 

trigger SetAccountOwner on Account (before insert, before update) {

Set<Id> accIds = new Set<Id>();
for(Account a:Trigger.new){
accIds.add(a.Id);
}
List<Account> acc = [Select Id, OwnerId, Billing_State_Abbreviation__c, BillingCity from Account where Id In: accIds];
Map<Id,String> accMap = new Map<Id,String>();
String strOwnerAddressKey ;
String strCity ;
List<Entity_Owner_Address_Map__c> ownerAddr = [Select Owner_Address_Key__c, Owner__c from Entity_Owner_Address_Map__c];
for(Account a: acc){
if(a.BillingCity==null){
strCity='DEFAULT';
}
else{
strCity=(String)a.BillingCity;
}
if(a.Billing_State_Abbreviation__c!=null){
strOwnerAddressKey = (String)a.Billing_State_Abbreviation__c + '-' + strCity;
accMap.put(a.Id, strOwnerAddressKey);
}
else{
// If State is absent, dont do anything
}
System.Debug('strOwnerAddressKey:' + strOwnerAddressKey);
strOwnerAddressKey = null; //Clear it
strCity = null; //Clear it //

// Now, loop through accMap and pull Owner Id from ownerAddr list, then update account
String strKeyInLoop;

for(Id ab:accMap.keySet()){
//System.Debug('a:'+a); // a Contains the account Id
strKeyInLoop=accMap.get(ab);
System.Debug('strKeyInLoop'+strKeyInLoop);
for(Entity_Owner_Address_Map__c e:ownerAddr){
System.Debug('e.Owner_Address_Key__c:'+e.Owner_Address_Key__c);
if((String)e.Owner_Address_Key__c==strKeyInLoop){
//ab.Id=a;
System.Debug('e.Owner__c:'+e.Owner__c);
System.Debug('a.OwnerId: Before '+a.OwnerId);
a.OwnerId = (Id)e.Owner__c;

System.Debug('a.OwnerId: After '+ a.OwnerId); // The debug log appears Good here, but the account record isnt actually updated
break;

}
}
}
}
}

 

DEBUG LOG:

 

11:55:33.116 (116084000)|USER_DEBUG|[41]|DEBUG|a.OwnerId: Before 005E0000003QJeKIAW
11:55:33.116 (116174000)|USER_DEBUG|[44]|DEBUG|a.OwnerId: After  005E0000000K9uHIAS

Hi

 

This is kindof confusing. I have created a trigger on the Contact object which works on Before Insert and Before Update.

 

One of the snippets of the trigger is as follows:

 

if(trigger.isInsert){
System.Debug('trigger.isInsert section is fired');
System.Debug('atm.UserId: ' + atm.UserId);
System.Debug('c.ASD__c before'+c.ASD__c);
c.ASD__c = atm.UserId;
System.Debug('c.ASD__c after'+c.ASD__c);


 

The problem is that when the SAVE button is clicked, the ASD__c field still doesnt show the new user value (ASD__c is a User).

 

Upon checking the debug log, here is what I see:

 

16:15:51.142 (142136000)|USER_DEBUG|[49]|DEBUG|c.ASD__c beforenull
16:15:51.142 (142265000)|USER_DEBUG|[51]|DEBUG|c.ASD__c after005E0000000KojDIAS

As you can see, both the before and after values in the debug statement are different which implies that the field ASD__c actually got set. However, when SAVE is clicked, it doesnt show.

Kind of super confusing. Any clue, idea, suggestion?

Thanks,
gm



}

Hi

 

I wasn't able to find this info. How many account records and contact records can be imported in a Salesforce developer edition?

 

Thanks

 

Hi All

 

I got stuck with this so I thought of asking it here. Any help would be highly appreciated.

 

Well, I am trying to write a test class wherein an AccountTeamMember record is created. I am not able to assign a value to the UserId. The following is the error:

 

Field is not writeable: AccountTeamMember.UserId

 

The following is the code:

 

@isTest
private class TestFox {
static testMethod void testTriggerContactMAMDforCO() {
Map<String, Id> recordTypes = new Map<String, Id>();
for (RecordType rt : [SELECT Id, SObjectType, DeveloperName FROM RecordType]) {
recordTypes.put('' + rt.SObjectType + rt.DeveloperName, rt.Id);
}


// Create an Entity
Account acct = new Account(name='Test Corporation',Sales_Report_Code__c='5000',RecordTypeId = recordTypes.get('AcctBr'));
insert acct;

// Create an Entity Team
AccountTeamMember atmMD = new AccountTeamMember(AccountId=acct.Id,TeamMemberRole='Marketing Dir', UserId='005E0000000KojD');
insert atmMD;

AccountTeamMember atmMA = new AccountTeamMember(AccountId=acct.Id,TeamMemberRole='Marketing Ass', UserId='005E0000000JaQD');
insert atmMA;


// Create a Contact and assign it an account
Contact con = new Contact(AccountId=acct.Id,lastname='lasty',firstname='firsty',BAD__c=true,RecordTypeId = recordTypes.get('CAD'));

//Now insert data ......
Test.startTest();
insert con;

// Now change the Account's Sales_Report_Code__c and Account Channel
acct.Sales_Report_Code__c='1234';
acct.Channel__c='Company Offices';
update acct;

// Update the Account Team Member users
atmMD.UserId='005E0000000JF9m';
update atmMD;

atmMA.UserId='005E0000000K9aE';
update atmMA;

// Update the contact , any field other than Marketing Dir & Marketing Ass
con.FirstName='firstyyyy';
con.BAD__c=false;
update con;
System.assertEquals(con.Marketing_Dir__c,'005E0000000JF9m');
System.assertEquals(con.Marketing_Ass__c,'005E0000000K9aE');

Test.stopTest();
}
}

 

Any suggestion what can be done better here to eliminate the error? 

 

Thank you

g

Hi

 

I have a custom VF page (with a controller behind) where a task is created. The task can relate a Contact with a Campaign successfully.

 

However, when I try to relate a Task with a Lead (Prospect) and Campaign, I get the following error:

 

You can't relate a prospect to an entity or other object.

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, You can't relate a prospect to an entity or other object.: [WhatId]

 

Any suggestion how to fix this?

 

thanks

gm

Hi 

 

I am trying to figure out the way how I can update a field on a Contact object, whenever the contact's account's account team member (User) is created (inserted), edited (updated) or removed (deleted) .

 

I realized that Workflows dont support this.

 

I also realized that it is not possible to create a Trigger on the AccountTeamMember child object as SF doesn't seem to allow creation of triggers on child objects.

 

In that case, what is the best way to handle this scenario? Any suggestions/thoughts?

 

Thanks

 

Hello

 

Say a user 'John' has a role 'X' and is set as an Account Team Member for an Account (say ABC Corp), who has a contact 'Mark Twain' .

 

I want to pull the value of the username with a role 'X' in the Account Team of an Account, and then consequently display it in a custom text field CF__c in the Contact object.

 

In short, I want to display username of John in the CF__c of the contact Mark.

 

Is there a way using a formula, I can set the CF__c?

 

Thanks

 

Hi All

 

I've been trying to get this run for a while now but cant get it. I'm not a fulltime apex programmer. I need help of all you veterans here in this discussion board.

 

I am trying to write a trigger on the Contact object that would fetch the values of one of the AccountTeamMember who has a profile 'P1'. To an extent, the debug values are fetching what I am trying to pull from the AccountTeamMember but am stuck in the last part of the code. I am getting the following error when I try to save the Contact record:

 

Apex trigger SetContact_ASD_Life_User caused an unexpected exception, contact your administrator: SetContact_ASD_Life_User: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 003E000000GvOz0IAF; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 003E000000GvOz0) is currently in trigger SetContact_ASD_Life_User, therefore it cannot recursively update itself: []: Trigger.SetContact_ASD_Life_User: line 25, column 1

 
And here is the code:

trigger SetContact_ASD_Life_User on Contact (before insert, before update) {
    Id AccId = null;
    Id uid = null;
    Id cid = null;
    List<Contact> con = trigger.old;
    List<User> users;

    for(integer i = 0; i<trigger.size;i++){
        AccId = con[i].AccountId;
        List<AccountTeamMember> atm = [SELECT UserId FROM AccountTeamMember where TeamMemberRole='ASD-Life' AND AccountId=:AccId limit 1]; 
        if(atm!=null){
                cid = con[i].Id;
                System.Debug('Contact Id is '+cid);
                AccountTeamMember m = atm[0];
                System.Debug('MSG ASD Life User '+ m.UserId);    
                if(m.UserId!=null){uid = m.UserId;}
                System.Debug('uid is : ' + uid);
                users = [Select Username from User where Id=:m.UserId ];                        
        }       
      }
    
    Contact[] cont = [Select Id, ASD_Life_User3__c, Email from Contact where Id=:cid limit 1]; 
    System.Debug('Contact Email is ' + cont[0].Email);
    cont[0].ASD_Life_user3__c = uid;
    update(cont);
 
 }

 

Any suggestions how to fix this?

 

thanks

gm


Hi

 

Say I have a string, as below:

 

String str = "Great";

 

Now I want to find out what is the character at the first position, second position and so on... How do I do that?

 

I basically need to find out what is the character at the second position of the word "Great", which is "r".

 

This might be simple but cant seem to get it work. In other languages it is easy but in Apex, I wasnt able to find out the trick.

 

It would be great if someone can help with some code sample.

 

Thanks

M

Hi

 

I am learning SOQL and am trying to figure this out. I have 2 custom objects and 1 junction  object (which is a custom object too). Fields as below:

 

Custom Object 1: Question__c

Fields: Answer_Choice__c, Question_Name__c, Question_Text__c (and it has a default field Id for the Question ID)

 

Custom Object 2: Survey__c

Fields: Is_Complete__c, Survey_Name__c, 

(and it has a default field Id for the Survey ID)

 

and the Junction Object: Question_Id__c, Survey_Id__c

 

Now I want to build a SOQL query so that I get the question_name__c, anser_choice__c from custom object 1 where the survey_id__c = :myVariable.

 

What is the best SOQL that can be used here?

 

Thanks

gm

Hi All

 

I am held up with this and would really appreciate any suggestions, inputs , help.

 

I have a trigger on the Account object. The trigger pulls a user ID from a custom sObject. The User Id is successfully fetched. It also appears in the debug log that the fetched user Id is assigned correctly to the Account's OwnerID. However, when I go back and check the account record, it still shows the previous User Id and not the ID that is fetched from the custom object. 

 

I have pasted the trigger and debug log excerpt below. Any thoughts?

 

TRIGGER

 

trigger SetAccountOwner on Account (before insert, before update) {

Set<Id> accIds = new Set<Id>();
for(Account a:Trigger.new){
accIds.add(a.Id);
}
List<Account> acc = [Select Id, OwnerId, Billing_State_Abbreviation__c, BillingCity from Account where Id In: accIds];
Map<Id,String> accMap = new Map<Id,String>();
String strOwnerAddressKey ;
String strCity ;
List<Entity_Owner_Address_Map__c> ownerAddr = [Select Owner_Address_Key__c, Owner__c from Entity_Owner_Address_Map__c];
for(Account a: acc){
if(a.BillingCity==null){
strCity='DEFAULT';
}
else{
strCity=(String)a.BillingCity;
}
if(a.Billing_State_Abbreviation__c!=null){
strOwnerAddressKey = (String)a.Billing_State_Abbreviation__c + '-' + strCity;
accMap.put(a.Id, strOwnerAddressKey);
}
else{
// If State is absent, dont do anything
}
System.Debug('strOwnerAddressKey:' + strOwnerAddressKey);
strOwnerAddressKey = null; //Clear it
strCity = null; //Clear it //

// Now, loop through accMap and pull Owner Id from ownerAddr list, then update account
String strKeyInLoop;

for(Id ab:accMap.keySet()){
//System.Debug('a:'+a); // a Contains the account Id
strKeyInLoop=accMap.get(ab);
System.Debug('strKeyInLoop'+strKeyInLoop);
for(Entity_Owner_Address_Map__c e:ownerAddr){
System.Debug('e.Owner_Address_Key__c:'+e.Owner_Address_Key__c);
if((String)e.Owner_Address_Key__c==strKeyInLoop){
//ab.Id=a;
System.Debug('e.Owner__c:'+e.Owner__c);
System.Debug('a.OwnerId: Before '+a.OwnerId);
a.OwnerId = (Id)e.Owner__c;

System.Debug('a.OwnerId: After '+ a.OwnerId); // The debug log appears Good here, but the account record isnt actually updated
break;

}
}
}
}
}

 

DEBUG LOG:

 

11:55:33.116 (116084000)|USER_DEBUG|[41]|DEBUG|a.OwnerId: Before 005E0000003QJeKIAW
11:55:33.116 (116174000)|USER_DEBUG|[44]|DEBUG|a.OwnerId: After  005E0000000K9uHIAS

Hi

 

I wasn't able to find this info. How many account records and contact records can be imported in a Salesforce developer edition?

 

Thanks

 

Here's my page code.  I need to say If profile != 'GIS' then no dealer approver name needed, else ask for dealer approver name.  is this possible? (I've commented where I need the IF statement

 

<apex:page standardController="Change__c" extensions="SubmitforApproval"> 
<apex:form id="frm"> 
<apex:detail subject="{!Change__c.Id}" relatedList="false" title="false"/> 
<apex:outputPanel id="tstpopup" rendered="{!IF(isDisplayPopUp ==true,true,false)}" > 
<apex:outputPanel styleClass="popupBackground" layout="block" /> 
<apex:outputPanel styleClass="custPopup" layout="block"> 
<apex:pageMessages >
</apex:pageMessages> 
<apex:pageBlock >
<apex:pageBlockSection columns="1" > 

<!--This is where I need the IF statement-->


<apex:inputField label="Dealer Approver" value="{!Change__c.Dealer14__c}" required="true"/>
<apex:inputField label="Change Implementor" value="{!Change__c.Change_Implementer__c}" required="true"/>
<apex:inputField label="Test Plan" value="{!Change__c.Test_Plan1__c}" required="true" style="width: 500px"  />
<apex:inputField label="Implementation Plan" value="{!Change__c.Implementation_Plan1__c}" required="true" style="width: 500px"/>
<apex:inputField label="Backout Plan" value="{!Change__c.Backout_Plan1__c}" required="true" style="width: 500px"/>
<apex:inputField label="Estimated Duration" value="{!Change__c.Estimated_Duration__c}" required="true"/>


<apex:outputPanel > 
<apex:CommandButton action="{!save}" value="Save!"/> 
<apex:CommandButton action="{!cancel}" value="cancel"/> 
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>
</apex:outputPanel>





</apex:form> 

 

 

  • October 15, 2013
  • Like
  • 0

Hi,

i have custom object A.B AND C Object have Lookup relationship with A OBJECT.In A object Have custom field name: delevery template (its a rich text).it is work as a EMAILTEMPLATE....
My task is whenever create a new record under A Object -when select 'B'&'c' custom  field...custom field name: delevery template (its a rich text) section automatically send email to 'B' object emailfield.
here i am use delevery template (its a rich text) section like a plaintext for email..how to automatically send email whenever create a new record under A Object -when select 'B'&'c' custom  field Using apex trigger..
please give your knowledge.

  • October 15, 2013
  • Like
  • 0

Hi All

 

I got stuck with this so I thought of asking it here. Any help would be highly appreciated.

 

Well, I am trying to write a test class wherein an AccountTeamMember record is created. I am not able to assign a value to the UserId. The following is the error:

 

Field is not writeable: AccountTeamMember.UserId

 

The following is the code:

 

@isTest
private class TestFox {
static testMethod void testTriggerContactMAMDforCO() {
Map<String, Id> recordTypes = new Map<String, Id>();
for (RecordType rt : [SELECT Id, SObjectType, DeveloperName FROM RecordType]) {
recordTypes.put('' + rt.SObjectType + rt.DeveloperName, rt.Id);
}


// Create an Entity
Account acct = new Account(name='Test Corporation',Sales_Report_Code__c='5000',RecordTypeId = recordTypes.get('AcctBr'));
insert acct;

// Create an Entity Team
AccountTeamMember atmMD = new AccountTeamMember(AccountId=acct.Id,TeamMemberRole='Marketing Dir', UserId='005E0000000KojD');
insert atmMD;

AccountTeamMember atmMA = new AccountTeamMember(AccountId=acct.Id,TeamMemberRole='Marketing Ass', UserId='005E0000000JaQD');
insert atmMA;


// Create a Contact and assign it an account
Contact con = new Contact(AccountId=acct.Id,lastname='lasty',firstname='firsty',BAD__c=true,RecordTypeId = recordTypes.get('CAD'));

//Now insert data ......
Test.startTest();
insert con;

// Now change the Account's Sales_Report_Code__c and Account Channel
acct.Sales_Report_Code__c='1234';
acct.Channel__c='Company Offices';
update acct;

// Update the Account Team Member users
atmMD.UserId='005E0000000JF9m';
update atmMD;

atmMA.UserId='005E0000000K9aE';
update atmMA;

// Update the contact , any field other than Marketing Dir & Marketing Ass
con.FirstName='firstyyyy';
con.BAD__c=false;
update con;
System.assertEquals(con.Marketing_Dir__c,'005E0000000JF9m');
System.assertEquals(con.Marketing_Ass__c,'005E0000000K9aE');

Test.stopTest();
}
}

 

Any suggestion what can be done better here to eliminate the error? 

 

Thank you

g

Hi

 

I have a custom VF page (with a controller behind) where a task is created. The task can relate a Contact with a Campaign successfully.

 

However, when I try to relate a Task with a Lead (Prospect) and Campaign, I get the following error:

 

You can't relate a prospect to an entity or other object.

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, You can't relate a prospect to an entity or other object.: [WhatId]

 

Any suggestion how to fix this?

 

thanks

gm

Hi 

 

I am trying to figure out the way how I can update a field on a Contact object, whenever the contact's account's account team member (User) is created (inserted), edited (updated) or removed (deleted) .

 

I realized that Workflows dont support this.

 

I also realized that it is not possible to create a Trigger on the AccountTeamMember child object as SF doesn't seem to allow creation of triggers on child objects.

 

In that case, what is the best way to handle this scenario? Any suggestions/thoughts?

 

Thanks

 

Hello

 

Say a user 'John' has a role 'X' and is set as an Account Team Member for an Account (say ABC Corp), who has a contact 'Mark Twain' .

 

I want to pull the value of the username with a role 'X' in the Account Team of an Account, and then consequently display it in a custom text field CF__c in the Contact object.

 

In short, I want to display username of John in the CF__c of the contact Mark.

 

Is there a way using a formula, I can set the CF__c?

 

Thanks

 

Hi

 

I am learning SOQL and am trying to figure this out. I have 2 custom objects and 1 junction  object (which is a custom object too). Fields as below:

 

Custom Object 1: Question__c

Fields: Answer_Choice__c, Question_Name__c, Question_Text__c (and it has a default field Id for the Question ID)

 

Custom Object 2: Survey__c

Fields: Is_Complete__c, Survey_Name__c, 

(and it has a default field Id for the Survey ID)

 

and the Junction Object: Question_Id__c, Survey_Id__c

 

Now I want to build a SOQL query so that I get the question_name__c, anser_choice__c from custom object 1 where the survey_id__c = :myVariable.

 

What is the best SOQL that can be used here?

 

Thanks

gm