• Sfd developer
  • NEWBIE
  • 115 Points
  • Member since 2013

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

Hi, users want to see all Campaign Members for Contacts at an Account on the Account page in a related list. Makes sense.

So I need to link the Campaign Member object directly to the Account.

Here's my code - am not sure why it isn't working.

Oddly the system debug tells me the field Contact on the Campaign member is Null even though the Member is linked to a Contact via it.

 

Any help appreciated thanks!

 

trigger AccountCampaignMember on CampaignMember (after insert, after update)
{
    
    for (CampaignMember t : Trigger.new)
    {
       system.debug('camp memb id================'+t.id);
       system.debug('camp memb Contact================'+t.Contact);
       system.debug('camp memb ContactAccount================'+t.Contact.Account);

            if (t.Contact<> null)
{
If (t.Account__c==null){

                t.Account__c= t.Contact.AccountId;
            }
        }
    //update t;
}}

 

I pretty new to apex, and I needed to do this trigger using map collection.  So I started and I'm stuck.  Where do i go from here?  When I create a new account the trigger should populate the account owner's email.  Thank you.

 

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

   Map<Id, String> emailMap = new Map<Id, String>();
    
    List<User> ownerEmail = [select id, email FROM User WHERE id IN: emailMap.Keyset()];
   
    for(user u: ownerEmail){

      emailMap.put(u.id, 'email');
      system.debug(emailMap);
      }
     system.debug('map ' + emailMap);

This is the class that I use to create first the opportunity header and then specific line items,  PROBLEM,,,,  For some reason it only takes the first of the line items and adds it to the new renewal opportunity.  Please help I will give major kudos.

 

Heres the code:

public with sharing class RenewalOpportunityCreation {

    public static void CreateRenewalOpportunity(Map<Id,Opportunity> oldMap, Map<Id,Opportunity> newMap)
    {

        List<Opportunity> opptsToInsert = new List<Opportunity>();
        Opportunity newOppt = new Opportunity();

        List<Id> OpptyIds = new List<Id>();

        for (Opportunity o : newMap.Values())
        {   
            OpptyIds.add(o.id);
        }

        for(Opportunity oppt : [Select RecordTypeId, Name, Contact__c, AccountId, id, (Select PriceBookEntry.Name, unitprice, 
                                Quantity, Classification__c, Is_Price_book_Entry_Active__c,Is_Product_Active__c  From OpportunityLineItems 
                                Where (Classification__c= 'Software'  OR Classification__c= 'Bundle (SW w/ HW)' OR Classification__c= 'Annual Maintenance' 
                                OR Classification__c = 'Annual Maintenance - 2nd Year & Beyond'))             
                                From Opportunity where Id in :OpptyIds])
        {
            newOppt.Name =  oppt.Name + ' Renewal Opportunity';
            newOppt.AccountId = oppt.AccountId;
            newOppt.Contact__c = oppt.Contact__c;
            newOppt.RecordTypeId =  ServiceClass.getRecordTypesNameMap('Opportunity').get('Renewal Opportunity').Id;                                                        
            newOppt.CloseDate = Date.Today()+30;
            newOppt.StageName = 'Renewal Opportunity';                  
            newOppt.Type = 'Add-On Business';
            newOppt.NextStep = 'Send a invoice for maintenance renewal';
            newOppt.Payment_Terms__c = 'Net 30';
            newOppt.ForecastCategoryName = 'Omitted';
            newOppt.Owner_Location__c = 'FL';
            newOppt.Original_Opportunity__c = oppt.Id;
            newOppt.OwnerId = '00570000001MRuL';
            
            newOppt.Renewal_Software__c = '';
            
            for (OpportunityLineItem lineItem :oppt.OpportunityLineItems) 
            {
                newOppt.Renewal_Software__c = newOppt.Renewal_Software__c + LineItem.PriceBookEntry.Name + '\n';
            }
            
            if(newOppt.Renewal_Software__c <> Null)
            {
                opptsToInsert.add(newOppt);
            }
          
        }
    
        if(opptsToInsert.size() > 0)
        {
            insert(opptsToInsert);
            
            List<OpportunityLineItem> opptLineItemsToInsert = new List<OpportunityLineItem>();
            
            List<Opportunity> OpptIdToInsert = new List<Opportunity>();
            Opportunity newOpptId = new Opportunity();
  
            for(Opportunity opptInsertedIDs : [Select Id, Description from Opportunity where Id in :opptsToInsert])
            {   
                newOpptId.ID = opptInsertedIDs.id;
 
                OpportunityLineItem newOpptLineItem = new OpportunityLineItem();   
                       
           
            
                for(Opportunity opptInserted : [Select RecordTypeId, Name, Contact__c, AccountId, id, Description, (Select PricebookEntry.Name,PricebookEntryid, 
                                                UnitPrice, Quantity, TotalPrice, Classification__c, Is_Price_book_Entry_Active__c,Is_Product_Active__c  
                                                From OpportunityLineItems Where (Classification__c = 'Software'  OR Classification__c= 'Bundle (SW w/ HW)' 
                                                OR Classification__c= 'Annual Maintenance' OR Classification__c = 'Annual Maintenance - 2nd Year & Beyond')) 
                                                From Opportunity where Id in :OpptyIds])
                {       
                    for (OpportunityLineItem lineItem2 :opptInserted.OpportunityLineItems) {
                    newOpptLineItem.Quantity = lineItem2.Quantity;
                    newOpptLineItem.UnitPrice = lineItem2.UnitPrice;
                    newOpptLineItem.PricebookEntryId = lineitem2.PricebookEntry.id;
                }
              
                newOpptLineItem.OpportunityID = newOpptId.ID;
                
                
                opptLineItemsToInsert.add(newOpptLineItem);                 
                
            }
            if(opptLineItemsToInsert.size() > 0)
            {
                insert(opptLineItemsToInsert);
            }
        }}
    }
}

 Thank you,

 Steve Laycock

