• Chris Eager
  • NEWBIE
  • -1 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 7
    Replies
I need to fetch all unique records from an object and display them on the screen and then on the basis of that selection i need to do the same process for a different object.
We’re a SaaS company that builds platforms for our clients, and we’ve recently integrated with your API to allow our clients to send data from our platform into their own Salesforce instance.
Before connecting, we ask clients to provide us with their version number, object they’d like to connect to, and ID object so that we can match platform users to those in Salesforce. We then pull this data into the API call and send it to Salesforce. This works for all our clients, except one.
We are now trying to help one of our clients connect and coming across the following error: [{salesforce sync HTTP Method 'PATCH' not allowed. Allowed are HEAD,GET,POST"}]
The client has confirmed that the version number, object and ID are correct, but continue to get this error.

Does anyone have any ideas?
My apex code :-
public class Acctcontroller
{
 // Delaration   
 public Account accobj{get;set;}
 public Opportunity oppobj{get;set;}
 public List<Product2> Productlist{get;set;}
 public List<wrapperclass> wraplist{get;set;}
 Public List<Pricebook2>   pbookobj{get;set;}
 Public Set<Id>      productidset{get;set;}
 public string oppid;
 public List<Opportunity> pbookidlst{get;set;}
 Public List<Pricebookentry> pbe{get;set;}   
 Public Map<Id,Double> mapunitprice{get;set;}
 Public Map<Id,string> mapproduct{get;set;}
 
 
 // constructor
 public Acctcontroller() {
     wraplist = new List < wrapperclass > ();
     oppobj = new Opportunity();
     pbookobj = new List < Pricebook2 > ();
    
     String accId = ApexPages.currentPage().getParameters().get('Id');
     System.debug('Accountid' + accId);
     oppid = ApexPages.currentPage().getParameters().get('oppId');

     if (accId != null && accId.trim() != '') {
         accobj = [SELECT Id, 
                             Name 
                       FROM Account 
                          WHERE Id = : accId];
         System.debug('hey' + accobj);
         oppobj.AccountId = accId;
     }

     Productlist = [SELECT Id, 
                    Name, Productcode 
                    FROM Product2];
     System.debug('Plistvalue' + Productlist);

     for (product2 prodt: Productlist) {
         wrapperclass wrap = new wrapperclass();
         wrap.pro = prodt;
         wraplist.add(wrap);
     }

 }

 public Pagereference save() {
     list<pricebook2> istpbook = [SELECT Id,
                                           Name 
                                      FROM pricebook2
                                      LIMIT 1];
     if(!istpbook.isEmpty())
     oppobj.pricebook2id = istpbook[0].id;
     insert oppobj;
     Pagereference objPG = new Pagereference('/apex/opportunityproductline?oppid=' + oppobj.id);
     objPG.setRedirect(true);
     return objPG;

 }

 public Pagereference saveproduct() {
     productidset = new set <Id>();
     for (wrapperclass wss: wraplist) {
         if (wss.checkbx == true) {

             productidset.add(wss.pro.id);
         }
         }
        System.debug('productsetid'+productidset); 
     
     
    pbookidlst = [SELECT Id,
                           Name,
                           Pricebook2id 
                      FROM Opportunity 
                      WHERE Id = :oppId];
    System.debug('productset1'+pbookidlst);
   
     pbe =[SELECT id,
          UnitPrice,
          Product2Id 
          FROM pricebookentry 
          WHERE product2.id in :productidset];
     
     System.debug('pricebookunitprice'+pbe);
 
     mapunitprice = new Map<id,Double>();
     for(pricebookentry p : pbe)
     {
      
      mapunitprice.put(p.Product2Id,p.UnitPrice);
      
     } 
      System.debug('Mapid'+mapunitprice);
      
 
     list < OpportunityLineItem > lstOLI = new list < OpportunityLineItem > ();
     for (wrapperclass ws: wraplist) {
         if (ws.checkbx == true) {
             OpportunityLineItem objOLI = new OpportunityLineItem();
             objOLI.Product2Id = ws.pro.id;
             objOLI.OpportunityId = oppid;
             objOLI.UnitPrice=mapunitprice.get(ws.pro.id);
             
             System.debug('prod id'+ws.pro.id+'\n--map-'+mapunitprice.get(ws.pro.id));
             System.debug('id11'+ws.pro.id);
             
             objOLI.Quantity = ws.qty;
             System.debug('Quantity'+objOLI.Quantity);
             System.debug('Tp'+objOLI.totalprice);
             // objOLI.totalprice = 100; 
             //objOLI.UnitPrice=map.get(ws.pro.id);
             lstOLI.add(objOLI);
             
         }

     }
     insert lstOLI;
     System.debug('waplistvalue' + lstOLI);
     Pagereference objPGg = new Pagereference('https://ap.salesforce.com?id=accid');
     objPGg.setRedirect(true);
     return objPGg;
 }

 public class wrapperclass {
     public product2 pro {get;set;}
     public Boolean checkbx {get;set;}
     public integer qty {get;set;}
     
     // Wrapper Constructor
     public wrapperclass() {
         pro = new product2();
         checkbx = false;
        
     }
 }
 }

I am trying this :- 
@isTest
public class Acctcontroller_Test {
       
     static testMethod void Updatefield() {
    Account acc = new Account();
        acc.Name = 'Test';
        acc.Rating = 'Hot';
        acc.Status__c= 'Active';
        insert acc;
        
        Opportunity opp = new Opportunity();
        opp.name = 'Test';
        opp.AccountId = acc.Id;
        opp.Amount =1500 ; 
        opp.StageName = 'Closed Won';
        opp.CloseDate = Date.today();
        opp.Type = 'New Customers';
        insert opp;
        
        
        
        Test.StartTest(); 
        Acctcontroller refClass = new Acctcontroller ();
        Test.stopTest();
    }       
}


but its coverage only 20% 
Please help me.........
Thanx in adv.*
Hello - How can I return a lead list called 'returnedLead' from a class to a trigger. Any assistance would be greatly appreciated. 

Trigger:
if(Trigger.isUpdate){
                   //Passing Trigger.new and Trigger.old to LeadOwnerAssignment class
                    LeadOwnerAssignment.leadChanges(Trigger.new, Trigger.old);
}

Class: 
public class LeadOwnerAssignment {
    
    public static void leadChanges(List<Lead> newLead, List<Lead> oldLead){
        
        List<Lead> returnedLead = new List<Lead>();
        
        //Old Lead Map
        Map<String, String> mapOfOldAffinityType = new Map<String, String>();
        
        for(lead oldLds : oldLead) {
            mapOfOldAffinityType.put(oldLds.Affinity_Type__c, oldLds.LastNameStreetAndZipCode__c);
        }

        for(Lead ld : newLead) {
            if(ld.Affinity_Type__c != mapOfOldAffinityType.get(ld.Affinity_Type__c)){
                returnedLead.add(ld);     
            }
        }  
    }            
}
I am attempting to upate a field on the Opportunity object with the project that gets created (that is associated to the opportunity) 

So basically the way things work is that when an opportunity is set to closed won a project gets created with a lookup relationship back to the opportunity. There is a field on the Project that automatically gets filled with the opportunity name, however the field on the Opportunity that is supposed to get filled with the project name is not being filled when the project is created. 

I have attempted to write some code to uopdate that field after the project is inserted. My logic seems correct however the field (Pse__Primary__Project__C) is not being uopdated with the project name. 

Here is the code.. 
 
public override void afterInsert(SObject so)
    {
        pse__proj__c newProj = (pse__proj__c)so;

        list <pse__proj__c> projects = [SELECT ID, Name, pse__Opportunity__c FROM pse__proj__c];
        list <opportunity> opportunities = [SELECT ID, Name, pse__Primary_Project__c FROM Opportunity];

        for (Opportunity opps : opportunities){

        if (newProj.Created_by_Opp__c == true)
        {
            opps.pse__Primary_Project__c = newProj.id;
            
        }

        }
    


ANy help would be MUCH appreciated!! THANKS IN ADVANCE!