• jungleee
  • SMARTIE
  • 610 Points
  • Member since 2012

  • Chatter
    Feed
  • 21
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 14
    Questions
  • 102
    Replies

Hello apex experts,

 

I have a field on the account object that updates when the account is edited.  When the record is edited individually, the correct value gets written to the field.  When I use the data loader . . . One value applies to all records.  Here is my trigger, please advise.

 

trigger Populate_Transfer_Manager on Account (before insert, before Update) {   
   
    list<id> aid = new list<id>();
    for(account a: trigger.new){           
        aid.add(a.ownerid);
    }
    
list<user> managers = new list<user>();
    managers = [select managerid from user where id in: aid];
   

set<id> manid = new set<id>();                             
    for(user u: managers){
        manid.add(u.managerid);
    }
   

for(account a: trigger.new){        
    for(id i: manid){           
            a.transfer_manager__c = i;       
        }
    }
}

I'm having trouble with this because the documentation says that the limit is number of sendEmail methods called, but my trigger is bulkified and the method is only called once.

 

Does this error mean that you can only send 10 emails per apex execution?  That sounds nutso.  Here's the code (note: accountIds set was already populated)

 

// Email related vars

Messaging.SingleEmailMessage m;

string messageBody;

Messaging.SingleEmailMessage[] emails = new List<Messaging.SingleEmailMessage>();

 

Account[] accounts = [select id, name, ownerid, owner.email, type from Account where id in :accountIds];

for(Account a : accounts)

{

 if(a.type.startsWith('X') || a.type.startsWith('Pending')) { 

  messageBody = 'The account: "' + a.name + '" with type ' + a.type + ' has closed an opportunity';

  m = new Messaging.SingleEmailMessage();

  m.setHtmlBody(messageBody);

  m.setPlainTextBody(messageBody);

  m.setSubject('Pending or X account ' + a.name + ' has closed an opportunity');

  m.setToAddresses(new list<string>{a.owner.email});

  emails.add(m);

 }

 

 if(a.type == 'Distributor' || a.type == 'Distributor & Customer') {

  a.type = 'Distributor & Customer';

 } else if(a.type == 'Prospect' || a.type == 'Customer' || a.type == 'X Customer') {

  a.type = 'Customer';

 } elseif(a.type == 'CP: Consultant') {

  a.type = 'CP: Consultant & Customer';

 } else {

  a.type = 'Partner & Customer';

 }

}

 

update accounts;

 

Messaging.sendEmail(emails);

 

Does anybody know the real answer?

I am getting this error on a VF page :

 

This page is redirected from another controller class : The details are coming on the URL but on the page it is displaying error as :Page DetailController does not exist 

 

External Controller Class : Method :

 

public PageReference SaveChanges()

{
String OppId = ApexPages.currentPage().getParameters().get('Id');
Splits__c LitOrd = new Splits__c();
DSObj = new List<Splits__c>();
LitOrd.Opportunity__c= Opp.id ;
DSObj.add(LitOrd);
insert DSObj;
insert OppTeam;
PageReference pageRef = new PageReference('/apex/DetailController?Id='+opp.Id);
return pageRef;

}

 

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

 

VF page :

<apex:page controller="DetailController" tabstyle="Opportunity">
<apex:form >
<apex:pageBlock title="Region Details">
<apex:pageBlockTable value="{!wrappers}" var="wrapper" id="wtable">
<apex:column headerValue="Ident">
<apex:outputText value="{!wrapper.ident}"/>
</apex:column>
<apex:column headerValue="Region">
<apex:inputField value="{!wrapper.MSalesO.Region__c}"/>
</apex:column>
</apex:pageBlockTable>
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlock>
</apex:form>
</apex:page>

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

 

Controller Class :