Hello friends,

 

I have inserted QuoteDocument object in test class like below.

        Quote Qu = New Quote();
        qu.Name = 'Test Quote';
        qu.OpportunityId = opp.Id;
        Insert qu;

        string before = 'Testing base 64 encode';
        Blob beforeblob = Blob.valueOf(before);
      
        QuoteDocument qdoc = New QuoteDocument();
        qdoc.QuoteId = qu.Id;

        qdoc.Document = body;
        insert qdoc;

 In the hightlighted its giving error :

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, This field is required: [VersionData]

 

Can someone tell What is VersionData Field, How to pass value in test class. I have searched in salesforce documentation also, I didn't find any such Field of VersionData in QuoteDocument object.

 

Looking ahead for earlier response...

 

Thanks in Advance,

Uday

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

  List<Account> accountsWithContacts = [select id, name, (select id, salutation, description, 
                                                                firstname, lastname, email from Contacts) 
                                                                from Account where Id IN :Trigger.newMap.keySet()];
	  
  List<Contact> contactsToUpdate = new List<Contact>{};

  for(Account a: accountsWithContacts){

     for(Contact c: a.Contacts){
   	  c.Description=c.salutation + ' ' + c.firstName + ' ' + c.lastname; 

   	  contactsToUpdate.add(c);
     }    	  
   }
      
   update contactsToUpdate;
}

 

Taking this fairly simple code, how can I take the contacts from the second for loop, and either find the contact that was created most recently, or create a list and sort by created date? The trick is that it will have to be specific to the parent, so most recent contact, for each account record.

 

I'm not sure how to go about this, any thoughts?

 

Thank you!

Can please help me to resolve error.

VF code

<apex:page controller="AsFour" sidebar="false" tabStyle="Account">

<apex:form >

<apex:sectionHeader title="AssignmentFour"/>

<apex:pageBlock >

<apex:pageBlockSection title="Search">

<apex:inputText value="{!searchString}" label="Search"/>

<apex:commandButton value="Search" action="{!doSearch}" reRender="output"/>

</apex:pageBlockSection>

<apex:outputPanel id="output">

<apex:pageBlockSection title="Results">

<apex:pageBlockTable value="{!accounts}" var="a">

<apex:column value="{!a.name}"/>

<apex:column value="{!a.BillingState}"/>

<apex:column value="{!a.Phone}"/>

<apex:column value="{!a.Webiste}"/>

</apex:pageBlockTable>

</apex:pageBlockSection>

</apex:outputPanel>

</apex:pageBlock>

</apex:form>

</apex:page>

 

Controller class

public class AsFour {

String Accountqurey;
public list<Account> listAccount{ get; set; }
public String searchString { get; set; }
public String errMsg;

public PageReference doSearch() {
listAccount = new list<Account>();
if(searchString !='' && searchString !=null){
for (List<Account> listAccount : [Select Id,Name,BillingState,Phone,Website FROM Account where name =:'searchString']) {
if(listAccount.size()>0 && listAccount.size()!= null){
}
else{
ApexPages.Message errMsg = new ApexPages.Message(ApexPages.Severity.Warning,'No Accounts Found');
ApexPages.addMessage(errMsg);
}
}
}
}
}

