• Chuckcho
  • NEWBIE
  • 0 Points
  • Member since 2011

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

Hi All,

 

I wrote below trigger to check  two fields on opportunity to stop duplicates. I'm not sure what I'm missing but for some reason the code is not working as its supposed. Can someone assist me with this

 

trigger OpptyDupeCatcher on Opportunity (before insert, before update) {

 

Map<String, Opportunity> OpportunityMap = new Map<String, Opportunity>();
Map<String, Opportunity> AccountNameMap = new Map<String, Opportunity>();


for (Opportunity opportunity : System.Trigger.new) {

// Make sure we don't treat an name and account name that
// isn't changing during an update as a duplicate.
if ((opportunity.name != null && opportunity.account.name !=null) && (System.Trigger.isInsert || ((opportunity.name != System.Trigger.oldMap.get(opportunity.Id).name) &&
(opportunity.account.name != System.Trigger.oldMap.get(opportunity .Id).account.name)) )){
// Make sure another new Opportunity isn't also a duplicate
if ((OpportunityMap.containsKey(opportunity.name))&& (AccountNameMap.containsKey(opportunity.account.name))) {
opportunity.name.addError('Another new Opportunity in your business has the same name and account name. ID = ' + opportunity.Id);
} else {
OpportunityMap.put(opportunity.name, opportunity);

system.debug ( 'opportunitymap' + OpportunityMap.KeySet());

AccountNameMap.put(opportunity.account.name, opportunity);
system.debug ( 'opportunitymap' + accountNameMap.KeySet());

}
}
}

// Using a single database query, find all the Opportunities in
// the database that have the same name as any
// of the opportunities being inserted or updated.
for (Opportunity opportunity : [SELECT Name, Id, account.name from Opportunity WHERE Name IN : OpportunityMap.KeySet()
AND account.name IN: AccountNameMap.KeySet()])
{

system.debug ('opportunity name is' + opportunity.name);

Opportunity NewOpportunity = OpportunityMap.get(opportunity.name);


system.debug('Opportunity: ' + NewOpportunity);
NewOpportunity.Name.addError('An Opportunityt with this name and account name already exists for your business. Id = ' + opportunity.Id);
}

}

I have a requirement where I need to select an opportunity as private and restrict access to the opportunity to other users. My opportunity crud is read, create, edit, del and the sharing settings are public read/write. I understand that i can set my sharing settings to private and then allow access by sharing rules. We want to have the sharing settings as public read/write and then have a sharing checkbox and restrict the access to opportunity record.

 

Thanks for the help.

 

 

I need to update start date and end date with the new values if the contract is set to Auto renew.

 

New Start Date = End Date + 1

New End Date = New Start Date + 60.

 

I created a workflow Rule with criteria End Date less than equal to Today and the time based field update workflow to trigger o days after end date. When I tested it the fields are not getting updated. Is there a better way to achieve this.

 

Thanks for your help and time.

I have the following trigger on tasks to update Account custom field from Agreements custom Object. Account is a custom lookup field on Agreements. The triggers works but updates with the Account ID. I'm trying to update with the Account Name. Can someone please advise how to get the name instead of ID. Thanks for the help

 

trigger updateAccounttname on Task (before insert, before update) {

Set<Id> AccnameIds = new Set<Id>();
for(Task t : trigger.new){
String wId = t.WhatId;
if(wId!=null && wId.startsWith('a1J') && !AccnameIds.contains(t.WhatId)){
AccnameIds.add(t.WhatId);
}
}
 List<Agreement__c> taskAccountname = [Select Id, Account__C from Agreement__C where Id in :AccnameIds];
Map<Id, Agreement__C> AccountnameMap = new Map<Id, Agreement__C>();
for(Agreement__c B : taskAccountname){
AccountNameMap.put(B.Id,B);
}
// Update custom task field with custom Agreement field
for(Task t : trigger.new){
String wId = t.WhatId;
if(wId!=null && wId.startswith('a1J')){
Agreement__C thisAcc = AccountNameMap.get(t.WhatId);
if(thisAcc!=null){t.Account__C = thisAcc.Account__C;}
}
}
}

Is there a way to add product to opportunity when converting a lead. I can add products to the leads but salesforce doesn't seam to allow mapping of the custom field to the Opportunity product.

 

Thanks

Is there anyway I can delete all the development in the sandbox at one place instead of finding each piece of code and then deleting. We are trying to have a new sandbox with no code or configurations in it. The new sand box was created from production and it has all the development in production. 

 

Thanks,

 

Srinivas

The requirement is to lock a opportunity record for editing after the Stage field is changed to "closed/won". Can someone advice how to achieve this.

 

Thanks

Is it possible to have different field labels for different users. Also we changed the Accounts to Companies. Can Accounts tab name be still shown for a particular profile and Companies tab name to other profiles.

 

Thank You!

 

 

How to create a custom view to query contacts created in the past one week. Every time a user logs in he should be able to view all the contacts created in the previous week.

 

Thanks

Is there a way to track automatically number of objects, classes, vf pages, triggers in my org. in other words is there some place I can get the summary of total no of objects, classes, triggers and VF pages created in the org??

when a lead is converted we want to create a new record in a custom object  in addition to account, contact and oppurtunity. Can anyone advise how to achieve this?? We also want to use a logic for account type. When the account type is "A" we want to create account,contact and oppurtunity, If the account type is "B" we want to create account, contact, oppurtunity and a custom object

 

Thanks

I have a custom field on lead and its mapped to account. How can I make the field not editable on the account after I convert the lead into an account??

 

Thanks

Can the leads be imported to multiple campaigns at once??

how  will a user know which queue he is assigned to??

can you have a HTML status related list on cases??

How can I setup a default value for contact name when a new case record is created?

Can you add service cloud to sales cloud.

I imported Accounts using Data Loader. I am trying to import the contact records associated to the accounts that i imported recently. How do i do this?

The requirement is to lock a opportunity record for editing after the Stage field is changed to "closed/won". Can someone advice how to achieve this.

 

Thanks

How to create a custom view to query contacts created in the past one week. Every time a user logs in he should be able to view all the contacts created in the previous week.

 

Thanks