public class DetailController
{

public List<SOWrapper> wrappers {get; set;}

public static Integer addCount {get; set;}
private Integer nextIdent=0;

public DetailController()
{
wrappers=new List<SOWrapper>();
for (Integer idx=0; idx<5; idx++)
{
wrappers.add(new SOWrapper(nextIdent++));
}
}
public void addRows()
{
for (Integer idx=0; idx<addCount; idx++)
{
wrappers.add(new SOWrapper(nextIdent++));
}
}

public PageReference save()
{
List<Order__c> MSO=new List<Order__c>();
for (SOWrapper wrap : wrappers)
{
MSO.add(wrap.MSalesO);
}

insert MSO;

return new PageReference('/' + Schema.getGlobalDescribe().get('Order__c').getDescribe().getKeyPrefix() + '/o');
}

public PageReference SaveDS()

{
return null;
}
public class SOWrapper
{
public Order__c MSalesO {get; private set;}
public Integer ident {get; private set;}

public SOWrapper(Integer inIdent)
{
ident=inIdent;
MSalesO=new Order__c(Opportunity__c='006f0000003afa5' + ident);
}
}

}

I have two custom objects, Equipment and Equipment History. I would like to insert a new record into Equipment History when a record is inserted into Equipment. So far, I getting this error:

 

Apex trigger insertrecords caused an unexpected exception, contact your administrator: insertrecords: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.insertrecords: line 8, column 1

 

Here is my trigger:

trigger insertrecords on Equipment__c (after insert)
{
 Equipment__c[] eq = [SELECT Name from Equipment__c where id =: trigger.new];
 List<Equipment_History__c> copyeq;
 for(Equipment__c neweq : eq)
 
 {
  copyeq.add(new Equipment_History__c (Name=neweq.Name));
 }
 
 insert copyeq;
}

I'd like to build a trigger that pulls that updates a text field on a record with the report ID of a particular report.  I'm not sure how to go about obtaining the report ID.