how to get the list of all avilable sobjects in salesforce database ?  using soql,sosl,apex  any one .

Hello all, this is my first post here :) I'm writing an APEX Trigger that is supposed to create a Product Line Item when an opportunity is created. Here is what I did:

 

trigger AutoCreateInterviewer on Opportunity (after insert) {
List<OpportunityLineItem> OpportunityLineItems = new List<OpportunityLineItem>();
for (Opportunity newOpportunity: Trigger.New) {
if (newOpportunity.of_HD_Channels__c != null) {
OpportunityLineItems.add(new OpportunityLineItem(ProductId = '01t60000004Inzu',Opportunity = newOpportunity.Id,Quantity = 3,UnitPrice = 50));
}
}
insert OpportunityLineItems;

 

but it's not working, it gives me the following error:

 

Error: Compile Error: Invalid field ProductId for SObject OpportunityLineItem at line 5 column 74

 


Could you kindly tell me what the right syntaz is for what I need? Thanks in advance

 

My issue is with the arguments I'm passing, mainly the ProductId and the Opportunity I think because it saves fine without them there, please help :(

  • June 28, 2013
  • Like
  • 0

I am trying to fetch data from description fied and update that in other field called "Email Sub". I am getting following errors

 

1. system.finalexception record is read-only

 

I have also tried before insert trigger, but field is not getting updated

 

 

trigger ParseBodySubject on BMCServiceDesk__Incident__c (after Insert, before update) {

    for(BMCServiceDesk__Incident__c incident : Trigger.new){

              String  description = String.valueof([Select id, BMCServiceDesk__incidentDescription__c from BMCServiceDesk__Incident__c where id=:trigger.new limit 1]);                                System.debug('Desc:'+description );

              String Sub = description.substringAfterLast('Subject:');              

              System.debug('Sub:' +Sub);

              incident.Email_Subject__c= Sub;    // Error Line       

       }

}

 

Appreciate your help

Hi,

 

I have developped a apex trigger on FeedItem after insert.  The purpose is to append an hashtag to the body of the post when certain criteria are met.  Everything works very well except that any mention in the body of the post becomes plain text.  Existing hashtags and the one I append are treated like hashtags.  

 

The simplified code is as follows (it appends the tag to all posts and exhibits the problem):

 

trigger FeedItemTagger on FeedItem (before insert) {

          for (FeedItem fi : trigger.new) {

                  fi.body = fi.body + ' I added this #tag in my trigger.';

                  }

          }

 

 

 

Has anyone tried something like this before?  

 

Any ideas on how to prevent the @ mentions being converted into text.

 

Thanks
Derek

  • June 25, 2013
  • Like
  • 0

Hi this is my trigger and class

my trigger is doing increasing the filed count

 

here my trigger and test class

am not able to cover the test code

can any one tel me where am missing

am not getting error but its not going to cover the test coverage

thanks for your help

 

 

trigger UpdateNum on QuoteLineItem (before insert)
{
    if(trigger.isinsert)
    {
    QuoteLineItem QtItem=trigger.new[0];
      List<QuoteLineItem> QtLINum=[Select q.Id from QuoteLineItem q where q.QuoteId=:QtItem.QuoteId];
           if(QtLINum.size()>0)
           {
               Integer num=QtLINum.size();
               QtItem.Number__c=num+1;
           }
           else
           {
               QtItem.Number__c=1;
           }
    }
}



@istest
public class Test_QuoteLineItem
{
public static testmethod void T_QuoteLineItem()
{
op.Name='test';
op.StageName='closed last';
op.CloseDate=system.today();
insert op;
Pricebook2 stdPb = [select Id from Pricebook2 where isStandard=true limit 1];
        
        Product2 p = new product2(name='Abhi',family='Abhi',productcode='12345');
        insert p;
        System.debug('### p:'+p);
        
        PricebookEntry pbe = new PricebookEntry(pricebook2id=stdPb.id, product2id=p.id,
                                              unitprice=1.0, isActive=true,UseStandardPrice=false);
        insert pbe;
Quote q=new Quote();
q.Name='test1';
q.OpportunityId=op.id;
q.pricebook2id=stdPb.id;
insert q;

QuoteLineItem qli = new QuoteLineItem(quoteId=q.Id,
                                pricebookentryid=pbe.id, unitprice=1.5, quantity=2,Number__c=1);
        insert qli;
}}

Visualforce page:

------------------------

<apex:page standardController="Proposal__c" extensions="npList">
<apex:sectionHeader subtitle="New Proposal" title="Proposal Edit" />
<apex:form >
<apex:pageBlock title="Proposal Edit">

<apex:pageBlockButtons location="top">
<apex:commandButton action="{!gettingRecords}" value="Records List" immediate="true"/>
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!saveandnew}" value="Save & New"/>
<apex:commandButton action="{!cancel}" value="Cancel" immediate="true"/>
</apex:pageBlockButtons>

<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!gettingRecords}" value="Records List" immediate="true"/>
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!saveandnew}" value="Save & New"/>
<apex:commandButton action="{!cancel}" value="Cancel" immediate="true"/>
</apex:pageBlockButtons>

<apex:pageBlockSection title="Information">
<apex:inputField value="{!acc.Name}" required="true"/>
<apex:inputField value="{!acc.Opportunity__c}" required="true"/>
<apex:inputField value="{!acc.Proposal_Name__c}"/>
<apex:inputField value="{!acc.Initial_Deal_Review_Date__c}"/>
<apex:inputField value="{!acc.Proposal_Type__c}"/>
<apex:inputField value="{!acc.Mid_Poin_Deal_Review_Date__c}"/>
<apex:inputField value="{!acc.Proposal_Recieved__c}"/>
<apex:inputField value="{!acc.Final_Deal_Review_Date__c}"/>
<apex:inputField value="{!acc.Proposal_Due_Date__c}"/>
<apex:inputField value="{!acc.Proposal_Submit_Date__c}"/>
<apex:inputField value="{!acc.Down_Select_Target_Date__c}"/>
<apex:inputField value="{!acc.Proposal_Final_Selection_Date__c}"/>
<apex:inputField value="{!acc.RFP_Selected__c}"/>
<apex:inputField value="{!acc.Link_to_Proposal__c}"/>
<apex:inputField value="{!acc.Status__c}"/>
<apex:inputField value="{!acc.Link_to_Pricing__c}"/>
<apex:inputField value="{!acc.Down_Selected__c}"/>
<apex:inputField value="{!acc.Down_Selected_Date__c}"/>
</apex:pageBlockSection>

</apex:pageBlock>
</apex:form>

</apex:page>

 

 

 

 

 

 

controller:

--------------

 

public with sharing class npList {
private ApexPages.StandardController controller {get; set;}
public npList(ApexPages.StandardController controller) {
// controller.npList =null;
}
public Proposal__c acc {get;set;}
public String getProposal() {
return null;
}
public npList()
{
acc = new Proposal__c();
}
public PageReference gettingRecords() {
PageReference submissionPage = new PageReference('https://ap1.salesforce.com/a07/o');
submissionPage.setRedirect(true);
return submissionPage;
}
public PageReference save() {
insert acc;
PageReference submissionPage = new PageReference('https://ap1.salesforce.com/006/o');
submissionPage.setRedirect(true);
return submissionPage;
}
public PageReference saveandnew() {
insert acc;
PageReference submissionPage = new PageReference('https://c.ap1.visual.force.com/apex/np');
submissionPage.setRedirect(true);
return submissionPage;
}
public PageReference cancel() {
PageReference submissionPage = new PageReference('https://c.ap1.visual.force.com/apex/np');
return null;
}}

 

 

 

Hi ,

Here I created one visualforce page and save and save&new button.Here my problem is,if  i click on save and save & new button then i will get an error like "System.NullPointerException: Attempt to de-reference a null object',"Error is in expression '{!save}' in page np" . Here the records are not stored into particular object ,so let me know what is the solution for this error and how to save the values.

 

Thanks in advance....

 

public void createorderline()
    {
        if(orderid == '' && orderid == null)
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please save the Order to proceed..'));
        else {
          orderline__c ol =new orderline__c();
          ol.Status__c ='Pending Submission';
    if(ol.Order_Price__r.product__r.name!=null)
          oderlinelist.add(new neworderlist(ol,ol.Order_Price__r.product__r.name,0.0,0.0));
   else {
    system.debug('inside else*************');
string temp='';
     oderlinelist.add(new neworderlist(ol,temp,0.0,0.0));  
 }

          }
    }



Thanks much in advance...

Hello Folks,

 

I am using a string to concatenate address fields. Say Address1__c, Address__C, Address__c. When I concatenate these fields it becomes a longer string.

 