Hi, I want to return the record count of a dynamic SOQL query, (checkVal is passed in so don't worry about that):

 

Public List<sObject> lstObj;

Public Integer totRecsToProcess;


mystr  = '[select count() from payout__ImportStaging__c where payout__BD_Id__c = \'' + String.escapeSingleQuotes(checkVal) ;

 lstObj = Database.query(mystr);

 

I want to set totRecsToProcess equal to the count() value returned, can someone please tell me the correct syntax for that?

 

Thanks.

 

 

 

 

Hi,

Why this err occr actually i want to pass the parameter where do i write with in metho r other class...

public class kathir_clsLand {

    public Account acct{get; set;}
    public static String accid;
    public static String qryString;
    public static List<Level1s__c> lstLevel1Tree;
    public static List<Level1s__c> lstLevel1;
    public static List<Level2s__c> lstLevel2; 
    public static List<Level3s__c> lstLevel3;
    public static List<Level4s__c> lstLevel4; 
    public String searchinput {get;set;}
    public List<Level1__c> lstsearch {get;set;} 
    public List<Level2__c> lstsearch2 {get;set;} 
    public List<Level3__c> lstsearch3 {get;set;} 
    public List<Level4__c> lstsearch4 {get;set;} 
    public List<Level5__c> lstsearch5 {get;set;} 
    public List<Level6__c> lstsearch6 {get;set;} 
    public String lurl{get;set;}
    public String state{get; set;}
 public String SearchText {get; set;}
 public Level1__c le1;
 
    public ApexPages.StandardController stdController; 
   public kathir_clsLand(ApexPages.StandardController con)
    {
        stdController = con;
        accid = ApexPages.currentPage().getParameters().get('id');
        lurl=ApexPages.currentPage().getParameters().get('levid');
        this.acct = (Account)con.getRecord();
       // this.le1= (Level1__c)con.getRecord();
        system.debug('*********'+acct);
        Integer j; 
        Integer k;
        // lstLevel1Tree = [Select id, name,(select account__r.name from Level1s__r where account__c =:accid ) from Level1s__c where id in (Select cLevel1__c from Level1__c where Account__c=:accid) ]; 
          if(ApexPages.currentPage().getParameters().get('S') == null)
          {
           lstLevel1 = [Select Id, Name,Description__c,(select account__r.name from Level1s__r where account__c =:accid ),(select id, name from Level2s__r limit 1) from level1s__c  order by Name ];
          // lstLevel4 = [Select Id,name,Level3__c,(select id, account__r.name from Level4s__r where account__c =: + accid ) from Level4s__c ];  
          }else
          {
           lstLevel1 = [Select id, name,(select account__r.name from Level1s__r where account__c =:accid ) from Level1s__c where id in (Select cLevel1__c from Level1__c where Account__c=:accid) ];
         //  lstLevel4 = [Select Id,name,Level3__c,(select id, account__r.name from Level4s__r where account__c =: + accid ), (select id from cusLevel5s__r limit 1) from Level4s__c  where id in (Select cLevel4__c from Level4__c where Account__c=:accid) ];  
         } 
         
            if(ApexPages.currentPage().getParameters().get('S') == null)
            {
                Level='All';   
            }
            else
            {
            Level='Selected Only';
            } 
            
            
    }        
    /* search*/
    
    public void searchmethod()
    {
        String url = ApexPages.currentPage().getParameters().get('levid');
        String urls = ApexPages.currentPage().getParameters().get('id');
        if(url != '' && url != null)
        {
            system.debug('$$$$$$$$$$$$$$$$$$$$$$state '+searchinput );
           if(searchinput != null)
           {
           
            lstsearch = [Select Level1__c,Name,cLevel1__r.Name, AccountName__c, Account__c ,cLevel1__c from Level1__c where cLevel1__c=:url   and  AccountName__c LIKE :(searchinput+'%') limit 500];
            lstsearch2 = [Select Level2__c,Name,cLevel2__r.Name, AccountName__c, Account__c ,cLevel2__c from Level2__c where cLevel2__c=:url   and  AccountName__c LIKE :(searchinput+'%') limit 500];
            lstsearch3 = [Select Level3__c,Name,cLevel3__r.Name, AccountName__c, Account__c ,cLevel3__c from Level3__c where cLevel3__c=:url  and  AccountName__c LIKE :(searchinput+'%') limit 500];
            lstsearch4 = [Select Level4__c,Name,cLevel4__r.Name, AccountName__c, Account__c ,cLevel4__c from Level4__c where cLevel4__c=:url   and  AccountName__c LIKE :(searchinput+'%') limit 500];
            lstsearch5 = [Select Level5__c,Name,cLevel5__r.Name, AccountName__c, Account__c ,cLevel5__c from Level5__c where cLevel5__c=:url  and  AccountName__c LIKE :(searchinput+'%') limit 500];
            lstsearch6 = [Select Level6__c,Name,cLevel6__r.Name, AccountName__c, Account__c ,cLevel6__c from Level6__c where cLevel6__c=:url  and  AccountName__c LIKE :(searchinput+'%') limit 500];

            system.debug('****search****'+lstsearch);
           // return lstLevel11 ;
           }
          
        }
    }
    
    /*radio*/
    public List<SelectOption> getItems()
{
   List<SelectOption> options = new List<SelectOption>(); 
   options.add(new SelectOption('All','All')); 
   options.add(new SelectOption('Selected Only','Selected Only'));     
   return options; 
}        
        
public string Level;           
public String getLevel() 
{
return Level;
}
public void setLevel(String Level) 
{ 
this.Level= Level; 
}
/*cuslevel start  */

    public class Level1sClass 
    {
        public String accURL;
        public string acid1{ get; set; }
        public Level1s__c lev1{ get; set; }
        public Level1s__c lev1Tree{ get; set; }
       // public Level1__c lev1AccTree{ get; set; }
        public Level1__c lev1IDTree{ get; set; }
        public List<Level2sClass> lev2 {get; set;}
        public List<Level2sClass> lev2Tree {get; set;}
        public integer chkcountL1 {get; set;} 
        public Boolean selected {get; set;}
        public Level1sClass(Level1s__c gp)
        {
            accURL= ApexPages.currentPage().getParameters().get('id');
            lev1 = gp;
            lev1Tree = gp;
            acid1 = accURL;
        /*    List<Level1__c> treelst1 = [Select Level1__c,Name,CusLevel1Name__c, AccountName__c, Account__c ,cLevel1__c from Level1__c where Account__c=:accURL];
            for(Level1__c le1: treelst1)
            {
             lev1IDTree =  le1;
             
            } */
           
            lev2 = getList2Details(gp); 
          //  lev2Tree = getTreeLevel2list(gp);
           
            if(accURL!= '' && accURL!= null)
            {
                  chkcountL1 = gp.Level1s__r.size();
                    if(chkcountL1  > 0 )
                        {
                            selected = true;
                           
                        }
                        else
                        {
                            selected = false;
                              
                        }
                      
             }  
 
        }
     }       
    public class Level2sClass
    {
        public String accURL;
        public level2s__c lev2 {get; set;}
        public level2s__c lev2Tree {get; set;}
        public Level2__c lev2IDTree{ get; set; }
        public List<Level3sClass> lev3 {get; set;}
        public List<Level3sClass> lev3Tree {get; set;}
        public Boolean selected {get; set;}
        public integer chkcountL2 {get; set;} 
        public Level2sClass(Level2s__c l2)
        {
           accURL= ApexPages.currentPage().getParameters().get('id');
           lev2 = l2;
           lev2Tree = l2;
         /*  List<Level2__c> treelst2 = [Select Level2__c,Name,CusLevel2Name__c, AccountName__c, Account__c ,cLevel2__c from Level2__c where Account__c=:accURL];
            for(Level2__c le1: treelst2)
            {
             lev2IDTree =  le1;
             
            } */
           lev3 = getList3Details(l2);
          // lev3Tree = getTreeLevel3list(l2);
          
           chkcountL2  = l2.Level2s__r.size();
            if(chkcountL2  > 0 )
            {
                selected = true;
               
            }
            else
            {
                selected = false;
                  
            }           
        }
    } 
    public class Level3sClass
    {
        public Level3s__c lev3 {get; set;}
        public Level3__c lev3IDTree{ get; set; }
        public List<Level4sClass> lev4 {get; set;}
        public Boolean selected {get; set;} 
        public integer chkcountL3{get; set;} 
        public Level3sClass(Level3s__c l3)
        {
            lev3 = l3;
          /*     List<Level3__c> treelst3 = [Select Level3__c,Name,CusLevel3Name__c, AccountName__c, Account__c ,cLevel3__c from Level3__c where Account__c=:accid];
            for(Level3__c le1: treelst3 )
            {
             lev3IDTree =  le1;
             
            }  */
            
            lev4 = getList4Details(l3);
            chkcountL3  = l3.Level3s__r.size();
            if(chkcountL3  > 0 )
            {
                selected = true;
               
            }
            else
            {
                selected = false;
                  
            }         
        }
    }
    public class Level4sClass
    {
        public Level4s__c lev4 {get; set;}
        public Boolean selected {get; set;}
        public integer chkcountL4{get; set;}
        public Level4sClass(Level4s__c l4)
        {
            lev4 = l4;
           // lstLevel4 = [Select Id,name,Level3__c,(select id, account__r.name from Level4s__r where account__c =: + accid ) from Level4s__c where Level3__c =:lev4.id limit 1 ]; 
            chkcountL4 = l4.Level4s__r.size();
            if(chkcountL4  > 0 )
            {
                selected = true;
               
            }
            else
            {
                selected = false;
                  
            }      
        }
    }
     List<Level1sClass> Level1List{get; set;}
    public List<Level1sClass> getList1Details()
    {
       if(Level1List == null)
       {       
            Level1List = new List<Level1sClass>();
          
            for(level1s__c k: lstLevel1 )
            { 
                Level1List.add(new Level1sClass(k)); 
            } 
       }     
          
        return  Level1List ;
    }
   
    public static  List<Level2sClass> Level2List; 
    public static List<Level2sClass> getList2Details(Level1s__c lvl) 
    {
          Level2List= new List<Level2sClass>(); 
          if(ApexPages.currentPage().getParameters().get('S') == null)
          {
              lstLevel2 = [Select id,name,Level1_Name__c,Level1__c, (select  id,account__r.name from Level2s__r where account__c =:accid  ) from Level2s__c where Level1__c =:lvl.id order by id]; 
             
          }else
          {
              lstLevel2 = [Select id,name,Level1_Name__c,Level1__c, (select  id,account__r.name from Level2s__r where account__c =:accid  ),(select id from Level3s__r limit 1) from Level2s__c where Level1__c =:lvl.id and id in (Select cLevel2__c from Level2__c where Account__c=:accid) order by id]; 
               
          }
              for(level2s__c s: lstLevel2)
              {
                Level2List.add(new Level2sClass(s));
              }
          
             
         return Level2List;  
    } 
    
    public static  List<Level3sClass> Level3List; 
    public static List<Level3sClass> getList3Details(Level2s__c lvl) 
    {
        Level3List= new List<Level3sClass>();  
        if(ApexPages.currentPage().getParameters().get('S') == null)
          {
               lstLevel3 = [Select Id,name,Description__c,Level2__c,(select id,account__r.name  from Level3s__r where account__c =: accid ),(select id from cusLevel4s__r limit 1)   from Level3s__c where Level2__c =:lvl.id ]; 
          }else
          {
             lstLevel3 = [Select Id,name,Description__c,Level2__c,(select id,account__r.name  from Level3s__r where account__c =: accid ),(select id from cusLevel4s__r limit 1)   from Level3s__c where Level2__c =:lvl.id and id in (Select cLevel3__c from Level3__c where Account__c =: accid) ];  
          }     
                
                 for(level3s__c s: lstLevel3)
                 {
                     Level3List.add(new Level3sClass(s));
                 }  
         
        return Level3List;          
    }
    public static  List<Level4sClass> Level4List; 
    public static List<Level4sClass> getList4Details(Level3s__c lv4) 
    {
        
        Level4List= new List<Level4sClass>(); 
          
             
    
        return Level4List;          
    }
 
/*cuslevel end */

/* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ Save $$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */


public PageReference Save()
{
   List<level1s__c> selectLevel1 = new List<level1s__c>();
     
       
    //this.stdController.save();
    

    /////////// LEVEL1 ///////////////////
    List<level1s__c> selectedLevel1 = new List<level1s__c>(); 
    
    for(Level1sClass cCon: getList1Details() )
    {
         system.debug('cCon'+cCon.selected);
        if(cCon.selected == true)
        {
            system.debug('firstCCCCCCCCCC:'+cCon.lev1);
            selectedLevel1.add(cCon.lev1);
        }
    }           
     
    Level1__c[] levl1= [Select Id from Level1__c where Account__c=: ApexPages.currentPage().getParameters().get('id')]; 
    delete levl1; 
    if(selectedLevel1 != null)
    {     
        for(level1s__c con : selectedLevel1)
        {
            system.debug('CCCCCCCCCC:'+con+'\n');
            string acctid =ApexPages.currentPage().getParameters().get('id');
            List<Level1__c> lvl1obj= new  Level1__c[0];
            lvl1obj.add(new Level1__c(Name='Level1',Account__c=acctid,cLevel1__c=con.id));
            insert lvl1obj;
    
        }
    }    
    //////////// LEVEL2 ////////////////////
    List<level2s__c> selectedLevel2 = new List<level2s__c>(); 
    
 
    for(Level2sClass cCon:getList2Details())
    {
    
         system.debug('cCon'+cCon.selected);
        if(cCon.selected == true)
        {
            system.debug('firstCCCCCCCCCC:'+cCon.lev2);
            selectedLevel2.add(cCon.lev2);
        }
    }           
     
    Level2__c[] levl2= [Select Id from Level2__c where Account__c=: ApexPages.currentPage().getParameters().get('id')]; 
    delete levl2; 
    if(selectedLevel2 != null)
    {     
        for(level2s__c con : selectedLevel2)
        {
            system.debug('CCCCCCCCCC:'+con+'\n');
            string acctid =ApexPages.currentPage().getParameters().get('id');
            List<Level2__c> lvl2obj= new  Level2__c[0];
            lvl2obj.add(new Level2__c(Name='Level2',Account__c=acctid,cLevel2__c=con.id));
            insert lvl2obj;
           
         }
    }
  
    return null;
    
}

 

 

trigger Trigger1 on Task (after insert,after update)
{
List<String> mlist = new List<String>();
List<String> mailAddrs = new List<String>();
String fURL = URL.getSalesforceBaseUrl().toExternalForm() ;


for(Task t : Trigger.new)

{
Account act = [select Name from Account where Id =: t.AccountId];
if(t.Status == 'Completed')
{
if( t.Activity_Type__c == 'Resolved')
{

Group g = [SELECT (select userOrGroupId from groupMembers) FROM group WHERE name = 'SET A'];

for (GroupMember gm : g.groupMembers)
{
mlist.add(gm.userOrGroupId);
}

User[] usr = [SELECT email FROM user WHERE id IN :mlist];
for(User u : usr)
{
mailAddrs.add(u.email);

}
}
else if ( t.Activity_Type__c == 'Completed')

{
Group g = [SELECT (select userOrGroupId from groupMembers) FROM group WHERE name = 'SET B'];
for (GroupMember gm : g.groupMembers)

{
mlist.add(gm.userOrGroupId);
}

User[] usr = [SELECT email FROM user WHERE id IN :mlist];
for(User u : usr)
{
mailAddrs.add(u.email);
}
}

else if ( t.Activity_Type__c == 'In Progress')

{
Group g = [SELECT (select userOrGroupId from groupMembers) FROM group WHERE name = 'SET C'];
for (GroupMember gm : g.groupMembers)

{
mlist.add(gm.userOrGroupId);

}
User[] usr = [SELECT email FROM user WHERE id IN :mlist];
for(User u : usr)
{
mailAddrs.add(u.email);
}
}

else if ( t.Activity_Type__c == 'On Hold')

{
Group g = [SELECT (select userOrGroupId from groupMembers) FROM group WHERE name = 'SET D'];
for (GroupMember gm : g.groupMembers)

{
mlist.add(gm.userOrGroupId);

}
User[] usr = [SELECT email FROM user WHERE id IN :mlist];
for(User u : usr)
{
mailAddrs.add(u.email);
}
}

else
{
Group g = [SELECT (select userOrGroupId from groupMembers) FROM group WHERE name = 'SET E'];

for (GroupMember gm : g.groupMembers) {
mlist.add(gm.userOrGroupId); }

User[] usr = [SELECT email FROM user WHERE id IN :mlist];
for(User u : usr) { mailAddrs.add(u.email); }

}

if(mailAddrs != null || mailAddrs.size() > 0)
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

mail.setToAddresses(mailAddrs);

mail.setSubject(t.Activity_Type__c+' : '+act.Name+' Task Information');

mail.setPlainTextBody(' Contact Report has been completed '+'\n'+fURL+'/'+t.Id);

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}

}
}

 

The above trigger is working fine. Can any one help to avoid Governor limits for this trigger. by using collections can do it. but am not able fix it please help me on this.

Im not using a sandbox but testing towards the actual database. This is the query I'm trying:

 

Select (Select Id, CurrencyIsoCode, Postcode_lookup__c From Post_code_company__r) From Postal_code_lookup__c 

 

The result Im looking for is not objects itselfs, but I want a list of the child records. Im not sure how to acomplish this since there seem to be no __r object to getch data from? How can you do this query?

Anyone have a technique for getting the timestamp of when a new Lead entry page is opened and still retain the ability to use the standard Page Layout capability?

 

I know that this is possible if a custom VF page is constructed, but we want to use the standard Page Layout editor with Record Types, etc. 

 

There was a suggestion that the NOW() function could be put into a custom Lead formula field to capture when the page was opened then used in a before insert trigger to calculate the time difference, but the NOW() function seems to continuously update whenever the field is accessed.

 

Any suggestions would be greatly appreciated.  Thanks.

How to query a file id from a custom objects Notes and Attachment and append this id to the salesforce's url?

 

can someone help me with the code

Datetime insdate;
insdate = 2013-10-07 00:00:00;
System.debug(insdate);

 

when i try to execute this as  annonymous, I get the error unexpected token: '2013-10-07'

 

My question is, How do we assign a datetime value to a variable?

Hi,

 

I am trying to call a future method from a before trigger.

 

Insert Operation is hapening fine.

 

Update, Delete are not getting executed.

 

Delete is failed with Error333: []

 

Update is failed with an error like 

Future method cannot be called from a future or batch method: MyFutureClass.myMethod(Id)

Please suggest.

 

trigger futurecheck on Account (after update) 

{
   system.debug('Name issssss ' + Trigger.NEW[0].name);
   Account acc = [SELECT name FROM Account WHERE name = 'Thru Future'];
   MyFutureClass.myMethod(acc.Id);
   
}


global class MyFutureClass
{

@future (callout=false)
Public static void myMethod(Id i)
{
System.debug('Method calleddddddd '+ i);

try {
acc.AccountSource='Phone Inquiry';
update acc;
}
catch (DmlException e) {


}

 

hi all,

 

i've been triyng to pull data from a remote service and have managed to get connected and can see in the logs that my child items are being read - my only issue is that the new records that I want creating aren't being created.

 

here is my code can anyone see what this isn't created montioring forms - the apex is triggered when we create a new form, basically it will then go off and check the remote service for any new forms on the server.

 

cheers

dan

 

public class MonitoringFormsUpdater {
  //Future annotation to mark the method as async.
  @Future(callout=true)
  public static void updateMF() {
    //construct an HTTP request
    Http http = new Http();
    HttpRequest req = new HttpRequest();
    req.setEndpoint('https://magpi.com/api/surveys?username=myusername&accesstoken=myaccesstoken');
    req.setMethod('POST'); 
    //send the request
     HTTPResponse res = http.send(req);
     System.debug(res.getBody());
    // list object ready for insert 
    List<Monitoring_Form__c> newforms = new List<Monitoring_Form__c> ();
    string s = res.getBody();
    Dom.Document docx = new Dom.Document();
        docx.load(s);
        dom.XmlNode xroot = docx.getrootelement();
        dom.XmlNode [] xrec = xroot.getchildelements(); //Get all Record Elements
        for(Dom.XMLNode child : xrec) //Loop Through Records
            {
            Monitoring_Form__c mf = new Monitoring_Form__c();
        for(dom.XmlNode magpi : child.getchildren() ) {
           if (magpi.getname() == 'SurveyId') {
                   mf.form_id__c = magpi.gettext();
             }
           if (magpi.getname() == 'SurveyName') {
                   mf.name = magpi.gettext();
             }  
         }
        newforms.add(mf);
        }
  }
}

 the remote service returns this xml file.

 

<Surveys>
<Survey>
<SurveyId>7471</SurveyId>
<SurveyName>Bole_ASD_JHS</SurveyName>
<Owner>episurveyor@camfed.org</Owner>
</Survey>
<Survey>
<SurveyId>7450</SurveyId>
<SurveyName>Bole_ASD_Pri</SurveyName>
<Owner>episurveyor@camfed.org</Owner>
</Survey>
<Survey>
<SurveyId>7493</SurveyId>
<SurveyName>Bole_ASD_SHS</SurveyName>
<Owner>episurveyor@camfed.org</Owner>
</Survey>
<Survey>
<SurveyId>7474</SurveyId>
<SurveyName>Bongo_ASD_JHS</SurveyName>
<Owner>episurveyor@camfed.org</Owner>
</Survey>
<Survey>
<SurveyId>7494</SurveyId>
<SurveyName>Bongo_ASD_SHS</SurveyName>
<Owner>episurveyor@camfed.org</Owner>
</Survey>
</Surveys>

So I'm trying to run some code through the developer console with execute anonymous. 

 

Anytime I try to run the code, it hangs for a second at Sending Request, then just shows Execution Failed and...that's it. No error message, nothing. Since I'm not getting an error message, I'm not really sure what's going wrong. It was working just fine a few days ago with the exact same code I'm trying to run now. Anyone ever see this issue before?

Hi, 

 

I am trying to check if an integer field has a string value , if yes display an error. 

 

if(totalunit != '' && totalunit != null && !Pattern.matches('\\d*', totalunit)){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'WARNING: Total Unit Quanitity Requested Only Accepts Number.'));
return null;
}

 

I am facing an error saying " Comparison arguments must be compatible types: Integer, String".

 

I would appreciate any help or pointers ...

 

Thank you 

 

Problem statement:

 

When APEX inserting OpportunityShare records, you get DML Exception: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY

 

Why does this happen?

 

The obvious reasons are:

 

  • OpportunityShare.OpportunityId is for an invalid Opportunity (or not an opportunity at all)
  • Running user doesn't have access to the Opportunity in OpportunityId



But if neither of these are the case...what else could it be?

 

ANSWER:

 

You can not insert OpportunityShare records for the current owner of the record.  You'll need to modify the Apex code to see if the current owner is the same as OpportunityShare.UserOrGroupId.  If it is, then don't insert.  You can still create OpportunityTeamMember records for that user but not OpportunityShare.  Who the current user is will depend if you are doing the OpportunityShare Dml statement in a before trigger, after trigger, VF controller, or API.

 

Although I haven't tested this, I presume the above applies to AccountShare and CaseShare objects as well.