Hence I want to add a new line character into the string, so that when it displays on the page - address 1, address 2 and address 3 would appear on the new line.

 

How can we achive this? I was trying with adding a '\n' character into the string. But it wasn't working.

 

Thanks,
Devendra S

 

 

 

 

 

 

 

Hi, users want to see all Campaign Members for Contacts at an Account on the Account page in a related list. Makes sense.

So I need to link the Campaign Member object directly to the Account.

Here's my code - am not sure why it isn't working.

Oddly the system debug tells me the field Contact on the Campaign member is Null even though the Member is linked to a Contact via it.

 

Any help appreciated thanks!

 

trigger AccountCampaignMember on CampaignMember (after insert, after update)
{
    
    for (CampaignMember t : Trigger.new)
    {
       system.debug('camp memb id================'+t.id);
       system.debug('camp memb Contact================'+t.Contact);
       system.debug('camp memb ContactAccount================'+t.Contact.Account);

            if (t.Contact<> null)
{
If (t.Account__c==null){

                t.Account__c= t.Contact.AccountId;
            }
        }
    //update t;
}}

 

The rtrigger below should be sending an email message only for tasks with a status completed and related to the PCN object. If the task is not related to the PCN object, then the trigger should not send an email. But when a task is marked completed and the task is not related to the PCN record, the trigger is throwing an error. I have not been able to write the condition so the trigger does not throw an error for tasks not related to the PCN record. Please help?

 

Below is the trigger:

trigger PCNQuoteRequestComplete on Task (before Update) {

    Set<Id> taskid = new Set<Id>();
    Set<Id> uid = new Set<Id>();
    
    String pcnid;
    string first3Letter;
    List<user> marketo = [select id from user where lastname = 'marketo' limit 1];
 
    for(task pcnids: trigger.new){
        pcnid=pcnids.whatid; 
        system.debug('/////////' + pcnid);
      if (pcnid!= null)
        first3Letter=pcnid.substring(0,3);
        system.debug('+++++++++' + first3Letter);
   }
  
  for(task pcnact: trigger.new){
        taskid.add(pcnact.id);
        uid.add(pcnact.createdbyid);
     
    }
    
    Task completedtask = [select id, createdbyid, BV_PCN_Quote_Request_Complete_Ckbx__c, 
                            whatid, subject from task where id =: taskid];
   system.debug('id -----' + completedtask);

   List<User> uu = New List<User>([select Email from user where isactive=:true and BV_SO_Admin_Assist__c =: true limit 1]);

               System.debug('###User'+UU);
   
    Map<id, User> fromu = New Map<Id, User>([select id, email, Full_Name__c,
                  isactive from user where isactive=:true and Id =:completedtask.createdbyid limit 1]);  

   system.debug('id -----' + pcnid);
   
      
     Map<id, pcn_s__c> pwhat = New Map<Id, pcn_s__c>([select id, name from pcn_s__c where id =:pcnid]);
  
    integer i=0;
    for(Task Emailto: trigger.new){
            
    if(first3Letter=='a09' && fromu.get(completedtask.createdbyid).id <> marketo[0].id ){
    system.debug('>>>>>>>>>>>>>>>>>>>>>' + first3Letter);

    
        If(emailto.status=='Completed' && emailto.subject=='PCN Requires Quote'
        && emailto.BV_PCN_Quote_Request_Complete_Ckbx__c==false && uu.size()>0){

        emailto.BV_PCN_Quote_Request_Complete_Ckbx__c = true;

                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                
                string EmailAddress;
                EmailAddress = uu[i].email;
                System.Debug('ToEmailAddress###########'+EmailAddress );
                System.Debug('ToEmailAddress###########'+EmailAddress );

                String[]toAddresses = new string[]{EmailAddress};
                
                mail.setToAddresses(toAddresses);
                mail.setReplyTo(fromu.get(completedtask.createdbyid).email);
                mail.setSenderDisplayName(fromu.get(completedtask.createdbyid).full_name__c);
                mail.setSubject('PCN Quote Completed');
                mail.setBccSender(false);
                mail.setUseSignature(false);
                mail.setHtmlBody('Quote request for ' + pwhat.get(pcnid).name + ' has been completed.' );
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); 
              
                       
        }i = i + 1;

    }
    }
}

 Thank you

I'm trying to write a test class, but I keep getting this error message.  Here's my code:

@isTest
public class Test_AttachPRTOPOExtension_Final{
    static testmethod void Test_Attachment_process() {
        SFDC_Purchase_Order__c myOrder = new SFDC_Purchase_Order__c();
        List<SFDC_Purchase_Requisition__c> RequestsToUpdate = new List<SFDC_Purchase_Requisition__c>();
        List<SFDC_Purchase_Items__c> ItemsToUpdate = new List<SFDC_Purchase_Items__c>();
        //Instatiate Controllers
        
        ApexPages.StandardController con = new ApexPages.StandardController(myOrder);
        AttachPRTOPOExtension ext = new AttachPRTOPOExtension(con);
          
        // create items
        List<SFDC_Purchase_Items__c> newItems= new List<SFDC_Purchase_Items__c>();
        for(integer i=0;i<100;i++){
            SFDC_Purchase_Items__c thisitem = new SFDC_Purchase_Items__c(name ='item '+ i);
            newItems.add(thisItem);
        }	//end for
        if(newItems.size() != 100){
            system.debug('newItems <> 100'+ newItems.size());
                } else {		//end if
        system.assertEquals(newItems.size(),100);
                }		// end else
        try {
            Database.SaveResult[] sriList = database.insert(newItems);
            for (Database.SaveResult sri : sriList) {
    			if (sri.isSuccess()) {
        // Operation was successful, so get the ID of the record that was processed
        System.debug('Successfully inserted item. Item ID: ' + sri.getId());
    } else {
        // Operation failed, so get all errors                
        for(Database.Error err : sri.getErrors()) {
            System.debug('The following error has occurred.');                    
            System.debug(err.getStatusCode() + ': ' + err.getMessage());
            System.debug('Item fields that affected this error: ' + err.getFields());
        }		// end inner for
    }			// end else
}				// 3ne outer for
        } catch (DMLEXCEPTION e){
            system.debug('insertItems failed: ' + e);
                         }	//end catch
		List<SFDC_Purchase_Order__c> newOrders = new List<SFDC_Purchase_Order__c>();
        date newDate= date.today();
        ID myPurchaser = [select id from User where  has_purchasing_authority__c = true Limit 1] ;
        ID myApprover = [select id from User where (has_approval_authority__c = true) and (has_purchasing_authority__c = false) Limit 1] ;
        List<SFDC_Purchase_Requisition__c> newReqs= new List<SFDC_Purchase_Requisition__c>();
       
        for(integer i=0;i<100;i++){
            SFDC_Purchase_Requisition__c thisReq = new SFDC_Purchase_Requisition__c(status__c = 'Sent to Purchaser',Department__c = 'Dev CR',Quantity__c = i,
                Item_requested__c = newItems[i].id, Approver__c = myApprover, Purchaser__c = myPurchaser); 
            newReqs.add(thisReq);
        }
        if(newReqs.size() != 100){
            system.debug('newIReqs <> 100'+ newReqs.size());
                } else {
        system.assertEquals(newReqs.size(),100);
                }
        Set<string> ReqSet = new Set<string>();
           try {
            Database.SaveResult[] srrList = database.insert(newReqs);
            for (Database.SaveResult srr : srrList) {
    if (srr.isSuccess()) {
        ReqSet.add(srr.getId());
        // Operation was successful, so get the ID of the record that was processed
        System.debug('Successfully inserted Requisition. Requisition ID: ' + srr.getId());
    } else {
        // Operation failed, so get all errors                
        for(Database.Error err1 : srr.getErrors()) {
            System.debug('The following error has occurred.');                    
            System.debug(err.getStatusCode() + ': ' + err.getMessage());
            System.debug('Requisition fields that affected this error: ' + err.getFields());
        }		//end inner for
    }		//end else
}			// end  outer for
        } catch (DMLEXCEPTION e){
            system.debug('insertReqs failed: ' + e);
        }
         List<SFDC_Purchase_Requisition__c> AllReqs = new List<SFDC_Purchase_Requisition__c>(AttachPRTOPOExtension.m_requestQuery);               }

        // create Orders

        

    for(integer o=0;o < 20; o++){
            SFDC_Purchase_Order__c anOrder = new SFDC_Purchase_Order__c(PO_notes__c = 'note number '+ o, Ship_To_Location__c= 'Cedar Rapids Office',
                                                                        Category = 'Dev CR', Expedite= true,
                                                                        PO_Date__c = newDate);
            newOrders.add(anOrder);
        }
    Test.startTest();
    	Set<string> OrderSet = new Set<string>();
        integer placeInList = 0;
        for(myOrder : newOrders){
            OrderSet.add(myOrder.id);
            myOrder = (SFDC_PurchaseOrder__c)myOrder;
            holdPage = SavePO();
            if(holdPage.URLfor = AttachPRTOPOExtension.m_DetailPage.urlFor){
                AssertNotEquals(AttachPRTOPOExtension.m_currentID, null);}
                AssertNotEquals(AttachPRTOPOExtension.m_resultList.size(), 0);
                for(AttachPRTOPOExtension.tempPR myReq : AttachPRTOPOExtension.m_resultList){
                    myReq = (AttachPRTOPOExtension.tempPR)myReq;
                    for(x=PlaceInList : x<PlaceInList+5 :x++){
                        myReq.selected = true;
                    }
                    PlaceInList++; 
                    AttachPRTOPOExtension.processSelected();
                    AssertEquals(AttachPRTOPOExtension.m_resultList.size(),5);
                    holdPage=AttachPRTOPOExtension.FinalizePO();
                    AssertEquals(ApexPage.currentPage().getURL(),AttachPRTOPOExtension.m_DetailPageROURL + AttachPRTOPOExtension.m_currentId)
                        }  //end inner for
						
                }  //end outer for
            Test.stoptest();
    List<SFDC_Purchase_Order__c> checkPOs = new List<SFDC_Purchase_Order__c>([select id,name,PO_Notes__c,
                                                                    PO_Date__c,Category__c, numRequisitions__c,
                                                                    Total_Price__c, Status__c,Ship_To_Location__c,
                                                                    Expedite__c, Finalized__c from
                                                                    Purchase_Order__c where id in OrderSet];
                                                                             for(SFDC_Purchase_Order__c myOrder : checkPOs){
                                                                                 AssertEquals(Status__c,'Placed');
                                                                                 AssertEquals(Finalized__c,'Placed');
                                                                                 AssertEquals(numRequisitions, 5);
                                                                                 AssertEquals(Expedite, false);
                                                                             }
    List<SFDC_Purchase_Requisitions__c> checkPRs= new List<SFDC_Purchase_Requisitions__c>([select Department__c,
                                                                                            Status__c,Approver__c,
                                                                                            Purchaser__c, Purchase_Order__c,
                                                                                            Quantity__c,Price_per_Unit__c,
                                                                                            Expedite__c,Editable__c,Finalized__c,
                                                                                            Item_Requested__c from SFDC_Purchase_Requisitions__c 
                                                                                            where id in ReqSet Order by Purchase_Order__c Limit 100]);
                                                                             for(SFDC_Purchase_Requisitions__c myReq : checkPRs){
                                                                                 AssertEquals(Status__c,'Sent to Purchaser');
                                                                                 AssertEquals(Finalize__c,true);
                                                                                 AssertEquals(Editable__c, false);
                                                                                 AssertEquals(Expedite__c, false);
                                                                                 AssertNotEquals(Price_per_unit__c, 0);
                                                                                 AssertNotEquals(Quantity__c, 0);
                                                                             }		//end for
																			 }		// end Class

 I've scoured the code to find the (apparent) unmatched curly bracket, with no joy, so I'm probably doing something else wrong which is messing with the compiler.  If I put a right curly bracket on line 82, as would be obvious, it matches up with the bracket at the start of the class, the message becomes "unexpected token: for" which makes sense as it would be appearing after the bracket ending the class definition.  Can anyone offer suggestions about what is wrong and how to fix it?

Thanks in advance.

 

I'm new to the salesforce , i have doubt on cretae lead ,

 

step - first i create lead , once i saved its automatically goes to convert option nxt page , before that ill select the 

status - its converted , not converted , working after then only im using convert onlead in cutomise object ,

 

den its converted to account , contact , opportunity

 

i want write the code using trigger for this conversion , plz how write the code for conerting  in trigger

 

 

Regards,

Ganez

 

 

my code is

Map<Id,Account> newmp = new map<Id,Account>([Select Id,Name from Account limit 10]);
for(Account acc : newmp.values())
{
string codesId = newmp.get('United Oil & Gas, UK');

system.assertEquals(codesId,'0019000000PCwb9AAD');
system.debug('account:'+codesId);
}

  • June 21, 2013
  • Like
  • 0

I pretty new to apex, and I needed to do this trigger using map collection.  So I started and I'm stuck.  Where do i go from here?  When I create a new account the trigger should populate the account owner's email.  Thank you.

 

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

   Map<Id, String> emailMap = new Map<Id, String>();
    
    List<User> ownerEmail = [select id, email FROM User WHERE id IN: emailMap.Keyset()];
   
    for(user u: ownerEmail){

      emailMap.put(u.id, 'email');
      system.debug(emailMap);
      }
     system.debug('map ' + emailMap);

Hey there,

 

I am very new to visualforce and writing any type of code in general and have come across a major snag. Basically, in my salesforce environment, Account is the main object and everything flows from the Account and is related somewhow. I have created a simple VF page with alot of help from one of the excercises within the VisualForce workbook. This visualforce page shows the  Account information as a tab labeled 'details' and all the other custom object/child objects/related lists are other tabs which appear on the page.

 

Now, different profiles have different object access, the main profile 'destiny standard'', does not have rights to alter or even view the Transaction object.The snag arose when I attempted to view an account from the Destiny Standard profile. I was greeted with an error message, something along the lines of "this profile does not have the rights to access this VF page". Easily solved by adding the visualforce page to the profile, however after adding it to the profile and attempting to access the Accounts object again i was greeted with "Transactions__r' is not a valid child relationship name for entity Account". I figured this was because I had labelled the transactions object as no access within the destiny standard profile.

 

My question: Is it possible to have a visualforce page, which will have sections that will not appear, should the user not have sufficient permission to access?

 

This is my accounts VF page:

 

<apex:page standardController="Account" showHeader="true"
tabStyle="account" >
<style>
.activeTab {background-color: #236FBD; color:white;
background-image:none}
.inactiveTab { background-color: lightgrey; color:black;
background-image:none}
</style>
<apex:tabPanel switchType="client" selectedTab="tabdetails"
id="AccountTabPanel" tabClass="activeTab"
inactiveTabClass="inactiveTab">
<apex:tab label="Details" name="AccDetails" id="tabdetails">
<apex:detail relatedList="false" title="true"/>
</apex:tab>
<apex:tab label="Contacts" name="Contacts" id="tabContact">
<apex:pageBlock title="Hello {!$User.FirstName}!">
You are displaying contacts from the {!account.name} account.
Click a contact's name to view his or her details.
</apex:pageBlock>
<apex:pageBlock title="Contacts">
<apex:form >
<apex:dataTable value="{!account.Contacts}" var="contact" cellPadding="4"
border="1">
<apex:column >
<apex:commandLink rerender="detail">
{!contact.Name}
<apex:param name="cid" value="{!contact.id}"/>
</apex:commandLink>
</apex:column>
</apex:dataTable>
</apex:form>
</apex:pageBlock>
<apex:outputPanel id="detail">
<apex:detail subject="{!$CurrentPage.parameters.cid}" relatedList="false"
title="false"/>
</apex:outputPanel>
</apex:tab>
<apex:tab label="Destiny Products"
name="Destiny Products" id="tabDestinyProducts">
<apex:relatedList subject="{!account}"
list="Destiny_Products_and_Services__r" />
</apex:tab>
<apex:tab label="Destiny Services"
name="Destiny Services" id="tabDestinyServices">
<apex:relatedList subject="{!account}"
list="Services__r" />
</apex:tab>
<apex:tab label="Transactions"
name="Transactions" id="tabTransactions">
<apex:relatedList subject="{!account}"
list="Transactions__r" />
</apex:tab>
<apex:tab label="Activities" name="OpenActivities"
id="tabOpenAct">
<apex:relatedList subject="{!account}"
list="OpenActivities" />
<apex:relatedList subject="{!account}"
list="ActivityHistories" />
</apex:tab>
<apex:tab label="Compliance Notes"
name="Compliance Notes" id="tabComplianceNotes">
<apex:relatedList subject="{!account}"
list="Compliance_Notes__r" />
</apex:tab>
</apex:tabPanel>
</apex:page>

 

Any help I could get would be much appreciated. Thank you in advance.

 

Mikie

Hi Folks,

 

Some of the activities in our system automatically by mistakenly deleted by certain User, Could you please let me know whether can we get the details of those Activities by querying in anyway?

 

I knew we can restore the activities from Recycle bin,but the problem is that now in our recycle bin it has redundant as well as Useful activities.

 

Any help  on this is highly appreciated.

 

Regards,

Subbu

  • June 20, 2013
  • Like
  • 0

i have an opportunity before trigger that works great but how do i keep it from firing when a new opportunitylineitem is added? it keeps changing a field on the opportunity causing it the opportunity to fire also there are some rollup fields on the opportunity and i think that is also the issue